2024-12-04 17:15:59 +11:00
|
|
|
{-# OPTIONS_GHC -Wno-x-partial #-}
|
|
|
|
|
2024-12-03 05:52:55 +11:00
|
|
|
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
|