diff --git a/2015/day08/day08.hs b/2015/day08/day08.hs new file mode 100644 index 0000000..e1371d4 --- /dev/null +++ b/2015/day08/day08.hs @@ -0,0 +1,20 @@ +import Aoc + +part1 :: [String] -> Int +part1 = sum . map (\line -> length line - actualSize line) + where + actualSize' :: Int -> String -> Int + actualSize' n ('\\':'x':_:_:rest) = actualSize' (n + 1) rest + actualSize' n ('\\':_:rest) = actualSize' (n + 1) rest + actualSize' n ('"':_) = n + actualSize' n (_:rest) = actualSize' (n+1) rest + + actualSize = actualSize' 0 . tail + +part2 :: [String] -> Int +part2 = sum . map sizeDiff + where + count c = length . filter (==c) + sizeDiff line = 2 + count '"' line + count '\\' line + +main = aocMain id part1 part2 \ No newline at end of file