Skip to content

Instantly share code, notes, and snippets.

@rkben
Created March 13, 2020 01:32
Show Gist options
  • Save rkben/3a45c7d54ce25749383a5625af1461be to your computer and use it in GitHub Desktop.
Save rkben/3a45c7d54ce25749383a5625af1461be to your computer and use it in GitHub Desktop.
from itertools import combinations
from typing import Generator
import random
vals: list = []
for fuck in range(25):
vals.append(random.randint(1, 500))
def iter_sums(values: list) -> Generator:
"""Generate possible all combinations from values
set_ = parts from `values`
"""
for each in range(0, len(values) + 1):
for set_ in combinations(values, each):
yield set_, round(sum(set_))
print(f'Generates values:\n{vals}')
count = 0
for set_, total in iter_sums(vals):
count += 1
print(f'[{count}] Generated set {set_}')
print(f'[{count}] Total of set {total}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment