# some problem with sum

• 12-20-2009, 07:51 PM
yuri1992
some problem with sum
i had a qusteion in my test , i need to build a script that
get a number and the number sum numeral.
exp

123456 = 66 i need to print = 12+3+45+6
5025 = 30 i need to print = 5+0+25
1245= 129 i need to print = 124+5.

how i solve this >
• 12-20-2009, 08:15 PM
JosAH
Quote:

Originally Posted by yuri1992
i had a qusteion in my test , i need to build a script that
get a number and the number sum numeral.
exp

123456 = 66 i need to print = 12+3+45+6
5025 = 30 i need to print = 5+0+25
1245= 129 i need to print = 124+5.

how i solve this >

Why do you add the rightmost digit (6) to the next two (45) in your first example but you add the two rightmost digits (25) to the third single digit (0) in your second example? I don't see any regularity from your examples.

kind regards,

Jos
• 12-20-2009, 10:00 PM
pbrockway2
Quote:

123456 = 66 i need to print = 12+3+45+6

How would you figure out how to split the original number without a computer?

One approach might be to check longer and longer start strings:

(1) Guess that the answer is 1+... and check if you can solve the simpler problem 23456=65 (why 65?). If you find you can then you have the answer.

Otherwise (2) Guess that the answer is 12+... and check if you can solve the problem 3456=54. This will eventually find the answer.

But if it didn't you would (3) Guess that the answer is 123+... This one is interesting because it fails right away.

Perhaps you could try solving the problems by hand (ie without using a computer) using some such systematic approach. Then see if you can express the steps you take (the algorithm) in a recursive way.