The monkey and the coconuts facts for kids
The monkey and the coconuts is a mathematical puzzle in the field of Diophantine analysis that originated in a magazine fictional 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.
Contents
General description
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.
History
The origin of the class of such problems has been attributed to the Indian mathematician Mahāvīra in chapter VI, §1311⁄2, 1321⁄2 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. 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 1700BC. 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 appeared in the diaries of the mathematician and author Lewis Carroll ("Alice in Wonderland") in 1888, involving 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 comes out even. The problem never appeared in any of the author's published works, though from other references it appears the problem was in circulation in 1888. An almost identical problem soon appeared in W.W. Rouse Ball's Elementary Algebra, 1890. Such propinquity suggests a common source; dissemination of the problem may have occurred via Carroll's exchanges with Bartholomew Price, professor of mathematics and Carrol's friend and tutor. Four renditions of the problem existed: two forms, one with remainders of one and another with remainders of zero but nuts discarded after division, and two endings, one where the final division has a remainder and one where it comes out even (or no nuts are discarded). 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 device of marked objects (see Blue coconuts, below) to aid in conceptualizing the division with remainders first appeared in 1912 in the work of Norman H. Anning involving a bin of apples divided by three men.
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. 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. During the night, one man woke up and decided to take his share of the coconuts. He divided them into five piles. One coconut was left over so he gave it to the monkey, then hid his share, put the rest back together, and went back to sleep.
- Soon a second man woke up and did the same thing. After dividing the coconuts into five piles, one coconut was left over which he gave to the monkey. He then hid his share, put the rest back together, and went back to bed. The third, fourth, and fifth man followed exactly the same procedure. The next morning, after they all woke up, they divided the remaining coconuts into five equal shares. This time no coconuts were left over.
- 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. He stated that 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 doesn't indicate which versions Williams had access to. Gardner once told his son Jim that it was his favorite problem, so much so that he later chose to make it the first chapter of his "best of columns" collection, The Colossal Book of Mathematics. He said that the Monkey and the Coconuts is "probably the most worked on and least often solved" Diophantine puzzle. Since that time the Williams version of the problem has become a staple of recreational mathematics. The original story containing the problem was reprinted in full in Clifton Fadiman's 1962 anthology The Mathematical Magpie, a book that the Mathematical Association of America recommends for acquisition by undergraduate mathematics libraries.
Numerous variants which vary the number of sailors, monkeys, or coconuts have appeared in the literature.
Solutions
Diophantine analysis is the study of equations with rational coefficients requiring integer solutions. In Diophantine problems, there are fewer equations than unknowns. The "extra" information required to solve the equations is the condition that the solutions be integers. Any solution must satisfy all equations. Some Diophantine equations have no solution, some have one or a finite number, and others have infinitely many solutions.
The monkey and the coconuts reduces algebraically to a two variable linear Diophantine equation of the form
- ax + by = c, or more generally,
- (a/d)x + (b/d)y = c/d
where d is the greatest common divisor of a and b. By Bézout's identity, the equation is solvable if and only if d divides c. If it does, the equation has infinitely many periodic solutions of the form
- x = x0 + t · b,
- y = y0 + t · a
where (x0,y0) is a solution and t is a parameter than can be any integer. The problem is not intended to be solved by trial-and-error; there are deterministic methods for solving (x0,y0) in this case (see text).
Numerous solutions starting as early as 1928 have been published both for the original problem and Williams modification. Clever and succinct solutions using modulo congruences, sieves, and alternate number bases have been devised based partly or mostly on the recursive definition of the problem, a structure that won't be applicable in the general case. The smallest positive solutions to both versions are sufficiently large that trial and error is very likely to be fruitless. An ingenious concept of negative coconuts was introduced that fortuitously solves the original problem. Formalistic solutions are based on Euclid's algorithm applied to the Diophantine coefficients. Finally, the calculus of finite differences yields a parameterized general solution for any number of sailors and all multiples of coconuts that could have been on the original pile. In modern times, a computer brute force search over the positive integers quickly yields the solution.
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 number will 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 isn't trivially small, like 5 or 10 (that's 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's no simple way of estimating what the solution will be.
The original version
A summary analysis of both the original problem and Williams's version was presented by Martin Gardner when he featured the problem in his Mathematical Games column. Gardner begins by solving the original problem because it is less confounding than the Williams variation. Let N be the size of the original pile and 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 F · 5+1. If that quantity is designated n, the number remaining before the last sailor's division is:
reversing the procedure of the sailor during the night. But each sailor followed the same procedure; there are thus defined a recursive series of 5 such s (replacing with and generating a new ), the fifth and last of which is N itself, the number of coconuts before the division by the first sailor. Successively substituting the s and yields:
which reduces to the Diophantine equation:
By a fundamental theorem, this equation has a solution if and only if 11529 is a multiple of the Greatest Common Divisor of 1024 and 15625. 1024=45 and 15625=56, so their GCD is 1, and 11529 is a multiple of 1 so the equation is solvable.
Gardner points out that this equation is much too difficult to solve by trial and error. Moreover, it has an infinite number of solutions. But Gardner was mistaken about the difficulty. In fact, if (N, F) is a solution then so is (N + 15625 t, F + 1024 t) for any integer t. This means that the equation also has solutions in negative integers. Trying out a few small negative numbers it turns out N = -4 and F = -1 is a solution. This involves the absurd notion of negative coconuts; so we add 15625 to -4 and add 1024 to -1 to get the smallest positive solution (15621, 1023).
Williams version
The negative coconuts approach doesn't apply to the Williams version, at least not for any reasonably small |N|, so a more systematic approach is needed.
Using a sieve
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 isn't 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.
Blue coconuts
Another device predating the problem, is to use extra or marked objects, in this case blue coconuts, to clarify the division process. Suppose that the first sailor before the division, adds four blue coconuts to the pile to guarantee division by 5 (since we know even if he doesn't, that there's going to be a remainder of 1, so adding 4 makes the pile divisible by 5). He divides the pile, takes the fifth with an extra (non-blue) coconut which he tosses to the monkey, hides his share, then puts the rest back together, putting the 4 blue coconuts to the side. Each sailor does the same. After the fifth sailor (or after the division in the morning if there's a remainder there), the blue coconuts are left on the side, belonging to no one. Since the original pile is divided 5 times (or 6, if there's a remainder in the morning), including the blue coconuts it must have been 55 (56) coconuts. That makes the pile 3125-4=3121 (15625-4=15621) coconuts. The blue coconuts may be considered to be "virtual" coconuts which play no role in the problem, only serving to clarify the divisibility.
Base 5 numbering
A simple and obvious 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're 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 now it 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 numerical approach
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 3125 · 1, so N = 3125 – 4 = 3121; the number left in the morning comes to 1020, which is evenly divisible by 5 as required.
Modulo congruence
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 with one 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 5 · 1+1=6 is a solution. In fact any multiple of five plus one is a solution, so a possible general formula is 5 · k - 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.
If two divisions are done, a multiple of 5 · 5=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 k · 25 - 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 left over, 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 convenient use 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,
- (mod 5) (the –1 is the nut tossed to the monkey)
- (mod 5)
- (mod 5) (–4 is the congruence class)
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 Diophantine equation and forms of solution
The equivalent Diophantine equation for this version is:
- (1)
where N is the original number of coconuts, and F is the number received by each sailor on the final division in the morning. This is only trivially different than the equation above for the predecessor problem, and solvability is guaranteed by the same reasoning.
Reordering,
- (2)
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=x0 · 8404, F0=y0 · 8404 is a solution of (2), which means any solution must have the form
- (3)
where is an arbitrary parameter that can have any integral value.
A reductionist approach
One can take both sides of (1) above modulo 1024, so
Another way of thinking about it is that in order for to be an integer, the RHS of the equation must be an integral multiple of 1024; that property will be unaltered by factoring out as many multiples of 1024 as possible from the RHS. Reducing both sides by multiples of 1024,
subtracting,
factoring,
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 1 · 1024, so 5F+4=1024 and F=204. Substituting into (1)
Euclidean algorithm
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 (see (3) in the previous subsection) that will make both N and F positive is 2569, so:
Continued fraction
Alternately, one may use a continued fraction, whose construction is based on the Euclidean algorithm. The continued fraction for 1024⁄15625 (0.065536 exactly) is [;15,3,1,6,2,1,3]; its convergent terminated after the repetend is 313⁄4776, giving us x0=–4776 and y0=313. The least value of t for which both N and F are non-negative is 2569, so
- .
This is the smallest positive number that satisfies the conditions of the problem.
A generalized solution
When the number of sailors is a parameter, let it be , rather than a computational value, careful algebraic reduction of the relation between the number of coconuts in the original pile and the number allotted to each sailor in the morning yields an analogous Diophantine relation whose coefficients are expressions in .
The first step is to obtain an algebraic expansion of the recurrence relation corresponding to each sailor's transformation of the pile, being the number left by the sailor:
where , the number originally gathered, and the number left in the morning. Expanding the recurrence by substituting for times yields:
Factoring the latter term,
The power series polynomial in brackets of the form sums to so,
which simplifies to:
But is the number left in the morning which is a multiple of (i.e. , the number allotted to each sailor in the morning):
Solving for (=),
The equation is a linear Diophantine equation in two variables, and . is a parameter that can be any integer. The nature of the equation and the method of its solution do not depend on .
Number theoretic considerations now apply. For to be an integer, it is sufficient that be an integer, so let it be :
The equation must be transformed into the form whose solutions are formulaic. Hence:
- , where
Because and are relatively prime, there exist integer solutions by Bézout's identity. This equation can be restated as:
But (m–1)m is a polynomial Z · m–1 if m is odd and Z · m+1 if m is even, where Z is a polynomial with monomial basis in m. Therefore r0=1 if m is odd and r0=–1 if m is even is a solution.
Bézout's identity gives the periodic solution , so substituting for in the Diophantine equation and rearranging:
where for odd and for even and is any integer. For a given , the smallest positive will be chosen such that satisfies the constraints of the problem statement.
In the William's version of the problem, is 5 sailors, so is 1, and may be taken to be zero to obtain the lowest positive answer, so N = 1 · 55 – 4 = 3121 for the number of coconuts in the original pile. (It may be noted that the next sequential solution of the equation for k=–1, is –12504, so trial and error around zero will not solve the Williams version of the problem, unlike the original version whose equation, fortuitously, had a small magnitude negative solution).
Here is a table of the positive solutions for the first few ( is any non-negative integer):
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 |
Other Variants and general solutions
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:
For and this yields 15,621 as the smallest positive number of coconuts for the pre-William's version of the problem.
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:
The alternate form also had two endings, when the morning division comes out even, and when there is one nut left over for the monkey. When the morning division comes out even, the general solution reduces via a similar derivation to:
For example, when and , the original pile has 1020 coconuts, and after four successive even divisions in the night with a coconut allocated to the monkey after each division, there are 80 coconuts left over in the morning, so the final division comes out even with no coconut left over.
When the morning division results in a nut left over, the general solution is:
where if is odd, and if is even. For example, when , and , the original pile has 51 coconuts, and after three successive divisions in the night with a coconut allocated to the monkey after each division, there are 13 coconuts left over in the morning, so the final division has a coconut left over for the monkey.
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:
where for odd and for even, is the remainder after each division (or number of monkeys) and is any integer ( is negative if the monkeys add coconuts to the pile).
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.