Coconuts and Diamonds

One of my favourite puzzles of all times is a bit tough for a typical lower-school kid. It goes like this :

Five men and a monkey are stranded on a desert island. They spend the day searching for food, and by evening, they have collected a big pile of coconuts. Too tired to do anything but sleep, they agree to share the coconuts out in the morning.

However, one of the men wakes up just before midnight. He doesn’t trust his companions, so he goes to the pile of coconuts to take his share. he divides the coconuts into five equal piles, with one left over. He takes his share and hides it, gives the spare coconut to the monkey, collects the rest back into a pile, and goes back to sleep.

Later, the second man wakes up. He also doesn’t trust his companions, so he divides the coconuts into five equal groups, with one left over, that he gives to the monkey. After hiding his share, he piles the rest back up.

Later still, the third man does the same – he divides the coconuts into five equal shares, with one left over that he gives to the monkey. He hides his share and goes back to sleep.

The fourth man does the same, and just before dawn, the fifth man does the same.

In the morning, the men decide to share the coconuts. Nobody comments on the fact that the pile is smaller – they all feel guilty. They split the pile into five equal shares. There’s one left over, which they give to the monkey.

The puzzle – how many coconuts were there in the beginning?

This puzzle was first presented to me as a problem for a computer programming contest – the goal was to write a computer program to solve it! You can make the puzzle easier by telling the story with four men or three instead of five, but here’s a version I made up myself that’s easy enough, while still requiring some careful thought.

Ali Baba has just raided the palace jewellery room, and is making his escape with a bag of diamonds. Unfortunately, he is caught by the treasury guard! He offers the guard half the diamonds in exchange for his freedom – but when they share the diamonds, there’s one left over. Ali Baba says he will give the extra diamond to his wife, but the guard refuses, and takes the extra diamond himself.

Then he is captured by the guard at the palace door! Again, he offers the guard half the diamonds, and again, after splitting the loot two ways, there is one diamond left over. Ali Baba promises to give it to his wife, but the guard insists on taking it before letting him go.

Then he is captured by the guard at the wall! The same thing happens, and after sharing the diamonds between himself and the guard, there is one left over, which Ali Baba says he will give to his wife. The guard disagrees, and keeps it himself.

His friends meet him outside the wall, and take him back to their hideout. They congratulate him on getting out of the palace alive, and insist that Ali Baba share the loot – half for them and half for Ali. However, when they try to do this, there is one left over. “That’s for my wife,” says Ali Baba, but the gang says “No!”, and take the extra diamond for themselves.

Finally, exhausted, Ali Baba arrives home. His wife is at the door, and says “Well?” Ali looks in his bag of loot. He has just one diamond left. He gives it to his wife, and goes to bed.

How many diamonds did he originally steal from the palace jewellery room?

Have fun solving the puzzle!