# Thread: some problem with sum

1. Member
Join Date
Dec 2009
Posts
1
Rep Power
0

## 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 >

2. 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

3. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,565
Rep Power
12
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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•