Last active
December 1, 2020 15:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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