module Commons where import GHC.IO.Handle (isEOF) import Data.List.Utils (split) type History = [Int] parse :: IO [History] parse = do done <- isEOF if done then return [] else do line <- getLine let history = map read $ split " " line otherHistories <- parse return $ history: otherHistories getDifferences :: History -> History getDifferences [h] = [] getDifferences (h1: h2: t) = h1 - h2: getDifferences (h2: t) getNextValue :: History -> Int getNextValue (0: 0: _) = 0 getNextValue (h: t) = h + (getNextValue . getDifferences) (h: t)