Files
advent-of-code-2023/day09/Commons.hs
2023-12-09 10:04:40 +01:00

27 lines
651 B
Haskell

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)