Problem Solving and Recreational Mathematics
Paul Yiu
Department of Mathematics Florida Atlantic University
Summer 2016
April 4, 2016
Contents
1 Arithmetic Problems 101 1.1 Reconstruction of division problems ...... 101 1.1.1 AMM E1 ...... 101 1.1.2 AMM E10 ...... 103 1.1.3 AMM E1111 ...... 104 1.1.4 AMM E971 ...... 105 1.1.5 AMM E198 ...... 106
2 Digit problems 107 2.1 When can you cancel illegitimately and yet get the cor- rect answer? ...... 107 2.2 Repdigits ...... 109 2.3 Sums of squares of digits ...... 112
3 Representation of a number in different bases 115 3.1 Base b-representation of a number ...... 115 3.1.1 A number from its base b-representation . ....116 3.2 The Josephus problem ...... 119
4 Representation of a number in different bases 121 4.1 Balanced division by an odd number ...... 121 4.2 Balanced base b representation of a number ...... 121 4.3 Arithmetic in balanced base 3 representations . ....123 4.3.1 A matrix card trick ...... 124
5 Cheney’s card trick 127 5.1 Three basic principles ...... 127 5.1.1 The pigeonhole principle ...... 127 5.1.2 Arithmetic modulo 13 ...... 127 iv CONTENTS
5.1.3 Permutations of three objects ...... 128 5.2 Examples ...... 129 5.3 A variation: Cheney card trick with spectator choosing secret card ...... 131
6 The nim game 133 6.1 Thenimsum...... 133 6.2 Thenimgame...... 134
7 Fibonacci and Lucas numbers 137 7.1 The Fibonacci sequence ...... 137 7.2 Some relations of Fibonacci numbers ...... 140 7.3 Zeckendorff representations ...... 141 7.4 The Lucas numbers ...... 142 7.5 How can we know if a given integer is a Fibonacci number? ...... 143 7.6 Periodicity of Fibonacci sequence mod m ...... 144
8 Counting with Fibonacci numbers 145 8.1 Squares and dominos ...... 145 8.2 Fat subsets of [n] ...... 146 8.3 An arrangement of pennies ...... 147 8.4 Counting circular permutations ...... 149
9 Floor and Ceiling 201 9.1 Clock problems ...... 201 9.2 Some equations involving x ...... 202 9.3 Number of trialing zeros in n! ...... 203 9.4 Characterizations of the ceiling and floor functions . . . 204
10 Combinatorial games 207 10.1 Subtraction games ...... 207 10.2 The Sprague-Grundy sequence ...... 209
11 Permutations 213 11.1 The universal sequence of permutations ...... 213 11.2 The position of a permutation in the universal sequence 214 11.3 The disjoint cycle decomposition of a permutation . . . 216 11.4 Lexicographical ordering of permutations ...... 217 11.5 Dudeney’s puzzle ...... 221 CONTENTS v
11.6 Problems on permutations ...... 224
12 Perfect card shuffles 227 12.1 In-shuffles ...... 229 12.2 Out-shuffles ...... 231 12.3 Perfect shuffling a card to a specified position . ....232
13 Interpolation problems 233 13.1 What is f(n +1)if f(k)=2k for k =0, 1, 2 ...,n? . . 233 1 13.2 What is f(n +1)if f(k)= k+1 for k =0, 1, 2 ...,n? . 235 13.3 Why is ex not a rational function? ...... 237
14 Transferrable numbers 239 14.1 Right-transferrable numbers ...... 239 14.2 Left-transferrable integers ...... 241
15 The equilateral lattice L (n) 245 15.1 Counting triangles ...... 245 15.2 Counting parallelograms ...... 248 15.3 Counting regular hexagons ...... 249
16 Counting triangles 253 16.1 Integer triangles of sidelengths ≤ n ...... 253 16.2 Integer scalene triangles with sidelengths ≤ n .....254 16.3 Number of integer triangles with perimeter n ...... 255 16.3.1 The partition number p3(n) ...... 255
17 Pythagorean triangles 301 17.1 Primitive Pythagorean triples ...... 301 17.1.1 Rational angles ...... 302 17.1.2 Some basic properties of primitive Pythagorean triples ...... 302 17.2 A Pythagorean triangle with an inscribed square ....304 17.3 When are x2 − px ± q both factorable? ...... 305 17.4 Dissection of a square into Pythagorean triangles ....305
18 The area of a triangle 307 18.1 Heron’s formula for the area of a triangle ...... 307 18.2 Heron triangles ...... 309 18.2.1 The perimeter of a Heron triangle is even ....309 vi CONTENTS
18.2.2 The area of a Heron triangle is divisible by 6 . . 309 18.2.3 Heron triangles with sides < 100 ...... 310 18.3 Heron triangle as lattice triangle ...... 311 18.4 Indecomposable Heron triangles ...... 312 18.5 Heron triangles with area equal to perimeter ...... 314 18.6 Heron triangles with integer inradii ...... 315 18.7 Heron triangles with square areas ...... 316
19 The golden ratio 317 19.1 Division of a segment in the golden ratio ...... 317 19.2 The regular pentagon ...... 319 19.3 Construction of 36◦, 54◦, and 72◦ angles ...... 320 19.4 The most non-isosceles triangle ...... 324
20 The Arbelos 325 20.1 Archimedes’ twin circle theorem ...... 325 20.2 Incircle of the arbelos ...... 326 20.2.1 Construction of incircle of arbelos ...... 327 20.3 Archimedean circles in the arbelos ...... 328
21 Menelaus and Ceva theorems 331 21.1 Menelaus’ theorem ...... 331 21.2 Ceva’s theorem ...... 333
22 Routh and Ceva theorems 339 22.1 Barycentric coordinates ...... 339 22.2 Cevian and traces ...... 340 22.3 Area and barycentric coordinates ...... 342
23 Perimeter - area bisectors of a triangle 347 23.1 Construction of perimeter-area bisectors in angle A . . 348 23.2 Isosceles triangles ...... 349 23.3 Scalene triangles ...... 350 23.4 Triangles with exactly two perimeter-area bisectors . . 352 23.5 Integer triangles ...... 353 23.5.1 Triangles with Da < 0 ...... 353 23.5.2 Triangles with Da =0 ...... 354 23.5.3 Triangles with Da > 0 ...... 354
24 Very Small Integer Triangles 357 CONTENTS vii
25 The games of Euclid and Wythoff 401 25.1 The game of Euclid ...... 401 25.2 Wythoff’s game ...... 403 25.3 Beatty’s Theorem ...... 405
26 Number sequences 407 26.1 The Farey sequence ...... 407 26.2 The number spiral ...... 410 26.3 The prime number spirals ...... 412 26.4 The prime number spiral beginning with 17 ...... 413 26.5 The prime number spiral beginning with 41 ...... 414 26.6 Two enumerations of the rational numbers in (0,1) . . . 416
27 Inequalities 417 27.1 The inequality AGH2 ...... 417 27.2 Proofs of the A-G inequality ...... 420 27.3 The AGH mean inequality ...... 422 27.4 Cauchy-Schwarz inequality ...... 424 27.5 Convexity ...... 427 27.6 The power mean inequality ...... 429 27.7 Bernoulli inequality ...... 430 27.8 Holland’s Inequality ...... 430 27.9 Miscellaneous inequalities ...... 432 27.10 A useful variant of AG2 ...... 433
28 Calculus problems 435 28.1 Philo’s line ...... 435 28.1.1 Triangle with minimum perimeter ...... 436 28.2 Maxima and minima without calculus ...... 440
29 449 29.1 Quartic polynomials and the golden ratio ...... 449
30 Infinite Series 453 30.1 Power series ...... 453 30.2 The Bernoulli numbers and the tangent function ....455 30.3 The Euler numbers and the secant function ...... 457 30.4 Summation of finite series ...... 458 viii CONTENTS
31 The art of integration 461 31.1 Indefinite integrals ...... 461 31.2 An iterated integral and a generalization ...... 463 31.2.1 Crux Math. 3913 ...... 463 31.2.2 A generalization ...... 464
32 Rearrangements of the alternating harmonic series 467 32.1 Riemann’s theorem on conditionally convergent series . 467 32.2 Rearrangements of the alternating harmonic series . . . 468 Chapter 1
Arithmetic Problems
1.1 Reconstruction of division problems
1.1.1 AMM E1
This is Problem E1 of the AMERICAN MATHEMATICAL MONTHLY: x 7 xxx xxx) xxxxxxxx xxxx xxx xxx xxxx xxx xxxx xxxx Clearly, the last second digit of the quotient is 0. Let the divisor be the 3-digit number d. Consider the 3-digit number in the seventh line, which is a multiple of d. Its difference from the 4-digit number in the sixth line is a 2-digit number. This must be 9xx. This cannot be the same as the 3-digit number in the fifth line, since the difference between the 3-digit numbers in the fourth and fifth lines is a 3-digit number. Therefore, in the quotient, the digit after 7 is a larger one, which must be smaller than the first and the last digits, since these give 4-digit multiples of d. It follows that the quotient is 97809. 102 Arithmetic Problems
Since 8d is a 3-digit number 9xx, the 4-digit number in the third and bottom lines is 9d =10xx or 11xx. From this 8d must be 99x, and therefore 992 = 8 × 124.
97809 124)12128316 1116 968 868 1003 992 1116 1116 1.1 Reconstruction of division problems 103
1.1.2 AMM E10
This is Problem E10 of the MONTHLY, by Fitch Cheney. In this case, not even one single digit is given.
xxxxxx xxx) xxxxxxxx xxx xxxx xxx xxxx xxx xxxx xxxx 104 Arithmetic Problems
1.1.3 AMM E1111
This is said to be the most popular MONTHLY problem. It appeared in the April issue of 1954. Our good friend and eminent numerologist, Professor Euclide Paracelso Bombasto Umbugio, has been busily engaged test- ing on his desk calculator the 81 · 109 possible solutions to the problem of reconstructing the following exact long division in which the digits indiscriminately were each replaced by x save in the quotient where they were almost entirely omitted.
xx8xx xxx)xxxxxxxx xxx xxxx xxx xxxx xxxx
Deflate the Professor! That is, reduce the possibilities to (18 · 109)0.
Martin Gardner’s remark: Because any number raised to the power of zero is one, the reader’s task is to discover the unique reconstruction of the problem. The 8 is in correct position above the line, making it the third digit of a five-digit answer. The problem is easier than it looks, yielding readily to a few elementary insights. 1.1 Reconstruction of division problems 105
1.1.4 AMM E971 Reconstruct the division problem ∗∗∗∗∗ ∗∗) ∗∗∗∗2 ∗ ∗∗ ∗∗∗ ∗∗ ∗∗∗ ∗∗∗ ∗∗ ∗∗
Charles Twigg comments that if the digit 2 is replaced by 9, the answer is also unique. ∗∗∗∗∗ ∗∗) ∗∗∗∗9 ∗ ∗∗ ∗∗∗ ∗∗ ∗∗∗ ∗∗∗ ∗∗ ∗∗ 106 Arithmetic Problems
1.1.5 AMM E198 Here is a multiplication problem: A multiplication of a three-digit number by 2-digit number has the form in which all digits involved are prime numbers. Reconstruct the multi- plication. (Note that 1 is not a prime number).
ppp × pp pppp p ppp p pppp Chapter 2
Digit problems
2.1 When can you cancel illegitimately and yet get the correct answer?
Let ab and bc be 2-digit numbers. When do such illegitimate cancella- tions as ab ab a bc = bc = c ,
a allowing perhaps further simplifications of c ? 16 1 19 1 26 2 49 4 Answer. 64 = 4 , 95 = 5 , 65 = 5 , 98 = 8 . Solution. We may assume a, b, c not all equal. ≤ 10a+b a Suppose a, b, c are positive integers 9 such that 10b+c = c . (10a + b)c = a(10b + c),or(9a + b)c =10ab. If any two of a, b, c are equal, then all three are equal. We shall therefore assume a, b, c all distinct. 9ac = b(10a − c). If b is not divisible by 3, then 9 divides 10a − c =9a +(a − c).It follows that a = c, a case we need not consider. It remains to consider b =3, 6, 9. Rewriting (*) as (9a + b)c =10ab. If c is divisible by 5, it must be 5, and we have 9a + b =2ab. The only possibilities are (b, a)=(6, 2), (9, 1), giving distinct (a, b, c)=(1, 9, 5), (2, 6, 5). If c is not divisible by 5, then 9a + b is divisible by 5. The only possibilities of distinct (a, b) are (b, a)=(3, 8), (6, 1), (9, 4). Only the 108 Digit problems latter two yield (a, b, c)=(1, 6, 4), (4, 9, 8).
Exercise 1. Find all possibilities of illegitimate cancellations of each of the fol- lowing types, leading to correct results, allowing perhaps further simplifications.
abc c (a) bad = d , cab c (b) dba = d , abc a (c) bcd = d .
2. Find all 4-digit numbers like 1805 = 192 × 5, which, when divided by the its last two digits, gives the square of the number one more than its first two digits. 2.2 Repdigits 109
2.2 Repdigits
A repdigit is a number whose decimal representation consists of a rep- etition of the same decimal digit. Let a be an integer between 0 and 9. For a positive integer n, the repdigit an consists of a string of n digits each equal to a. Thus, a n an = (10 − 1). 9 Example 2.1. Show that 16n 1 19n 1 26n 2 49n 4 = , = , = , = . 6n4 4 9n5 5 6n5 5 9n8 8
abn a Solution. More generally, we seek equalities of the form bnc = c for distinct integer digits a, b, c. Here, abn is digit a followed by n digits each equal to b. To avoid confusion, we shall indicate multiplication with the sign ×. The condition (abn) × c =(bnc) × a is equivalent to b 10b 10na + (10n − 1) c = (10n − 1) + c a, 9 9 b 10b (10n − 1)a + (10n − 1) c = (10n − 1) a. 9 9 10n−1 Cancelling a common divisor 9 , we obtain (9a + b)c =10ab, which ab a is the same condition for bc = c .
Exercise 1. Complete the following multiplication table of repdigits.
1n 2n 3n 4n 5n 6n 7n 8n 9n 1 1n 2n 3n 4n 5n 6n 7n 8n 9n 2 4n 6n 8n 1n013n−1215n−1417n−1619n−18 3 9n 13n−1216n−1519n−1823n−1126n−1429n−17 4 17n−162n026n−1431n−208 35n−1239n−16 5 27n−153n038n−154n049n−15 6 39n−1646n−1253n−228 59n−14 7 54n−239 62n−216 69n−13 8 71n−204 79n−12 9 98n−201
2. Simplify (1n)(10n−15). Answer. (1n)(10n−15) = 1n5n. 110 Digit problems
Exercise 1. Find the three 3-digit numbers each of which is equal to the product of the sum of its digits by the sum of the squares of its digits. Answer. 133, 315, 803. √ 2. Find all 4-digit numbers abcd such that 3 abcd = a + b + c + d. Answer. 4913 and 5832. Solution. There are only twelve 4-digit numbers which are cubes. For only two of them is the cube root equal to the sum of digits.
n 10 11 12 13 14 17 16 17 18 19 20 21 n3 1000 1331 1728 2197 2744 3375 4096 4913 5832 6859 8000 9261 ∗∗∗ ∗∗∗
3. Use each digit 1, 2, 3, 4, 5, 6, 7, 8, 9 exactly once to form prime numbers whose sum is smallest possible. What if we also include the digit 0? 4. There are exactly four 3-digit numbers each equal to the sum of the cubes of its own digits. Three of them are 153, 371, and 407. What is the remaining one? 5. Find all possibilities of a 3-digit number such that the three num- bers obtained by cyclic permutations of its digits are in arithmetic progression. Answer. 148, 185, 259, 296. Solution. Let abc be one such 3-digit numbers, with a smallest among the digits (which are not all equal). The other two numbers are bca and cab. Their sum abc + bca + cab = 111 × (a + b + c). Therefore the middle number =37× (a + b + c). We need therefore look for numbers of the form abc =37× k with digit sum equal to s, and check if 37 × s = bca or cab. We may ignore multiples of 3 for k (giving repdigits for 37 × k). Note that 3k<27. We need only consider k =4, 5, 7, 8.
k 37 × ks 37 × s arithmetic progression 4 148 13 13 × 37 = 481 148, 481, 814 5 185 14 14 × 37 = 518 185, 518, 851 7 259 16 16 × 37 = 592 259, 592, 925 8 296 17 17 × 37 = 629 296, 629, 962 2.2 Repdigits 111
6. A 10-digit number is called pandigital if it contains each of the dig- its 0, 1, ..., 9 exactly once. For example, 5643907128 is pandigi- tal. We regard a 9-digit number containing each of 1,...,9 exactly once as pandigital (with 0 as the leftmost digit). In particular, the number A := 123456789 is pandigital. There are exactly 33 positive integers n for which nA are pandigital as shown below.
n nA n nA n nA 1 123456789 2 246913578 4 493827156 5 617283945 7 864197523 8 987654312 10 1234567890 11 1358024679 13 1604938257 14 1728395046 16 1975308624 17 2098765413 20 2469135780 22 2716049358 23 2839506147 25 3086419725 26 3209876514 31 3827160459 32 3950617248 34 4197530826 35 4320987615 40 4938271560 41 5061728349 43 5308641927 44 5432098716 50 6172839450 52 6419753028 53 6543209817 61 7530864129 62 7654320918 70 8641975230 71 8765432019 80 9876543120
How would you characterize these values of n? 7. Find the smallest natural number N, such that, in the decimal nota- tion, N and 2N together use all the ten digits 0, 1,...,9. Answer. N = 13485 and 2N = 26970. 112 Digit problems
2.3 Sums of squares of digits
Given a number N = a1a2 ···an of n decimal digits, consider the “sum of digits” function
2 2 2 s(N)=a1 + a2 + ···+ an. For example s(11) = 2,s(56) = 41,s(85) = 89,s(99) = 162.
For a positive integer N, consider the sequence S(N): N, s(N),s2(N), ...,sk(N), ..., where sk(N) is obtained from N by k applications of s. Theorem 2.1. For every positive integer N, the sequence S(N) is either eventually constant at 1 or periodic. The period has length 8 and form a cycle 37 58 16
89 1 4
145 20 42 A proof of the theorem is outlined in the following exercise. 2.3 Sums of squares of digits 113
Exercise 1. Prove by mathematical induction that 10n−1 > 81n for n ≥ 4. 2. Prove that if N has 4 or more digits, then s(N) (b, c) (5, 9) (6, 9) (7, 9) (8, 9) (9, 9) (6, 8) (7, 8) (8, 8) (9, 5) (9, 6) (9, 7) (9, 8) (8, 6) (8, 7) s(N) 107 118 131 146 183 101 114 129 Therefore there is no 3-digit number N satisfying s(N) ≥ N. 4. For a given integer N, there is k for which sk(N) is a 2-digit num- ber. 5. If n is one of the integers 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, then sk(N)=1for some k. 7 70 44 94 19 91 23 79 49 82 32 31 97 28 86 13 130 68 10 100 1 114 Digit problems 6. If N is a 2-digit integer other than 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, then the sequence S(N) is eventually cycling between 4, 16, 37, 58, 89, 145, 42, 20. 60 6 63 36 66 54 45 84 48 22 27 14 72 41 35 71 80 8 53 17 46 43 5 64 34 50 52 25 29 67 76 92 3 77 83 85 9 30 98 38 81 73 89 56 39 145 58 61 90 47 65 93 42 37 33 95 18 57 20 16 106 74 75 4 59 40 24 62 2 26 11 51 113 117 69 78 87 128 88 Chapter 3 Representation of a number in different bases 3.1 Base b-representation of a number Let b be a fixed positive integer. To write an integer n in base b, keep on dividing the number by b until the quotient is 0, and record the re- mainders, which are integers between 0 and b − 1, from right to left. The resulting sequence, which always begins with a nonzero leftmost digit, is the representation of n in base b. Example 3.1. (a) 123 = [1111011]2 divisor quotient remainder 2 123 1 61 1 30 0 15 1 7 1 3 1 1 1 0 116 Representation of a number in different bases (b) 123 = [11120]3 divisor quotient remainder 3 123 0 41 2 13 1 4 1 1 1 0 3.1.1 A number from its base b-representation Given the base b representation of an integer: n =[a0a1 ···ak−1ak]b, to find the integer in its decimal form, calculate a sequence of numbers n0, n1,...,nk as follows: (i) n0 = a0, (ii) for i =1, 2,...,k, ni = ai + b · ni−1. Then, n = nk. Example 3.2. (a) [1111011]2 = 123. 1 1 1 1 0 1 1 2 2 6 14 30 60 122 1 3 7 15 30 61 123 (b) [23147]11 = 33447. 2 3 1 4 7 11 22 275 3036 33440 2 25 276 3040 33447 Example 3.3. Ask your friend to think of a number between 1 and 31. Then ask her if the number appears in card (a), (b), (c), (d), or (e). Now add up the numbers from the lower left hand corners of the card which she answers yes. That is the number she has chosen. 3.1 Base b-representation of a number 117 4 4 7 15 23 31 7 15 23 31 3 3 5 13 21 29 6 14 22 30 2 2 3 11 19 27 3 11 19 27 1 1 1 9 17 25 2 10 18 26 0 0 0 1 2 3 4 0 1 2 3 4 4 4 7 15 23 31 14 28 25 9 3 3 6 14 22 30 12 31 27 11 2 2 5 13 21 29 10 26 30 13 1 1 4 12 20 28 8 24 29 15 0 0 0 1 2 3 4 0 1 2 3 4 4 20 28 25 17 3 22 31 27 19 2 18 26 30 23 1 16 24 29 21 0 0 1 2 3 4 118 Representation of a number in different bases Exercise 1. Complete the multiplication table in base 7. 1 2 3 4 5 6 1 1 2 3 4 5 6 2 2 3 3 12 4 4 5 5 6 6 15 51 2. Multiply in base 7: [12346]7 × [06]7 = [12346]7 × [15]7 = [12346]7 × [24]7 = [12346]7 × [33]7 = [12346]7 × [42]7 = [12346]7 × [51]7 = 3. Ask your friend to write down a polynomial f(x) with nonnegative integer coefficients. Ask her for the value of f(1). She returns 7. Ask her for the value of f(8). She returns 4305. What is the polynomial? 3.2 The Josephus problem 119 3.2 The Josephus problem There are n people, numbered consecutively, standing in a circle. First, Number 2 sits down, then Number 4, Number 6, etc., continuing around the circle with every other standing person sitting down until just one person is left standing. What number is this person? This is Problem 1031 of MATHEMATICS MAGAZINE, a reformula- tion of the Josephus problem. Here is M. Chamberlain’s solution: Write n =2m + k where 0 ≤ k ≤ 2m − 1. Then seat the people numbered 2, 4, ...,2k. This leaves 2m people standing, beginning with the person numbered 2k +1; call him Stan. Now continue to seat people until you get back to Stan. It is easy to see that 2m−1 people will be left standing, starting with Stan again. On every subsequent pass of the circle half of those standing will be left standing with Stan always the first among them. Stan’s the man. 2 6 4 3 * 1 5 2 3 6 1 8 7 10 7 5 8 9 4 9 Let J(n) be the position of the last standing man in a circle of n. Theorem 3.1. The binary expansion of J(n) is obtained by transferring the leftmost digit 1 of the binary expansion of n to the rightmost. Proof. If n =2m + k for k ≤ 2m, then J(n)=2(n − 2m)+1. The binary expansion of J(n) is obtained by moving the leftmost digit of the binary expansion of n (corresponding to 2m) to the rightmost. 120 Representation of a number in different bases Exercise 1. For what values of n is J(n)=n? 2. For what values of n is J(n)=n − 1? Chapter 4 Representation of a number in different bases 4.1 Balanced division by an odd number Given a positive integer b and a string of b consecutive integers, for every integer a, there are unique integers q and r so that a = bq + r with r in the given string of b consecutive integers. In particular, if b is odd, say b =2c +1, we may choose the string of remainders to be −c, −(c − 1), ..., −1, 0, 1, ..., c− 1,c. If we write a = bq + r, −c ≤ r ≤ c, we say that this is the balanced division of a by the odd number b. 4.2 Balanced base b representation of a number Let b be a positive odd number. The balanced base b representation of an integer n is obtained by repeatedly performing balanced divisions by b and recording, from right to left, the remainders, which are integers in − b−1 ··· − b−1 the range 2 , , 1, 0, 1, ..., 2 . We shall write 1, 2, 3, 4, ... in place of the negative remainders −1, −2, −3, −4, .... 122 Representation of a number in different bases Examples (1) 100 = 11011 3 divisor quotient remainder 3 100 1 33 0 11 1 4 1 1 1 0 The balanced ternary form of a number expresses it as a sum and/or differences of distinct powers of 3: 100 = 34 +33 − 32 +1. Here is a simple application of the balanced ternary expansion of numbers. Example 4.1. Suppose we have a beam balance and a set of seven stan- dard weights 1, 2, 4, 8, 16, 32, 64 units. It is possible to weigh every integer units from 1 to 127 with these seven standard weights. For ex- ample, since 1002 = 1100100, balance is achieved by putting a weight of 100 units on one pan, and standard weights of 4, 32 and 64 units on the other. However, with a set of five standard weights 1, 3, 9, 27, 81,itis possible to weigh every integer units from 1 to 121. For example, since 100 3 =11101, a weight of 100 units can be balanced by putting it with a standard weight 9 units on one pan and the standard weights 1, 27, 81 on the other pan. 4.3 Arithmetic in balanced base 3 representations 123 4.3 Arithmetic in balanced base 3 representations + 1 01 × 1 01 1 11 1 0 1 101 0 1 01 0 000 1 0111 1 1 01 Example 4.2. 11111 3 × 1111 3 = 11000011 3. 1 1111 × 111 1 1 1111 1 1111 1 1111 1 1111 1 1 000011 124 Representation of a number in different bases 4.3.1 A matrix card trick Let p and q be given odd numbers, say p =2h +1and q =2k +1. Arrange pq cards in the form of a p × q matrix. Ask a spectator to select one secret card and name the column containing the secret card. Then the cards are (i) picked up along columns in any order, except that the named one is the middle one, being preceded by k arbitrary columns and followed by the remaining k columns arbitrarily, (ii) rearranged into the p × q matrix along rows. Repeat a number of times, each time asking for the column which contains the secret card. The secret card will eventually appear exactly in the middle row of the matrix. If p ≤ q, you can tell what the secret card is after the first step. It is in the middle row. We shall henceforth assume p>qso that there are more rows than columns. Example 4.3. In the arrangement below, the spectator chooses ♦2 and tells you that it is in the second column. ♣5 ♠6 ♦8 ♣J ♠Q ♠K ♥9 ♠A ♦6 ♦9 ♣6 ♥10 ♠10 ♦2 ♣9 Then you pick up, in order, the first, the second, and then the third columns, and deal the cards in rows: ♣5 ♣J ♥9 ♦9 ♠10 ♠6 ♠Q ♠A ♥6 ♦2 ♦8 ♠K ♦6 ♥10 ♠9 Now ask the spectator which column contains the secret card. She will answer the first column. Then you pick up, in order, the third, the first, and the second column, and deal the cards in rows: 4.3 Arithmetic in balanced base 3 representations 125 ♥9 ♠6 ♥6 ♠K ♠9 ♣5 ♦9 ♠Q ♦2 ♦6 ♣J ♠10 ♠A ♦8 ♥10 Now, the spectator will tell you that the secret card is in the third column. You immediately know that the card is ♦2. How many times do you need to rearrange the cards before you can tell what the secret card is? 1 Label the rows −h, −(h − 1),...,0,...,h − 1, h so that the middle rowisrow0. An application of (i) and (ii) will bring the i-th card in the column containing the secret card into row g(i), where g(i) is the quotient in the balanced division of i by q. Equivalently, g(i)=b if i = bq + r for − k ≤ i ≤ k. It is easy to see that g is an odd function: under the same condition, −i = −bq − r, with −k ≤−r ≤ k, so that g(−i)=−b.Now,g(i) is decreasing for positive i, and increasing for i<0. Furthermore, if g(i)=0, then all subsequent iterates by g are stationary at 0. Therefore, if we write p =2h +1, then the number of times to guarantee the secret card in the middle row is min{ : g (h)=0}. The function g on positive integers can be easily described in terms of the base q representations of numbers. Lemma 4.1. If n = amam−1 ...a1a0 q in balanced base q representa- tion, then g(n)= amam−1 ···a1 q. Proposition 4.2. The number of times for the secret card to move to the middle row is not more than the length of the balanced base q- p−1 representation of the integer 2 . Examples (1) 51 cards in 3 columns: p =17, q =3. Since 8= 101 3, three operations suffice. 1G. R. Sanchis, A card trick and the mathematics behind it, College Math. Journal, 37 (2006) 103Ð109. Here, we make use of balanced base q representation of numbers. 126 Representation of a number in different bases (2) 35 cards in 5 columns: p =7, q =5. Since 3= 12 5,two operations suffice. Exercise Find the number of operations required to move the secret card to the middle row for 1. 45 cards in 5 columns; 2. 39 cards in three columns. Chapter 5 Cheney’s card trick You are the magician’s assistant. What he will do is to ask a spectator to give you any 5 cards from a deck of 52. You show him 4 of the cards, and in no time, he will tell everybody what the 5th card is. This of course depends on you, and you have to do things properly by making use of the following three basic principles. 5.1 Three basic principles 5.1.1 The pigeonhole principle Among 5 cards at least 2 must be of the same suit. So you and the magician agree that the secret card has the same suit as the first card. 5.1.2 Arithmetic modulo 13 The distance of two points on a 13-hour clock is no more than 6. We decide which of the two cards to be shown as the first, and which to be kept secret. For calculations, we treat A, J, Q, and K are respec- tively 1, 11, 12, and 13 respectively. Now you can determine the distance between these two cards. From one of these, going clockwise, you get to the other by travelling this distance on the 13-hour clock. Keep the latter as the secret card. 128 Cheney’s card trick hours distance clockwise 2 and 7 5 2 to 7 3 and 10 6 10 to 3 2 and J 4 J to 2 A and 8 6 8 to A The following diagram shows that the distance between ♣3 and ♥10 is 6, not 7. ♣Q ♠K ♦A ♥J 6 ♣2 ♥10 ♣3 ♦9 ♦4 ♣8 ♥5 ♦7 ♣6 5.1.3 Permutations of three objects There are 6 arrangements of three objects The remaining three cards can be ordered as small, medium, and large. 1 Now rearrange them properly to tell the magician what number he should add (clockwise) to the first card to get the number on the secret card. Let’s agree on this: arrangement distance sml 1 slm 2 msl 3 mls 4 lsm 5 lms 6 If you, the assistant, want to tell the magician that he should add 4 to the number (clockwise) on the first card, deal the medium as the second card, the large as the third, and the small as the fourth card. 1First by numerical order; for cards with the same number, order by suits: ♣ < ♦ < ♥ < ♠. 5.2 Examples 129 5.2 Examples Example 5.1. Suppose you have ♠5, ♣7, ♦J, ♣4, and ♠Q, and you decide to use the ♣ cards for the first and the secret ones. The distance between ♣7 and ♣4 is of course 3, clockwise from ♣4 to ♣7.You therefore show ♣4 as the first card, and arrange the other three cards, ♠5, ♦J, and ♠Q, in the order medium, small, large. The second card is ♦J, the third ♠5, and the fourth ♠Q. The secret card is ♣7. 4 ♣ J ♦ 5 ♠ Q ♠ ? ? Example 5.2. Now to the magician. Suppose your assistant show you these four cards in order: Q ♠ J ♦ 7 ♣ 4 ♣ ? ? Then you know that the secret card is a ♠, and you get the number by adding to Q the number determined by the order large, medium, small, which is 6. Going clockwise, this is 5. The secret card is ♠5. Exercise 1. For the assistant: (a) ♠5, ♠7, ♦6, ♣5, ♣Q. (b) ♥2, ♠J, ♥K, ♣2, ♠8. 130 Cheney’s card trick 2. For the magician: what is the secret card? 5 2 ♠ 7 ♥ J ♠ 6 ♠ 2 ♦ 5 ♣ 8 ♣ ? ♠ ? ? ? 5.3 A variation: Cheney card trick with spectator choosing secret card 131 5.3 A variation: Cheney card trick with spectator choos- ing secret card Now the spectators say they would choose the secret card. What should you, the assistant, do? 1. Arrange the four open cards in ascending order, and put the n-th card in the first position, with n =1, 2, 3, 4, according as the secret card is for ♣, ♦, ♥,or♠. For example, if you are given ♠2, ♥6, ♦K, ♠10, and ♣4 as secret card, then since ♠2 < ♥6 < ♠10 < ♦K, you put ♠2 in the first position. 2. Note the rank of the secret card. If it is the same as the first card, put the secret card in the third position, and arrange the remaining three in any order. 3. If the ranks of secret card and the first card are different, deter- mine the 13−point clock difference, and arrange the remaining three open cards to indicate this difference. (a) If the rank of the secret card is higher than that of the first card, put the secret card in the second position, followed by the remaining three open cards in the positions indicating the difference. (b) If the rank of the secret card is lower than that of the first card, put the three open cards in the positions indicating the differ- ence, followed by the secret card. 2 ♠ ? ? 6 ♥ K ♦ 10 ♠ Now, for the magician, 132 Cheney’s card trick 1. Determine the order of the first card among the four open cards. The secret card is ♣, ♦, ♥, ♠ according as this is the least, second, third, or largest. 2. If the secret card appears in the third position, its rank is the same as the rank of the first card. 3. If the secret card separates the first card from the remaining three, add the number determined by the remaining three cards to the first card to get the rank of the secret card. 4. If the secret card appears at the end, subtract the number deter- mined by the remaining three cards from the first card to get the rank of the secret card. Exercise 1. For the assistant: (a) ♠5, ♠7, ♦6 (secret card), ♣5, ♣Q. (b) ♥2, ♠J, ♥K, ♣2, ♠8 (secret card). 2. For the magician: what is the secret card? 5 2 ♠ ? ♥ J ? 6 ♠ 2 ♦ 5 ♣ 8 ♣ 7 ♠ ? ♠ ? Chapter 6 The nim game 6.1 The nim sum The nim sum of two nonnegative integers is the addition in their base 2 notations without carries. If we write 0 0=0, 0 1=1 0=1, 1 1=0, then in terms of the base 2 expansions of a and b, a b =(a1a2 ···an) (b1b2 ···bn)=(a1 b1)(a2 b2) ···(an bn). The nim sum is associative, commutative, and has 0 as identity ele- ment. In particular, a a =0for every natural number a. Example 6.1. (a) 6 5 = [110]2 [101]2 = [011]2 =3. (b) 34 57 = [100010]2 [111001]2 = [011011]2 =27. Here are the nim sums of numbers ≤ 15: 134 The nim game