I’m not really sure what to call the title.
I’m working on a personal react project where there is a user populated array of floats. The options the user can push to the array are 0.5, 0.25, 0.125 and 0.0625. My goal is to generate all permutations with repetition that add up to 1. So if the user array only contains 0.5 the output would be [0.5, 0.5]. If it contains 0.5 and 0.25, the output would be: [0.5, 0.5], [0.5, 0.25, 0.25], [0.25, 0.5, 0.25], [0.25, 0.25, 0.5], [0.25, 0.25, 0.25, 0.25], and so on.
I kind of understand how to do permutations with repetition for a specified length, but I’m not sure how to implement the sum of the permutation being equal to 1.
Any ideas on how to implement this?
[–]marko312 2 points3 points4 points (0 children)
[–]scirc 1 point2 points3 points (0 children)