Skip to content

Instantly share code, notes, and snippets.

@newton-migosi
Last active December 1, 2020 15:43
Show Gist options
  • Save newton-migosi/8368148584a733c22ea8ce16f400846e to your computer and use it in GitHub Desktop.
Save newton-migosi/8368148584a733c22ea8ce16f400846e to your computer and use it in GitHub Desktop.
Inner loop for finding all the ways to add up to a number
loop counter runningTotal accumulator = do
current <- pool
case accumulator of
[] -> guard True
(previous:_) -> guard (current < previous)
guard (current + runningTotal <= target)
loop (counter-1) (runningTotal+current) (current:accumulator)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment