Your example is incorrect. You have eight possibilities. You can choose zero blocks. The total is the sum of the corresponding line in Pascal's triangle.
I think your problem can be described as the sum of 'N choose R' (or 'R choose N', I forget which way the terms are used).
So you do 3 choose 0 plus 3 choose 1 plus 3 choose 2 plus 3 choose 3 to arrive at your total.
In Python, it is easy as there is an itertools module that does the combinations and permutations maths for you.
You might have to consider uniqueness in your calculations – different combinations of blocks could add up to the same total. Again, in Python, you put your total into a set, which cannot contain duplicate entries.
If you want to display systematically, you store the total and block choices in a standard list. For 30, the list item would be (30, 10, 20); for 35, the list would be (35, 20, 25). Then sort the list by total and print out the list.
When the numbers get big (like an 81 piece imperial gauge block set), the time taken for the calculations is excessive.
Edited By DC31k on 26/08/2023 07:11:32