Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 9, 2023
1 parent e24480e commit 15b907e
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions solutions/src/2023/09.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ main =
print (sum (map (nextInSequence . reverse) input))

nextInSequence :: [Int] -> Int
nextInSequence = sum . map last . allDifferences

allDifferences :: [Int] -> [[Int]]
allDifferences = takeWhile (any (0 /=)) . iterate differences
nextInSequence = sum . map last . takeWhile (any (0 /=)) . iterate differences

differences :: [Int] -> [Int]
differences xs = zipWith (-) (tail xs) xs

0 comments on commit 15b907e

Please sign in to comment.