import Data.List.Split (splitOn) 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 " "