Skip to content

Instantly share code, notes, and snippets.

@MaxHalford
Created October 31, 2017 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxHalford/bf1b5471b7a0e9cffa15c1e9762371d1 to your computer and use it in GitHub Desktop.
Save MaxHalford/bf1b5471b7a0e9cffa15c1e9762371d1 to your computer and use it in GitHub Desktop.
Ratio combinations
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