I need a program for all the combinations of the alphabet "01234", of length 5, of which the digits add up to 4 or less.
Examples 00013, 00031, 00101, 10120
but not 11213, 00341
Questions:
- How to calculate the number of strings that add up to X ?
- How to generate all strings that add up to X ?
- How to generate all strings that add up to a number <=X ?
- What is this concept called in mathematics ? update:
- How to find the subset(s) of digits (numbers) that add to sum X ?
Any procedural language or pseudo code will do. By concept I mean finding the subset(s) of numbers that will add up to a given sum. So, in addition I would like to get an algorithm to find these subsets. Finding all combinations and then filtering out the ones that match is easy, but not time efficient for larger alphabets (strings of digits).