c++ math algorithm

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zandiago
    New Member
    • Jul 2007
    • 19

    c++ math algorithm

    Good day. My semester of c++ is coming to an end. I've got to complete a total of 7 assignments within the next 3 weeks. I've completed 5 out of the seven. I've got two left (1 has a separate thread by itself). So you can also take a look at it. This is the assignment:
    STOLEN GOLD SHIPMENT MYSTERY
    Three gangsters rob a shipment of gold bars late one night. They
    escaped to their hideout and resolved to divide the loot in the
    morning.
    However, as soon as one of the bandits heard the others snoring, he
    divided the gold into three equal piles, finding one bar left over. He
    buried one of the three piles near a tree along with the extra bar.
    Then he went to sleep, sure that he had protected his interest in the
    treasure.
    Naturally, the other two outlaws were no more honest than the first.
    Each in turn crept to the pile of gold bars, divided it three ways and
    found one bar left over, which he kept along with "his" third of the
    treasure.
    Soon, morning came and the final three—way division. Oddly enough,
    this division also left one odd bar remaining. The bandits fought over
    this bar, and in an unprecedented three—way draw, shot each other
    dead.
    The problem is this:
    Each of the four 3-way divisions left exactly one bar. How many bars
    could have been in the original shipment. Assume that the shipment
    contained no more than 500 bars.

    No arrays/functions are necessary. So if someone could give me a jumpstart or how you'd go about addressing it, that would be appreciated. Thank you and have a good day.
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    If you're having trouble getting started with your code, see if you can work it out on paper first.

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      So you had some total, N, gold to start. When it was divided by three, the remainder was one. Let's call the new sum (which is N/3) N1. Then N1 was divided by 3, and again the remainder was 1. Let's call the new sum (which is N1/3) N2. Again, N2 is divided by 3, and 1 is the remainder. Let's call the new sum (which is N2/3) N3. Finally, N3 is divided by 3, and 1 is the remainder. So each pile had a total of G/3 (where G == N3/3) gold, and there was 1 extra. From here, I think it would be simple to find out the total. Just find the total remaining above ground, then repeat these steps to find N2, N1, and finally, N.

      Comment

      Working...