Hi,
First of all. This is not a school assignment.
(See
my wiki page to see what I'm doing in real life.)
For those who have nothing better to do, or just like the challenge.
Here's the situation.
After a huge storm 5 sailors are stranded on a tropical island.
On the island there is no other human being.
There are trees and 1 monkey (maybe other monkeys too, but the don't show themselves).
The sailors gather as much coconuts as they can and then go to sleep.
During the night one after each other the sailors wake up.
Each sailor in turn, when awake, sees the pile of coconuts and divides it into 5 equal shares.
After dividing there is exactly 1 coconut left, and he gives that to the monkey.
He hides his share of coconuts and then puts the remaining back onto 1 pile.
When the day breaks, all of the sailors wake up again and see a rather smaller pile.
(Nobody of course is willing to tell what he's donduring the night).
The sailors then divide this final pile into 5 equal shares, and this time no coconut is leftover (so the monkey gets none).
Q1: How many coconuts where there at the beginning (it can be proven that there is an infinite amount of solutions, so what is the smallest amount)?
Q2: Can you write an equation that
calculates the smallest possible solution?
Q3: Can you write a search function that
finds the smallest possible solution, with the condition that the input of that function must be the amount of coconuts that each sailor gets in the final division? (Starting with the total amount is way to easy).
(A prototype could be: function IsPossibleSolution(FinalShare: Integer; out N: Integer): Boolean;)
Q4: Can you generalize the function from Q3 so that it accepts 6 arbitrary remainders (0..4) for each step in the division? It can be assumed that after each division, the remainder is given to the monkey.
Q5: Given the same situation, but now in the final division there is again 1 coconut remaining (which goes to the monkey). How many coconuts where there at the beginning?
Q6: Given the function from Q5: what is the solution if the remainders are (from first division to last): 4, 3, 2, 1, 0, 1?
Bart