2023 day 9

This commit is contained in:
eriedaberrie 2023-12-09 00:01:25 -08:00
parent bab443b919
commit 601b102bf4
3 changed files with 25 additions and 0 deletions

12
2023/9/Main1.hs Normal file
View 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
View 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 " "

View file

@ -32,6 +32,7 @@
(pkgs.ghc.withPackages (p: (pkgs.ghc.withPackages (p:
with p; [ with p; [
containers containers
extra
regex-compat regex-compat
split split
unordered-containers unordered-containers