Last active
August 15, 2016 17:14
-
-
Save marksteve/0bfeee29fe93b86ffe901fdfd420fe41 to your computer and use it in GitHub Desktop.
Revisions
-
marksteve revised this gist
Aug 15, 2016 . No changes.There are no files selected for viewing
-
marksteve created this gist
Aug 15, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ import itertools def partition(n): x = 1 _sum = 0 # Get possible addends addends = set() while _sum < n: addends.add(x) _sum += x x += 1 addends.add(x) # Get all combinations choices = set() for t in range(len(addends)): for combination in itertools.combinations(addends, t): if sum(combination) == n: choices.add(combination) # Get first combination with most addends result = None max_len = 0 for choice in choices: if len(choice) > max_len: max_len = len(choice) result = choice return result if __name__ == '__main__': s = int(raw_input()) print list(partition(s))