Created
August 23, 2013 03:38
-
-
Save gjcourt/6315303 to your computer and use it in GitHub Desktop.
For a given sequence finds all solutions to the subset sum problem.
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
lst = [2, 2, 3, -5] | |
from itertools import * | |
[m[1] for m in zip(chain(*[combinations(lst, n) for n in range(1,len(lst)+1)]), chain(*[combinations(range(len(lst)), n) for n in range(1,len(lst)+1)])) if sum(m[0]) == 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment