Begin with an N-digit positive integer (no leading zero) and from it create N more integers (each N-1 digits long) by sequentially removing the units digit, or the tens digit, etc from the original number.
The sum of these N+1 integers is the final result.
For example, 1234 + 123 + 124 + 134 + 234 = 1849
1) What original number yields 2022 as the result?
2) How about 487929?
3) If the original number is represented by the concatenation of digits "dN-1 dN-2 ... d2 d1 d0", provide an algebraic formula for the final result.
The formula in 3) should be a function of N, i, and the di:
where the di are the individual digits, and i is the position of the digit.
Note that I am representing the ones digit as i=0.
for n=1:2000
ns=char(string(n));
tot=n;
for i=1:length(ns)
a=[ns(1:i-1) ns(i+1:end)];
tot=tot+str2double(a);
end
if tot==2022
disp([n tot]);
end
end
finds
>> fromSumToAddends2
1320 2022
and, to verify,
1320 + 132 + 130 + 120 + 320 = 2022.
A modified program finds
275795 487929
275813 487929
314159 487929
Formula:
d(N-1) * 10^(N-1) + Sigma{i=0 to N-2} ((i+1)*d(i+1) + (N-i)*d(i) ) * 10^i
I could have included the first term into the Sigma, but that would need the proviso that a non-existent digit should be considered to be zero.
|
Posted by Charlie
on 2022-07-28 11:40:05 |