The monkey and the coconuts is a mathematical puzzle in the field of Diophantine analysis that originated in a short story involving five sailors and a monkey on a desert island who divide up a pile of coconuts; the problem is to find the number of coconuts in the original pile (fractional coconuts not allowed). The problem is notorious for its confounding difficulty to unsophisticated puzzle solvers, though with the proper mathematical approach, the solution is trivial. The problem has become a staple in recreational mathematics collections.
The problem can be expressed as:
There is a pile of coconuts, owned by five men. One man divides the pile into five equal piles, giving the one left over coconut to a passing monkey, and takes away his own share. The second man then repeats the procedure, dividing the remaining pile into five and taking away his share, as do the third, fourth, and fifth, each of them finding one coconut left over when dividing the pile by five, and giving it to a monkey. Finally, the group divide the remaining coconuts into five equal piles: this time no coconuts are left over.
How many coconuts were there in the original pile?
The monkey and the coconuts is the best known representative of a class of puzzle problems requiring integer solutions structured as recursive division or fractionating of some discretely divisible quantity, with or without remainders, and a final division into some number of equal parts, possibly with a remainder. The problem is so well known that the entire class is often referred to broadly as "monkey and coconut type problems", though most are not closely related to the problem.
Another example: "I have a whole number of pounds of cement, I know not how many, but after addition of a ninth and an eleventh, it was partitioned into 3 sacks, each with a whole number of pounds. How many pounds of cement did I have?"
Problems ask for either the initial or terminal quantity. Stated or implied is the smallest positive number that could be a solution. There are two unknowns in such problems, the initial number and the terminal number, but only one equation which is an algebraic reduction of an expression for the relation between them. Common to the class is the nature of the resulting equation, which is a linear Diophantine equation in two unknowns. Most members of the class are determinate, but some are not (the monkey and the coconuts is one of the latter). Familiar algebraic methods are unavailing for solving such equations.
The origin of the class of such problems has been attributed to the Indian mathematician Mahāvīra in chapter VI, § 131, 132 of his Ganita-sara-sangraha (“Compendium of the Essence of Mathematics”), circa 850CE, which dealt with serial division of fruit and flowers with specified remainders.[1] That would make progenitor problems over 1000 years old before their resurgence in the modern era. Problems involving division which invoke the Chinese remainder theorem appeared in Chinese literature as early as the first century CE. Sun Tzu asked: Find a number which leaves the remainders 2, 3 and 2 when divided by 3, 5 and 7, respectively. Diophantus of Alexandria first studied problems requiring integer solutions in the 3rd century CE. The Euclidean algorithm for greatest common divisor which underlies the solution of such problems was discovered by the Greek geometer Euclid and published in his Elements in 300CE.
Prof. David Singmaster, a historian of puzzles, traces a series of less plausibly related problems through the middle ages, with a few references as far back as the Babylonian empire circa 1700 BC. They involve the general theme of adding or subtracting fractions of a pile or specific numbers of discrete objects and asking how many there could have been in the beginning. The next reference to a similar problem is in Jacques Ozanam's Récréations mathématiques et physiques, 1725. In the realm of pure mathematics, Lagrange in 1770 expounded his continued fraction theorem and applied it to solution of Diophantine equations.
The first description of the problem in close to its modern wording appears in Lewis Carroll's diaries in 1888: it involves a pile of nuts on a table serially divided by four brothers, each time with remainder of one given to a monkey, and the final division coming out even. The problem never appeared in any of Carroll's published works, though from other references it appears the problem was in circulation in 1888. An almost identical problem appeared in W.W. Rouse Ball's Elementary Algebra (1890). The problem was mentioned in works of period mathematicians, with solutions, mostly wrong, indicating that the problem was new and unfamiliar at the time.
The problem became notorious when American novelist and short story writer Ben Ames Williams modified an older problem and included it in a story, "Coconuts", in the October 9, 1926, issue of the Saturday Evening Post.[2] Here is how the problem was stated by Williams (condensed and paraphrased):
Five men and a monkey were shipwrecked on an island. They spent the first day gathering coconuts for food.
During the night, one man woke up, and decided to take his share early. So he divided the coconuts in five piles. He had one coconut left over, and he gave that to the monkey. Then he hid his pile and put the rest back together.
By and by each of the five men woke up and did the same thing, one after the other: each one taking a fifth of the coconuts that were in the pile when he woke up, and having one left over for the monkey. In the morning they divided what coconuts were left, and they came out in five equal shares. Of course each one must have known there were coconuts missing; but each one was guilty as the others, so they didn't say anything.
How many coconuts were there in the original pile?
Williams had not included an answer in the story. The magazine was inundated by more than 2,000 letters pleading for an answer to the problem. The Post editor, Horace Lorimer, famously fired off a telegram to Williams saying: "FOR THE LOVE OF MIKE, HOW MANY COCONUTS? HELL POPPING AROUND HERE". Williams continued to get letters asking for a solution or proposing new ones for the next twenty years.
Martin Gardner featured the problem in his April 1958 Mathematical Games column in Scientific American. According to Gardner, Williams had modified an older problem to make it more confounding. In the older version there is a coconut for the monkey on the final division; in Williams's version the final division in the morning comes out even. But the available historical evidence does not indicate which versions Williams had access to.[3] Gardner once told his son Jim that it was his favorite problem.[4] He said that the Monkey and the Coconuts is "probably the most worked on and least often solved" Diophantine puzzle.[5] Since that time the Williams version of the problem has become a staple of recreational mathematics.[6] The original story containing the problem was reprinted in full in Clifton Fadiman's 1962 anthology The Mathematical Magpie,[7] a book that the Mathematical Association of America recommends for acquisition by undergraduate mathematics libraries.[8]
Numerous variants which vary the number of sailors, monkeys, or coconuts have appeared in the literature.[9]
Numerous solutions starting as early as 1928 have been published both for the original problem and Williams modification.[10] [11] [12] [13]
Before entering upon a solution to the problem, a couple of things may be noted. If there were no remainders, given there are 6 divisions of 5, 56=15,625 coconuts must be in the pile; on the 6th and last division, each sailor receives 1024 coconuts. No smaller positive numberwill result in all 6 divisions coming out even. That means that in the problem as stated,any multiple of 15,625 may be added to the pile, and it will satisfy the problem conditions.That also means that the number of coconuts in the original pile is smaller than 15,625, else subtracting 15,625 will yield a smaller solution. But the number in the original pile is not trivially small, like 5 or 10 (that is why this is a hard problem) – it may be in the hundreds or thousands. Unlike trial and error in the case of guessing a polynomial root, trial and error for a Diophantine root will not result in any obvious convergence. There is no simple way of estimating what the solution will be.
Martin Gardner's 1958 Mathematical Games column begins its analysis by solving the original problem (with one coconut also remaining in the morning) because it is easier than Williams's version. Let F be the number of coconuts received by each sailor after the final division into 5 equal shares in the morning. Then the number of coconuts left before the morning division is
5F+1
\tfrac{5}{4}(5F+1)+1=\tfrac{25}{4}F+\tfrac{9}{4}
\tfrac{5}{4}(\tfrac{25}{4}F+\tfrac{9}{4})+1=\tfrac{125}{16}F+\tfrac{241}{16}
1024N=15625F+11529
Gardner points out that this equation is "much too difficult to solve by trial and error," but presents a solution he credits to J. H. C. Whitehead (via Paul Dirac): The equation also has solutions in negative integers. Trying out a few small negative numbers it turns out
N=-4,F=-1
N=15621,F=1023
Trial and error fails to solve Williams's version, so a more systematic approach is needed.
The search space can be reduced by a series of increasingly larger factors by observing the structure of the problem so that a bit of trial and error finds the solution. The search space is much smaller if one starts with the number of coconuts received by each man in the morning division, because that number is much smaller than the number in the original pile.
If F is the number of coconuts each sailor receives in the final division in the morning, the pile in the morning is 5F, which must also be divisible by 4, since the last sailor in the night combined 4 piles for the morning division. So the morning pile, call the number n, is a multiple of 20. The pile before the last sailor woke up must have been 5/4(n)+1. If only one sailor woke up in the night, then 5/4(20)+1 = 26 works for the minimum number of coconuts in the original pile. But if two sailors woke up, 26 is not divisible by 4, so the morning pile must be some multiple of 20 that yields a pile divisible by 4 before the last sailor wakes up. It so happens that 3*20=60 works for two sailors: applying the recursion formula for n twice yields 96 as the smallest number of coconuts in the original pile. 96 is divisible by 4 once more, so for 3 sailors awakening, the pile could have been 121 coconuts. But 121 is not divisible by 4, so for 4 sailors awakening, one needs to make another leap. At this point, the analogy becomes obtuse, because in order to accommodate 4 sailors awakening, the morning pile must be some multiple of 60: if one is persistent, it may be discovered that 17*60=1020 does the trick and the minimum number in the original pile would be 2496. A last iteration on 2496 for 5 sailors awakening, i.e. 5/4(2496)+1 brings the original pile to 3121 coconuts.
Another device is to use extra objects to clarify the division process. Suppose that in the evening we add four blue coconuts to the pile. Then the first sailor to wake up will find the pile to be evenly divisible by five, instead of having one coconut left over. The sailor divides the pile into fifths such that each blue coconut is in a different fifth; then he takes the fifth with no blue coconut, gives one of his coconuts to the monkey, and puts the other four fifths (including all four blue coconuts) back together. Each sailor does the same. During the final division in the morning, the blue coconuts are left on the side, belonging to no one. Since the whole pile was evenly divided 5 times in the night, it must have contained 55 coconuts: 4 blue coconuts and 3121 ordinary coconuts.
The device of using additional objects to aid in conceptualizing a division appeared as far back as 1912 in a solution due to Norman H. Anning.[15]
A related device appears in the 17-animal inheritance puzzle: A man wills 17 horses to his three sons, specifying that the eldest son gets half, the next son one-third, and the youngest son, one-ninth of the animals. The sons are confounded, so they consult a wise horse trader. He says, "here, borrow my horse." The sons duly divide the horses, discovering that all the divisions come out even, with one horse left over, which they return to the trader.
A simple solution appears when the divisions and subtractions are performed in base 5.Consider the subtraction, when the first sailor takes his share (and the monkey's). Let n0,n1,... represent the digits of N, the number of coconuts in the original pile, and s0,s1... represent the digits of the sailor's share S, both base 5. After the monkey's share, the least significant digit of N must now be 0; after the subtraction, the least significant digit of N' left by the first sailor must be 1, hence the following (the actual number of digits in N as well as S is unknown, but they are irrelevant just now):
n5n4n3n2n1 0 (N5) s4s3s2s1s0 (S5) 1 (N'5)The digit subtracted from 0 base 5 to yield 1 is 4, so s0=4. But since S is (N-1)/5, and dividing by 55 is just shifting the number right one position, n1=s0=4. So now the subtraction looks like:
n5n4n3n2 4 0 s4s3s2s1 4 1
Since the next sailor is going to do the same thing on N', the least significant digit of N' becomes 0 after tossing one to the monkey, and the LSD of S' must be 4 for the same reason; the next digit of N' must also be 4. So now it looks like:
n5n4n3n2 4 0 s4s3s2s1 4 4 1
Borrowing 1 from n1 (which is now 4) leaves 3, so s1 must be 4, and therefore n2 as well. So nowit looks like:
n5n4n3 4 4 0 s4s3s2 4 4 4 1
But the same reasoning again applies to N' as applied to N, so the next digit of N' is 4, so s2 and n3 are also 4, etc. There are 5 divisions; the first four must leave an odd number base 5 in the pile for the next division, but the last division must leave an even number base 5 so the morning division will come out even (in 5s). So there are four 4s in N following a LSD of 1: N=444415=312110
A straightforward numeric analysis goes like this: If N is the initial number, each of 5 sailors transitions the original pile thus:
N => 4(N–1)/5 or equivalently, N => 4(N+4)/5 – 4.
Repeating this transition 5 times gives the number left in the morning:
N => 4(N+4)/5 – 4
=> 16(N+4)/25 – 4
=> 64(N+4)/125 – 4
=> 256(N+4)/625 – 4
=> 1024(N+4)/3125 – 4
Since that number must be an integer and 1024 is relatively prime to 3125, N+4 must be a multiple of 3125. The smallest such multiple is 31251, so N = 3125 – 4 = 3121; the number left in the morning comes to 1020, which is evenly divisible by 5 as required.
A simple succinct solution can be obtained by directly utilizing the recursive structure of the problem: There were five divisions of the coconuts into fifths, each time withone left over (putting aside the final division in the morning). The pile remaining after each division must contain an integral number of coconuts. If there were only one such division, then it is readily apparent that 51+1=6is a solution. In fact any multiple of five plus one is a solution, so a possiblegeneral formula is 5k – 4, since a multiple of 5 plus 1 is also a multiple of 5 minus 4.So 11, 16, etc also work for one division.[16]
If two divisions are done, a multiple of 55=25 rather than 5 must be used, because 25 can be divided by 5 twice. So the number of coconuts that could be in the pile is k25 – 4.k=1 yielding 21 is the smallest positive number that can be successively divided by 5 twice with remainder 1. If there are 5 divisions, then multiples of 55=3125 are required; the smallest such number is 3125 – 4 = 3121. After 5 divisions, there are 1020 coconuts leftover, a number divisible by 5 as required by the problem. In fact, after n divisions,it can be proven that the remaining pile is divisible by n, a property made convenientuse of by the creator of the problem.
A formal way of stating the above argument is:
The original pile of coconuts will be divided by 5 a total of 5 times with a remainder of 1, not considering the last division in the morning. Let N = number of coconuts in the original pile. Each division must leave the number of nuts in the same congruence class (mod 5). So,
N\equiv4/5 ⋅ (N-1)
5N\equiv4N-4
N\equiv-4
So if we began in modulo class –4 nuts then we will remain in modulo class –4. Since ultimately we have to divide the pile 5 times or 5^5, the original pile was 5^5 – 4 = 3121 coconuts. The remainder of 1020 coconuts conveniently divides evenly by 5 in the morning. This solution essentially reverses how the problem was (probably) constructed.
The equivalent Diophantine equation for this version is:
1024N=15625F+8404
Reordering,
1024N-15625F=8404
This Diophantine equation has a solution which follows directly from the Euclidean algorithm; in fact, it has infinitely many periodic solutions positive and negative. If (x0, y0) is a solution of 1024x–15625y=1,then N0=x08404, F0=y08404 is a solution of (2), which means any solution must have the form
\begin{cases} N=N0+15625 ⋅ t\\ F=F0+1024 ⋅ t \end{cases}
where
t
One can take both sides of (1) above modulo 1024, so
1024N=15625F+8404\mod1024
n
0=(15625F-15 ⋅ 1024F)+(8404-8 ⋅ 1024)\mod1024
0=265F+212\mod1024
0=53 ⋅ (5F+4)\mod1024
The RHS must still be a multiple of 1024; since 53 is relatively prime to 1024, 5F+4 must be a multiple of 1024. The smallest such multiple is 11024, so 5F+4=1024 and F=204. Substituting into (1)
1024N=15625 ⋅ 204+8404 ⇒ N=
3195904 | |
1024 |
⇒ N=3121
The Euclidean algorithm is quite tedious but a general methodology for solving rational equations ax+by=c requiring integral answers. From (2) above, it is evident that 1024 (210) and 15625 (56) are relatively prime and therefore their GCD is 1, but we need the reduction equations for back substitution to obtain N and F in terms of these two quantities:
First, obtain successive remainders until GCD remains:
15625 = 15·1024 + 265 (a)
1024 = 3·265 + 229 (b)
265 = 1·229 + 36 (c)
229 = 6·36 + 13 (d)
36 = 2·13 + 10 (e)
13 = 1·10 + 3 (f)
10 = 3·3 + 1 (g) (remainder 1 is GCD of 15625 and 1024)
1 = 10 – 3(13–1·10) = 4·10 – 3·13 (reorder (g), substitute for 3 from (f) and combine)
1 = 4·(36 – 2·13) – 3·13 = 4·36 – 11·13 (substitute for 10 from (e) and combine)
1 = 4·36 – 11·(229 – 6·36) = –11·229 + 70*36 (substitute for 13 from (d) and combine)
1 = –11·229 + 70·(265 – 1·229) = –81·229 + 70·265 (substitute for 36 from (c) and combine)
1 = –81·(1024 – 3·265) + 70·265 = –81·1024 + 313·265 (substitute for 229 from (b) and combine)
1 = –81·1024 + 313·(15625 – 15·1024) = 313·15625 – 4776·1024 (substitute for 265 from (a) and combine)
So the pair (N0,F0) = (-4776·8404, -313*8404); the smallest
t
N=N0+15625 ⋅ 2569=3121
F=F0+1024 ⋅ 2569=204
Alternately, one may use a continued fraction, whose construction is based on the Euclidean algorithm. The continued fraction for (0.065536 exactly) is [;15,3,1,6,2,1,{{overline|3}}];[17] its convergent terminated after the repetend is, giving us x0=–4776 and y0=313. The least value of t for which both N and F are non-negative is 2569, so
N=-4776 ⋅ 8404+15625 ⋅ 2569=3121
This is the smallest positive number that satisfies the conditions of the problem.
When the number of sailors is a parameter, let it be
m
m
The first step is to obtain an algebraic expansion of the recurrence relation corresponding to each sailor's transformation of the pile,
ni
ni=
m-1 | |
m |
(ni-1-1)
ni → \equivN
ni →
ni
ni-1
m
n | ||||
|
\right)m ⋅ n0-\left[(
m-1 | |
m |
| ||||
) |
| ||||
) |
\right]
n | ||||
|
\right)m ⋅ n0-\left(
m-1 | |
m |
\right) ⋅ \left[(
m-1 | |
m |
)m-1+...+
m-1 | |
m |
+1\right]
xm-1+...+x+1
(1-xm)/(1-x)
n | ||||
|
\right)m ⋅ n0-\left(
m-1 | |
m |
\right) ⋅ \left[\left(1-(
m-1 | |
m |
| ||||
) |
)\right)\right]
n | ||||
|
\right)m ⋅ n0-(m-1) ⋅
mm-(m-1)m | |
mm |
nm
m
F
m ⋅ F=\left(
m-1 | |
m |
\right)m ⋅ n0-(m-1) ⋅
mm-(m-1)m | |
mm |
n0
N
N=mm ⋅
m-1+m ⋅ F | |
(m-1)m |
-(m-1)
The equation is a linear Diophantine equation in two variables,
N
F
m
m
Number theoretic considerations now apply. For
N
m-1+m ⋅ F | |
(m-1)m |
r
r= | m-1+m ⋅ F |
(m-1)m |
ax+by=\pm1
(m-1)m ⋅ r-m ⋅ s=-1
s=1+F
m
m-1
(r,s)
(m-1)m ⋅ r\equiv-1\modm
Bézout's identity gives the periodic solution
r=r0+k ⋅ m
r
N=r0 ⋅ mm-(m-1)+k ⋅ mm+1
r0=1
m
r0=-1
m
k
m
k
N
In the William's version of the problem,
m
r0
k
Here is a table of the positive solutions
N
m
k
m | N | |
---|---|---|
2 | 11+k ⋅ 8 | |
3 | 25+k ⋅ 81 | |
4 | 765+k ⋅ 1024 | |
5 | 3121+k ⋅ 15,625 | |
6 | 233,275+k ⋅ 279,936 | |
7 | 823,537+k ⋅ 5,764,801 | |
8 | 117,440,505+k ⋅ 134,217,728 |
Other variants, including the putative predecessor problem, have related general solutions for an arbitrary number of sailors.
When the morning division also has a remainder of one, the solution is:
N=-(m-1)+k ⋅ mm+1
m=5
k=1
In some earlier alternate forms of the problem, the divisions came out even, and nuts (or items) were allocated from the remaining pile after division. In these forms, the recursion relation is:
ni=
m-1 | |
m |
ni-1-1
N=-m+k ⋅ mm+1
m=4
k=1
When the morning division results in a nut left over, the general solution is:
N=r0 ⋅ mm-m+k ⋅ mm+1
r0=-1
m
r0=1
m
m=3
r0=-1
k=1
Other post-Williams variants which specify different remainders including positive ones (i.e. the monkey adds coconuts to the pile), have been treated in the literature. The solution is:
N=r0 ⋅ mm-c ⋅ (m-1)+k ⋅ mm+1
r0=1
m
r0=-1
m
c
k
c
Other variants in which the number of men or the remainders vary between divisions, are generally outside the class of problems associated with the monkey and the coconuts, though these similarly reduce to linear Diophantine equations in two variables. Their solutions yield to the same techniques and present no new difficulties.
r0=-1+1 ⋅ m
m
for
m
N=(1+m ⋅ k) ⋅ mm-(m-1)
for
m
N=(m-1+m ⋅ k) ⋅ mm-(m-1)
k