advent-of-code/2023/9/Main1.hs

13 lines
323 B
Haskell
Raw Normal View History

2023-12-12 20:25:25 -08:00
import Data.List.Split (splitOn)
2023-12-09 00:01:25 -08:00
solve :: [Int] -> Int
solve [] = 0
solve xs@(x:_) = x + solve (getDifferences xs)
where
getDifferences = zipWith (-) <*> tail
main :: IO ()
main = print . sum . map solveLine . lines =<< readFile "data.txt"
where
solveLine = solve . reverse . map read . splitOn " "