I don’t even know where to even take this – Python? Excel? Just Google it? (FWIW, my numbers are making up an Excel table. I’ve been just trying to select a few and guess it, but no bueno.)
I have these numbers:
826, 583, 212, 976, 385, 198, 662, 133, 212, 583, 211, 519
I want to figure out which sets to pull together to make these numbers:
1047, 2453, 2000
(both sets add up to 5500).
Any thoughts about how to figure that out?
>Solution :
Try this
from itertools import chain, combinations
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
for p in powerset([826, 583, 212, 976, 385, 198, 662, 133, 212, 583, 211, 519]):
if sum(p) in [1047, 2453, 2000]:
print(p)
Output
(385, 662)
(826, 976, 198)
(583, 212, 198, 662, 133, 212)
(212, 198, 662, 133, 212, 583)
(583, 212, 133, 212, 583, 211, 519)
(583, 212, 385, 198, 133, 212, 211, 519)
(212, 385, 198, 133, 212, 583, 211, 519)