2023 day 9
This commit is contained in:
parent
bab443b919
commit
6bbb33d72d
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@(x:_) = x + 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@(x:_) = x + 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