diff --git a/2015/day01/day01.hs b/2015/day01/day01.hs new file mode 100644 index 0000000..4c98e2b --- /dev/null +++ b/2015/day01/day01.hs @@ -0,0 +1,19 @@ +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 \ No newline at end of file