I was wandering which is the best way to generate various combinations of $x_i$ such that $$\sum\limits_{i=1}^7 x_i = 1.0$$
where $ x_i \in \{0.0, 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0\}$
I can generate these using brute-force, i.e checking through all $ 11^7$ combinations and only taking those which satisfies our constraint, however I am interested to know if there is another approach for this. Any ideas?
You can use a recursive programming approach. Start from the top. If $1.0$ is in the set, you need $6$ that add to $0.0$-those are easy to find. Otherwise, see if $0.9$ is in it, then look for combinations of $6$ that add to $0.1$ I am imagining a function f(val, n, max) that splits val into n pieces with max the greatest allowable piece and returns a list of the solutions. It will be something like:
where the first call gets the ones with val included and the second gets all the ones without. They will be sorted in decreasing order.