Jump to content

The monkey and the coconuts

From Wikipedia, the free encyclopedia
(Redirected from Monkey and the coconuts)

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.

General description

[edit]

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

[edit]

The origin of the class of such problems has been attributed to the Indian mathematician Mahāvīra in chapter VI, § 13112, 13212 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 300 BC.

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[which?] it appears the problem was in circulation in 1888. An almost identical problem appeared in W.W. Rouse Ball's Elementary Algebra (1890).[citation needed] The problem was mentioned in works of period mathematicians, with solutions, mostly wrong, indicating that the problem was new and unfamiliar at the time.[citation needed]

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[3] (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.[3]

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.[4] Gardner once told his son Jim that it was his favorite problem.[5] He said that the Monkey and the Coconuts is "probably the most worked on and least often solved" Diophantine puzzle.[2] 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]

Solutions

[edit]
A Diophantine problem

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 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.[10] 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.[11][12][13][14]

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 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.

The original version

[edit]
Original version, with one coconut left over

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 ; the number present when the fifth sailor awoke was ; the number present when the fourth sailor awoke was ; and so on. We find that the size N of the original pile satisfies the Diophantine equation[3]

Gardner points out that this equation is "much too difficult to solve by trial and error,"[3] but presents a solution he credits to J. H. C. Whitehead (via Paul Dirac):[3] The equation also has solutions in negative integers. Trying out a few small negative numbers it turns out is a solution.[15] We add 15625 to N and 1024 to F to get the smallest positive solution: .

Williams version

[edit]
Williams's version, with no coconuts left over

Trial and error fails to solve Williams's version, so a more systematic approach is needed.

Using a sieve

[edit]

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.

Blue coconuts

[edit]

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.[3][16]

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.

Base 5 numbering

[edit]

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 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

[edit]

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

[edit]

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.[17]

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

[edit]

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

[edit]

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

[edit]

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

[edit]

Alternately, one may use a continued fraction, whose construction is based on the Euclidean algorithm. The continued fraction for 102415625 (0.065536 exactly) is [;15,3,1,6,2,1,3];[18] its convergent terminated after the repetend is 3134776, 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

[edit]

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.[19] 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 [20]
3
4
5
6
7
8

Other variants and general solutions

[edit]

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.

See also

[edit]

References

[edit]
  1. ^ Chronology of Recreational Mathematics by David Singmaster
  2. ^ a b Pleacher (2005)
  3. ^ a b c d e f Martin Gardner (2001). The Colossal Book of Mathematics. W.W. Norton & Company. pp. 3–9. ISBN 0-393-02023-1.
  4. ^ Antonick (2013)
  5. ^ Antonick (2013): "I then asked Jim if his father had a favorite puzzle, and he answered almost immediately: 'The monkeys [sic] and the coconuts. He was quite fond of that one.'"
  6. ^ Wolfram Mathworld
  7. ^ KIRKUS REVIEW of The Mathematical Magpie July 27, 1962
  8. ^ The Mathematical Magpie, by Clifton Fadiman, Mathematical Association of America, Springer, 1997
  9. ^ Pappas, T. "The Monkey and the Coconuts." The Joy of Mathematics. San Carlos, CA: Wide World Publ./Tetra, pp. 226-227 and 234, 1989.
  10. ^ d can be found if necessary via Euclid's algorithm
  11. ^ Underwood, R. S., and Robert E. Moritz. "3242." The American Mathematical Monthly 35, no. 1 (1928): 47-48. doi:10.2307/2298601.
  12. ^ Kirchner, Roger B. "The Generalized Coconut Problem," The American Mathematical Monthly 67, no. 6 (1960): 516-19. doi:10.2307/2309167.
  13. ^ S. Singh and D. Bhattacharya, “On Dividing Coconuts: A Linear Diophantine Problem,” The College Mathematics Journal, May 1997, pp. 203–4
  14. ^ G. Salvatore and T. Shima, "Of coconuts and integrity," Crux Mathematicorum, 4 (1978) 182–185
  15. ^ Bogomolny (1996)
  16. ^ Norman H. Anning (June 1912). "Problem Department (#288)". School Science and Mathematics. 12 (6).
  17. ^ A special case is when k=0, so the initial pile contains -4 coconuts. This works because after tossing one positive coconut to the monkey, there are -5 coconuts in the pile. After division, there remain -4 coconuts. No matter how many such divisions are done, the remaining pile will contain -4 coconuts. This is a mathematical anomaly called a "fixed point". Only a few problems have such a point, but when there is one, it makes the problem much easier to solve. All solutions to the problem are multiples of 5 added to or subtracted from the fixed point.
  18. ^ See here for an exposition of the method.
  19. ^ Gardner gives an equivalent but rather cryptic formulation by inexplicably choosing the non-canonical when is even, then refactoring the expression in a way that obscures the periodicity:
    for odd,  
    for even,
    where is a parameter than can be any integer.
  20. ^ While N=3 satisfies the equation, 11 is the smallest positive number that gives each sailor a non-zero positive number of coconuts on each division, an implicit condition of the problem.

Sources

[edit]
[edit]