AoC/2019/day1/day1.hs

15 lines
371 B
Haskell
Raw Normal View History

2019-12-01 09:02:57 +01:00
main = do
content <- readFile "input"
let input = lines content
print (day11 input)
print (day12 input)
day11 :: [String] -> Int
day11 xs = sum $ map ((subtract 2) . (`div` 3) . read) xs
2019-12-01 09:02:57 +01:00
day12 :: [String] -> Int
day12 xs = (sum $ map (f . read) xs) - (sum $ map read xs) where
f x | x>0=x+f (((subtract 2) . (`div` 3)) x)
2019-12-01 09:02:57 +01:00
| otherwise = 0