Created
March 13, 2020 01:32
-
-
Save rkben/3a45c7d54ce25749383a5625af1461be to your computer and use it in GitHub Desktop.
This file contains 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
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