Created
March 14, 2015 19:44
-
-
Save meeuw/b9f687a55a7bb371f4bd to your computer and use it in GitHub Desktop.
generate all combinations to a specified sum
This file contains hidden or 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
| def recurse(lst, c): | |
| s = sum(lst) | |
| if s > c: | |
| return | |
| if s == c: | |
| print lst | |
| return | |
| for i in range(1, c+1): | |
| if lst and lst[-1] < i: continue | |
| recurse(lst+[i], c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment