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

Exercise 1.2.8-37

not stated yet in Lean solution written

RatingM35
MarkersM (mathematical)
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 the best first move in the chip game with 1000 chips, where each move takes at most twice what the opponent took and the first move may not take all chips.

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

Look for the winning condition in the Fibonacci number system of Exercise 1.2.8-34. Let μ(n)\mu(n) be the smallest term of the representation of nn.

Hint 2

Claim: the player to move with nn chips and the limit qq wins if and only if μ(n)≤q\mu(n) \le q. Prove it by induction on nn.

Hint 3

The winning move is to take μ(n)\mu(n) chips. For the other direction, bound μ(n−t)\mu(n - t) for t<μ(n)t < \mu(n).

Solution

Show the solution

Plan. Define the game state (n,q)(n, q): nn chips are left and the mover may take tt chips with 1≤t≤min⁡(n,q)1 \le t \le \min(n, q). The mover who takes the last chip wins. The first player has the state (1000,999)(1000, 999). For n≥1n \ge 1 let μ(n)=Fkr\mu(n) = F_{k_r} be the smallest term in the Fibonacci representation n=Fk1+⋯+Fkrn = F_{k_1} + \cdots + F_{k_r} of Exercise 1.2.8-34, with k1≫⋯≫kr≥2k_1 \gg \cdots \gg k_r \ge 2.

Claim. In the state (n,q)(n, q) with n≥1n \ge 1 the mover has a winning strategy if and only if μ(n)≤q\mu(n) \le q.

Two facts about μ\mu are needed. Write k=krk = k_r for the index of μ(n)\mu(n).

Fact 1. If n>μ(n)n > \mu(n), then μ(n−μ(n))>2μ(n)\mu(n - \mu(n)) > 2\mu(n). Indeed μ(n−μ(n))=Fkr−1\mu(n - \mu(n)) = F_{k_{r-1}} with kr−1≥k+2k_{r-1} \ge k + 2, and Fk+2=2Fk+Fk−1>2FkF_{k+2} = 2F_k + F_{k-1} > 2F_k because Fk−1≥1F_{k-1} \ge 1 for k≥2k \ge 2.

Fact 2. If 0<t<μ(n)=Fk0 < t < \mu(n) = F_k, then μ(n−t)≤2t\mu(n - t) \le 2t. Proof. Let g=Fk−tg = F_k - t, so 0<g<Fk0 < g < F_k. The representation of n−t=(n−Fk)+gn - t = (n - F_k) + g is that of n−Fkn - F_k (terms of index at least k+2k + 2) followed by that of gg (terms of index at most k−1k - 1). The gap between the two parts is at least 33, so the combined list is admissible, and it is the representation of n−tn - t by uniqueness. Hence μ(n−t)=μ(g)\mu(n - t) = \mu(g). Let μ(g)=Fi\mu(g) = F_i. All terms of gg have index in [i,k−1][i, k-1], and they have gaps at least 22. A set of such indices has the sum at most Fk−Fi−1F_k - F_{i-1}. (Induction on the number of terms: if j≤k−1j \le k - 1 is the largest index, the sum is at most Fj+(Fj−1−Fi−1)=Fj+1−Fi−1≤Fk−Fi−1F_j + (F_{j-1} - F_{i-1}) = F_{j+1} - F_{i-1} \le F_k - F_{i-1}, using the bound for indices in [i,j−2][i, j-2], or the empty set when j−2<ij - 2 < i.) So g≤Fk−Fi−1g \le F_k - F_{i-1}, which gives t=Fk−g≥Fi−1t = F_k - g \ge F_{i-1}. Since Fi≤2Fi−1F_i \le 2F_{i-1}, it follows that μ(n−t)=Fi≤2t\mu(n - t) = F_i \le 2t.

Proof of the claim, by induction on nn.

Winning side. Let μ(n)≤q\mu(n) \le q. If q≥nq \ge n, the mover takes all chips and wins. Otherwise the mover takes t=μ(n)t = \mu(n). If n=tn = t, the mover has won. Otherwise the opponent has the state (n−t,2t)(n - t, 2t), and μ(n−t)>2t\mu(n - t) > 2t by Fact 1. By the induction hypothesis the opponent loses.

Losing side. Let μ(n)>q\mu(n) > q. A move takes t≤q<μ(n)t \le q < \mu(n) chips, and t<nt < n because μ(n)≤n\mu(n) \le n. The opponent gets (n−t,2t)(n - t, 2t) and μ(n−t)≤2t\mu(n - t) \le 2t by Fact 2. By the induction hypothesis the opponent wins. So every move loses.

The answer. 1000=987+13=F16+F71000 = 987 + 13 = F_{16} + F_7, so μ(1000)=13≤999\mu(1000) = 13 \le 999 and the first player wins. The move is to take 1313 chips, which leaves 987987 for the opponent with the limit 2626, and μ(987)=987>26\mu(987) = 987 > 26.

A python search over every first move t=1,…,999t = 1, \ldots, 999 shows that 1313 is the only winning first move. The first player wins from every pile nn that is not a Fibonacci number, and loses for a Fibonacci number n≥2n \ge 2, where μ(n)=n>n−1\mu(n) = n > n - 1.

Check

With python and a full search of the game tree for all piles n<160n < 160 and all limits: the mover wins in (n,q)(n, q) exactly when μ(n)≤q\mu(n) \le q. For n=1000n = 1000 the only first move with μ(1000−t)>2t\mu(1000 - t) > 2t is t=13t = 13. Small cases: n=4=3+1n = 4 = 3 + 1 gives μ=1≤3\mu = 1 \le 3 and the winning move is 11: the opponent has 33 chips and limit 22, takes 11 or 22, and then the first player takes the last 22 or 11. For n=5n = 5, a Fibonacci number, every first move loses.

Remarks

A full search for small piles shows which moves win in (n,q)(n, q): the move must take a tail Tj=Fkj+⋯+FkrT_j = F_{k_j} + \cdots + F_{k_r} of the representation with Tj≤qT_j \le q, where either j=1j = 1 or the term just above the tail is more than 2Tj2T_j. Fact 1 is the case j=rj = r. This is the game of Fibonacci Nim. Exercise 1.2.8-38 asks for a program that plays it.

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.