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.

Recommended Answers

All 5 Replies

3(3(3(3x+1)+1)+1)+1 < 500

Thanks for your feedback....i was actually thinking about something like this:

float N = 3(3(3(39+1)+1)1)1 < 500;//total of gold bars
double N1= (N/3);
double N2 = (N1/3);
double N3 = (N2/3);

Your input is appreciated. ithelp...with your method tho...i just tried something....your format is a type of function?

your format is a type of function?

No. It's the answer in math. If we set x=1 the answer would be 3*(3*(3*(3+1)+1)+1)+1 = 121
That would be the smallest amount of bars it would be possible with. If you fill in the x with any other number it would result in other answers.

if you want to know what numbers, do something like this:
(not tested)

int main(void)
{
    int answer = 0;
 
    for (int i = 1; answer < 500; i++)
    {
         answer = 3*(3*(3*(3*i+1)+1)+1)+1;
         std::cout << "with i = " << i << " total no. of bars = " 
                       << answer << std::endl;
    }
 
    std::cin.get();
    return 0;
}

Ok....thanx...Nick...this helps...our professor said there shoukd be multiple answers...so i'm checking something with him. Thx again. Prob solved, time to move on to my very last and final c++ assignment.

Ok....thanx...Nick

No prob.

our professor said there shoukd be multiple answers...so i'm checking something with him.

There are. If you run the program it will give you all the answers in ascending order. I noticed that there's just one little bug in it, because it will give you one to many answers. This is because of the for() loop. If you use a do while loop the problem should be solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.