Java helppppppppppppp
Here is original problem. I have to find out total number of bars.
"3 outlaws have stolen a stagecoach shipment of gold bars. they escape to their hideout and agree to divide up the loot in the morning. however, as soon as one of the bandits hears the others snoring, he decides to biry his one-third of the loot for safe-keeping. after dividing the bars into 3 equal piles, he discovers that there is 1 extra bar left, which he adds to his pile, and buries it. the remaining two piles are merged back into one pile, so the others won't notice the missing gold bars.
in turn, the other two outlaws awake, each while the other two are sleeping, and also divide the remaining loot into thirds and discovers one extra gold bar which they add to their own pile and stash away for safe keeping. in the morning, the outlaws proceed to divide up the remaining gold bars and discover that there is, once again, 1 gold bar left over."
This is what I got so far (link below), I think its correct ... but I'm stuck.
http://img373.imageshack.us/img373/8625/untitled3ro1.jpg
3 bars + 1 extra is four.
4 times 1.5 would be 6, add one and you have 7
7 by 1.5 is a fraction...
(9 + 1) = 10 x 1.5 = (15 +1) = 16 x 1.5 = (24 + 1) = 25 x 1.5 is a fraction... (NULL result)
(12 + 1) = 13 which would not work...
(15 + 1) = 16 which would not work...
(18 + 1) does not work...
(27 + 1) = 28 x 1.5 = (42 +1) =43 x 1.5 is a fraction...
(30 + 1) = 31 does not work...
(33 + 1) = 34 x 1.5 = (51 + 1) = 52 x 1.5 = (78 + 1) = 79 x 1.5 is a fraction...
I don't know how far I want to follow that out, but somehow I think it can be expressed in JAVA to accomplish the result. (I skipped some stages that were apparent in earlier "runs".)
Each pile to be divided is in brackets, I'm sure I goofed on at least one stage - but the java would likely run it (successive incremented numbers) anyway
It would have to run out to four divisions and stop
Last edited by Greywolf; Oct 24, 2005 at 04:02 PM.
left = left - (bars/3 + 1)
Instead of
left = bars - (bars/3 + 1)
Otherwise your always subtracting from the total amount of bars, not what the previous bandit left.
edit: I don't know much about Java, does / give you integer values, or will it return a decimal?
Last edited by pitrow; Oct 24, 2005 at 05:51 PM.



