taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.2.8-1

Exercise 1.2.8-1

not stated yet in Lean solution written

Rating10
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 1.2.8 of Volume 1. Companion chapter: Fibonacci numbers

The task

Find how many pairs of rabbits exist after twelve months when one pair starts and each pair bears a new pair every month from the age of one month.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Let pnp_n be the number of pairs after nn months. Compare pn+2p_{n+2} with pn+1p_{n+1} and pnp_n.

Hint 2

All pairs of month n+1n+1 stay alive. A new pair is born for each pair that is at least one month old at that time. Which pairs are these?

Solution

Show the solution

Let pnp_n be the number of pairs after nn months, so p0=1p_0 = 1 and p1=2p_1 = 2 (the first pair and its first offspring).

Go from month n+1n+1 to month n+2n+2. No pair dies, so all pn+1p_{n+1} pairs stay. A pair bears a new pair in month n+2n+2 if it is at least one month old at month n+1n+1. These are the pairs that were alive after nn months, and there are pnp_n of them. The pairs born in month n+1n+1 are too young. Hence

pn+2=pn+1+pn.p_{n+2} = p_{n+1} + p_n.

This is the rule of the Fibonacci numbers. With p0=1=F2p_0 = 1 = F_2 and p1=2=F3p_1 = 2 = F_3, induction gives pn=Fn+2p_n = F_{n+2}. The values for n=0,1,…,12n = 0, 1, \ldots, 12 are

1,2,3,5,8,13,21,34,55,89,144,233,377.1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377.

After one year there are p12=F14=377p_{12} = F_{14} = 377 pairs. The count includes the original pair.

Check

Simulate the story with two counters, the mature pairs and the newborn pairs: each month the mature pairs stay and bear as many newborn pairs as there are mature pairs, and the old newborn pairs become mature. A run in python3 gives the totals 2,3,5,8,13,21,34,55,89,144,233,3772, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 for months 11 to 1212, which agrees with Fn+2F_{n+2}. As a test of the rule, 144+233=377144 + 233 = 377.

Remarks

The answer depends on the reading of the story. If the original pair is not counted, the answer is 376376. The usual reading counts every pair, and the answer is 377377. The number of pairs born in nn months is Fn+2−1F_{n+2} - 1 (Exercise 1.2.8-20). See the C1 chapter on Section 1.2.8 for the history of the problem.

This solution is checked, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.