AoC/2023/day09/day09.hs

15 lines
321 B
Haskell
Raw Normal View History

2023-12-09 17:05:01 +01:00
import Control.Arrow
main :: IO ()
main = do
input <- parse <$> readFile "input"
print $ (day09 &&& day09 . map reverse) input
2023-12-09 17:05:01 +01:00
parse :: String -> [[Int]]
parse = map (map read . words) . lines
day09 :: [[Int]] -> Int
2023-12-09 17:05:01 +01:00
day09 =
sum .
map (sum . map last . takeWhile (not . null) . iterate (zipWith (-) =<< tail))