2015 Day 08 in Haskell
This commit is contained in:
parent
5d2559af06
commit
e46ff8585d
20
2015/day08/day08.hs
Normal file
20
2015/day08/day08.hs
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user