2023 day 9
This commit is contained in:
parent
bab443b919
commit
601b102bf4
12
2023/9/Main1.hs
Normal file
12
2023/9/Main1.hs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import Data.List.Split (splitOn)
|
||||||
|
|
||||||
|
solve :: [Int] -> Int
|
||||||
|
solve [] = 0
|
||||||
|
solve xs = head xs + 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 " "
|
12
2023/9/Main2.hs
Normal file
12
2023/9/Main2.hs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import Data.List.Split (splitOn)
|
||||||
|
|
||||||
|
solve :: [Int] -> Int
|
||||||
|
solve [] = 0
|
||||||
|
solve xs = head xs + solve (getDifferences xs)
|
||||||
|
where
|
||||||
|
getDifferences = zipWith (-) <*> tail
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = print . sum . map solveLine . lines =<< readFile "data.txt"
|
||||||
|
where
|
||||||
|
solveLine = solve . map read . splitOn " "
|
Loading…
Reference in a new issue