A large number can be comma formatted to read more easily into groups of three. E.g. 1050 = 1,050
and 10200 = 10,200
.
The sum of each of these groups of three would be:
1050=1,050
gives: 1+50=51
10200=10,200
gives: 10+200=210
I need to search for matches in the sum of the groups of threes.
Namely, if I am searching for 1234
, then I am looking for numbers whose sum of threes = 1234
.
The smallest match is 235,999
since 235+999=1234
. No other integer less than 235,999
gives a sum of threes equal to 1234.
The next smallest match is 236,998
since 236+998=1234
.
One can add 999 each time, but this fails after reaching 999 since an extra digit of 1 is added to the number due to overflow in the 999.
More generally, I am asking for the solutions (smallest to highest) to:
a+b+c+d… = x
where a,b,c,d… is an arbitrary number of integers between 0-999 and x is a fixed integer
Note there are infinite solutions to this for any positive integer x.
How would one get the solutions to this beginning with the smallest number solutions (for y number of solutions where y can be an arbitrarily large number)?
Is there a way to do this without brute force looping one by one? I'm dealing with potentially very large numbers, which could take years to loop through in a straight loop. Ideally, one should do this without failed attempts.