19 lines
427 B
Haskell
19 lines
427 B
Haskell
|
import Aoc ( aocMain )
|
||
|
|
||
|
parseFile :: [String] -> [Char]
|
||
|
parseFile lines = let [line] = lines in line
|
||
|
|
||
|
part1 :: [Char] -> Int
|
||
|
part1 ps = count '(' - count ')'
|
||
|
where count c = length $ filter (==c) ps
|
||
|
|
||
|
part2 :: [Char] -> Int
|
||
|
part2 = f 0
|
||
|
where
|
||
|
f 0 (')':_) = 1
|
||
|
f n (')':ps) = f (n-1) ps + 1
|
||
|
f n ('(':ps) = f (n+1) ps + 1
|
||
|
f _ _ = undefined
|
||
|
|
||
|
main :: IO ()
|
||
|
main = aocMain parseFile part1 part2
|