This commit is contained in:
2023-12-09 10:04:40 +01:00
parent dbfd617fb0
commit cb79c63bb2
5 changed files with 60 additions and 0 deletions

26
day09/Commons.hs Normal file
View File

@@ -0,0 +1,26 @@
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)