Created
October 31, 2017 17:24
-
-
Save MaxHalford/bf1b5471b7a0e9cffa15c1e9762371d1 to your computer and use it in GitHub Desktop.
Ratio combinations
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
import numpy as np | |
combos = [] | |
def generate(remainder, n, current_combo=[], i=0, step=0.1): | |
if n == 1: | |
combos.append(np.round(current_combo + [remainder], 1)) | |
return | |
for p in np.arange(step, remainder - (n-2) * step - step / 10, step): | |
generate(remainder - p, n - 1, current_combo + [p], i + 1) | |
generate(1, 5) | |
for combo in combos: | |
print(combo, np.sum(combo)) | |
print(len(combos)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment