SuposeSuppose months = 5 and supplies = 9, and (72000) means 7 in the first month, 2 in the second and 0 in the following months.
VALID: (90000)
VALID: (81000)
VALID: (72000)
VALID: (71100)
INVALID: (61200)
INVALID: (80100)
VALID: (90000) VALID: (81000) VALID: (72000) VALID: (71100) INVALID: (61200) INVALID: (80100)
So thisThis is basically a problem of combinations following a rule: in a MONTHS
sized array, the n-th element cannot be larger than the (n-1)-th element, and the sum of all elements must be SUPPLIES
.
My solution to do this was slicing the array into smaller parts and carrying digits over, code below in Javascript:
It's not in any way clear what this does thothough, and I myself would probably have a hard time understanding this code a year from now.
The clearest way I can imagine is just generating all numbers from 90000 down to 0 (in the 9 supplies and 5 months example) and checking if each number follows the rule, but it's ridiculous for bigger values of MONTHSMONTHS
and SUPPLIESSUPPLIES
.