20 lines
611 B
Haskell
20 lines
611 B
Haskell
|
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
|