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 >
Printable View
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 >
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.