Day 9
This commit is contained in:
26
day09/Commons.hs
Normal file
26
day09/Commons.hs
Normal 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)
|
||||
Reference in New Issue
Block a user