Results 1 to 3 of 3
  1. #1
    yuri1992 is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default 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. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by yuri1992 View Post
    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. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    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.

Similar Threads

  1. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 07:12 AM

Posting Permissions

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