Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimitroulas committed Dec 9, 2023
1 parent e05aee0 commit 5260b4b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Solutions/Day09.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ differences (x1:x2:xs) = x2 - x1 : differences (x2:xs)
extrapolateSequence1 :: ExtrapolateDir -> [Int] -> Int
extrapolateSequence1 dir xs = go [] xs
where
-- When extrapolating forwards we sum differences whereas when going backwards we minus
-- them
combiner = if dir == Forward then (+) else (-)
-- If extrapolating forwards, we always grab the last element from the lists.
-- Otherwise we always grab the first element.
accessor = if dir == Forward then last else head
foldFn = foldl' (flip combiner) 0

Expand Down

0 comments on commit 5260b4b

Please sign in to comment.