## The Memory Game - CiteSeerX

22.11.1992 - end the game) and the winner is the player possessing the largest number of pairs. The gain (or loss, if negative) of a player at any stage is de ...
The Memory Game  Uri Zwick

y

Michael S. Paterson

z

Department of Computer Science University of Warwick [email protected]

Mathematics Institute University of Warwick and Computer Science Department Tel Aviv University [email protected]

November 22, 1992 Abstract The memory game , or concentration , as it is sometimes called, is a popular card game played by children and adults around the world. Good memory is one of the qualities required in order to succeed in it. This however is not enough. When it is assumed that the players have perfect memory, the memory game can be seen as a game of strategy. The game is analysed under this assumption and the optimal strategy is found. It is simple and perhaps unexpected. In contrast to the simplicity of the optimal strategy, the analysis leading to its optimality proof is rather involved. It supplies an interesting example of concrete mathematics of the sort used in the analysis of algorithms. It is doubtful whether this analysis could have been carried out without resort to experimentation and a substantial use of automated symbolic computations.

This work was partially supported by the ESPRIT II BRA Programme of the EC under contract # 3075 (ALCOM). y Most of this work has been carried out while this author was visiting the University of Warwick. Current mailing address : Computer Science Department, Tel Aviv University, Tel Aviv 69978, Israel. z Mailing address: Computer Science Department, University of Warwick, Coventry CV4 7AL, England. 

1

1 The game A pack containing n pairs of identical cards is shued and the cards are spread face down on a table. Each player in turn ips two cards, one after the other. If the two cards ipped are identical (i.e., they form a pair), they are removed from the table into the possession of the player who ipped them and he/she gets another turn. If the two cards are not identical then they are ipped back and the turn passes to the next player. The game continues until all the cards are removed from the table (or until all the players agree to end the game) and the winner is the player possessing the largest number of pairs. The gain (or loss, if negative) of a player at any stage is de ned to be the number of pairs he/she holds minus the average number of pairs held by the opponents. Any number of players can play the game but the most interesting situation occurs when there are only two of them. We will therefore consider this case here. The invention of the memory game is sometimes attributed to Christopher Louis Pelman and the game is often called Pelmanism (consult this entry in ). A light-hearted report on some of the results obtained in this paper has recently appeared in .

2 Moves, positions and strategies Each player tries to remember the position and the identity of all the cards already inspected. To focus our attention on the strategic questions involved we will assume that the players have already reached a high level of pro ciency and are able to absorb all this information (in other words, they have perfect memories). A turn in the game is composed of two plies. The observation that triggered this work is that at each ply the player can either inspect a new card (in which case we assume that the outcome is uniformly distributed over all the as-yet-un ipped cards), or an old card whose identity is already known to both players. Inspecting an old card in the rst ply, or a non-matching old card in the second ply, are in a sense idle plies. Idle plies are not always possible. In the beginning of the game, for example, the rst player has to ip two new cards. There are at most three reasonable moves from each position . The rst is to pick no new cards at all. Such a move will be called a 0-move and it is possible only if there are at least two inspected cards on the table. The two other moves, termed 1-move and 2-move , both begin by ipping a new card. If the new card matches a previously inspected card then in both cases the matching card is ipped, a pair is formed and the player gets another turn. If however the rst card ipped does not match a previously inspected card then an idle ply is used in a 1-move while a new card is inspected in a 2-move. It can be easily seen that making an idle ply rst and then ipping a new card is always inferior to the 1

1

See however the note at the end of the paper.

2

other moves. While playing the game the players can have two di erent objectives. They could try to maximise the probability of winning the game or, alternatively, they could try to maximise their expected gain. The two objectives lead to somewhat di erent optimal strategies. We will investigate here the strategy that maximises the expected gain. The optimal strategy for the other case could presumably be obtained using similar methods and a more involved analysis. If a 0-move maximises the expected gain for the next player then, after this 0-move is played, the situation remains exactly the same and the second player would also like to play a 0-move. Since this can go on forever we stop the game in such a case. A position in the game is characterised by the number n of pairs still on the table and the number k of cards on the table which have already been inspected. We can assume that all the inspected cards are di erent. In the case where the last player played a 2-move and the second card ipped matches not the rst card ipped but one of the previously inspected cards, the resulting pair would be immediately removed by the other player, and we may account for this as part of the present turn. A strategy is a rule which determines which one of the three plausible moves should be used in each position (n; k) where 0  k  n are integers. An optimal strategy is a strategy which maximises the expected gain assuming that both players play optimally. The value of a position is the expected future gain of the player who is rst to play from that position assuming that both players use an optimal strategy. We shall see in the next section that the position values and an optimal strategy can be de ned mutually recursively. It is easy to see that if a player is playing according to an optimal strategy then the expected gain from some position is at least the value of that position, no matter what strategy the opponent may choose.

3 The optimal strategy We recursively de ne the values en;k of the di erent positions. The only initial condition that we need is that e ; = 0, that is, that no one gains from a null game. Assume that we have already de ned en0;k0 for n0 < n and en;k0 for k0 > k. We will rst de ne en;k and en;k which will be the expected gain from position (n; k) when beginning with a 1- or a 2-move respectively, and subsequently playing using an optimal strategy. Referring to Figure 1, it is relatively easy to verify that 0 0

1

2

en;k = en;k = 1

2

k n?k (1 + en? ;k? k n?k (1 + en? ;k?

2

2

1

1

1

1

)? )?

n?k e n?k n;k n?k k? n?k n?k?

2(

)

+1

2 2(

2

)

1

2

1

;

(1 + en? ;k ) + 1

n?k? n?k?

2( 2

1)

1

en;k

 +2

:

We explain the rst relation as an example. When ipping the rst card, there are k inspected cards on the table, all of them di erent, and 2n ? k uninspected cards. In a 1-move an uninspected card is ipped. With probability nk?k it will be a card which matches one of the previously inspected cards, in which case the player will gain a pair 2

3

1 ::: k

|

{z

}

n

2

k n?k

n?k n?k

2(

2

 ik

1 ::: k i

|

j

k?

{z

n?

2

2

n?k?

2

}

n?k? n?k?

k n?k?

1

1

i>k

1 ::: k i

6 ?

1 + 1 :::

)

2

1

2

2(

1

? j k

=

1 ::: k i i

1 ::: k i j

1 + 1 ::: k

?1 ? 1 : : : k

6 ?

|

{z

n?

2

2

6 ?

}

|

1)

2

{z

n?

2

2

1

j>k ~ j 6= i 1 ::: k i j

}

Figure 1: Possible outcomes of moves from position (n; k). and will be entitled to play again from position (n ? 1; k ? 1). With the complementary probability nn??kk the rst card ipped will not match any previously inspected card, an idle ply will follow and the opponent will play from position (n; k + 1). Since the gain of one player is the other's loss, the expected gain of a player from a position (n; k + 1) when the opponent is about to play is ?en;k . This accounts for the two terms appearing in the rst relation. The second relation is obtained in a similar way. (A reference to Figure 1 may again be useful). The value en;k of the position (n; k) with n > 0 is now de ned as en; = en; en; = maxfen; ; en; g en;k = maxf0; en;k ; en;k g for 2  k  n : These de nitions are explained by the following observations. A 2-move is the only legal move from position (n; 0). A 1-move and a 2-move are the only two moves allowed from position (n; 1). In positions of the form (n; k) where k  2 a 0-move could be used. If en;k ; en;k < 0 then it is advantageous to use a 0-move and the game will stop with value 0. We say that an i-move is optimal from position (n; k) if en;k = ein;k (where en;k = 0). It is possible that more than one move will be optimal from a certain position. Using these recursive de nitions we can compute the values and nd the optimal moves. Table 1 gives the values of positions with n  7; while Table 2 gives the optimal moves for n  15. For (n; k) = (4; 3) it turns out that both the 0-move and the 2-move are optimal but only the 2-move is listed in the table. Similarly, for any n, en;n = en;n = n, 2(

)

2

+1

2

0

0

1

1

2

1

1

1

1

2

2

0

1

4

2

k=0 k=1 k=2 k=3 k=4 k=5 k=6 k=7

n=0 n=1 n=2 n=3 n=4 n=5 n=6 n=7

? ? ? ?

0 1

1

2

2

3

3

2

1

1

5

3

?

4

4

4

35

35

15

3 0

1

1

19

35

7

35

4 0

1 5

?

2

2

2

13

27

1155

1155

21

105

35

5 0

1

35

61

61

13

53

2

62

1155

1155

495

231

21

63

6 0

7

Table 1: The expected values of the simplest positions so both the 1-move and the 2-move are optimal in this case. In fact, they are identical in this case since the rst card ipped will always match a previously inspected card. The pattern emerging from Table 2 is clear. A 2-move should be used when k = 0, since this is the only allowed move. A 1-move should be used whenever k > 0 and n + k is even. Either a 2-move or a 0-move should be used when n + k is odd ((n; k) = (6; 1) being the only exception). Inspecting a few more rows in the table immediately suggests that a 0-move should be used when, in addition to the requirement that n + k is odd, we also have k  2(n + 1)=3. We thus claim :

Theorem 3.1

8 > < 0 if [k  n and n + k odd ] en;k = > en;k if [k  1 and n + k even ] or [(n; k) = (6; 1)] : e otherwise. 2(

+1)

3

1

2

n;k

Another interesting issue is the behaviour of the values en;k themselves. The following approximation gives their asymptotical behaviour.

Theorem 3.2

8 > > < en;k = > > :

k ? n?k + O(n ) n? k n?k + O(n? n?k 3 1

2(

)+1

(2

3 )(2

16(

0

)

)

2

if n + k even ) if n + k odd and k  if n + k odd and k 

n

2

+1

3

n

2(

+1)

3

.

If we let  = k=n then we see that for  < 1, en;k = en;k  ? if n + k is even, and en;k = en;k  ? ??  n if n + k is odd and k  n . Similarly, we can get that 1

2(1

2

(2

3

16(1

)(2

3

)

2

1

+1

3

)

5

)

n=1 n=2 n=3 n=4 n=5 n=6 n=7 n=8 n=9 n = 10 n = 11 n = 12 n = 13 n = 14 n = 15

21 221 2121 22121 212101 2112101 21212101 221212101 2121212101 22121212101 212121210101 2212121210101 21212121210101 221212121210101 2121212121210101

Table 2: The optimal moves for n  15.

en;k  ? k n . 2

 ?

2(1

2

+1

)



?  2 2 ?

4

12

(2

+7 )

if n + k is even and that en;k = ? 1

?  32  ? n

4

8

+5

16(1

1

)

if n + k is odd and

3

A graph of en;k = en;k and en;k for even values of n + k is given in Figure 2. It can be seen that, unless  is very small, en;k is both positive and markedly superior to en;k . Similarly, a graph contrasting en;k = en;k with en;k for odd values of n + k is presented in Figure 3. Again there is a sharp di erence between these two options. We need better approximations, however, to show that en;k = en;k when n + k is even and k = o(n), and that en;k = en;k when n + k is odd and k = n ? o(n). These are obtained in the next section. Another interesting question is the sign of the values of the di erent positions. By de nition en;k  0 whenever k  2, but what happens when k = 1 or k = 0? In particular, when is it advantageous to take the rst turn? It turns out that en; > 0 for n  6, that en; > 0 when n  7 and n is odd, and that en; < 0 when n  8 and n is even. Thus it is advantageous to take the rst move in the game if and only if n is either 1; 6 or an odd number greater or equal to 7. Finally, what is the expected gain or loss from a game played with n pairs of cards? It turns out that, for large n, the gain or loss is roughly 1=4n. More precisely 1

2

1

2

2

1

1

2

2

3

1

0

Theorem 3.3

0

8 < en; = : ? 0

1 +2

1

n?

4

+ O( n ) if n odd + O( n ) if n even. 1

n

4

2

3

1

3

The proofs of the theorems stated in this section are given in the next section. 6

1

en;k = 1



en;k 1

2(1 ? )

en;k = ? 2(1 ? )  4 ? 12 + 7 (2 ? )

0.8

2

2

2

0.6

en;k 2

0.4

0.2

0.1

0.2

0.3

0.4

0.5

0.6

Figure 2: The behaviour of en;k = en;k and en;k for n + k even. 1

2

en;k 2

0.25

0.1

0.2

0.3

0.4

0.5

0.6

-0.25 -0.5

en;k 1

-0.75

en;k = (2 ? 3)(2 ? )  n1 16(1 ? ) en;k = ? 4 ? 8 + 5  n1 16(1 ? ) 2

-1

3

2

-1.25

1

3

-1.5

Figure 3: The behaviour of en;k = en;k and en;k for n + k odd. 2

7

1

4 Analysis Our strategy for proving the results claimed in the previous section is the following. We rst investigate the expected gains from each position when the two players play according to the alleged optimal strategy. Once we have tight estimations of these values it will be easy to prove by induction that these values do in fact correspond to the optimal strategy.

4.1 Preliminary manipulations Let en;k be the expected values of the di erent positions when both players play according to the conjectured optimal strategy. As a `warm-up' we prove the following lemma

Lemma 4.1 (i ) en; = en; for odd n  1; (ii ) en; = ?en; for even n 6= 6: 0

1

0

1

Proof : For odd n, we have en; = en; and en; = en; . Consulting the de nitions of en;k 2

0

2

1

1

and en;k from Section 3, we see that both en; and en; expand to the same expression 0

1

1

2

1

1

0

en; = en; =

(1 + en? ; ) ?

n? n?

en; : This proves the rst part of the lemma. For even n 6= 6, we have en; = en; and en; = en; 1

2

1

0

1

2(

1 0

1)

2

2

1

h

en; + en; = 1

n? (1 + en? ; ) ? n? (1 + en? ; ) ? 1

2

=

1

2

2

n? n? n? n?

2(

1 0

1 0

1

2

1)

2

1

1

2

1

2(

i h en; + n? (1 + en? ; ) ? en; ? nn?? en; :

1)

2

2(

2

2

1 0

1

2

en; + en; = 1

=

n?

2

1

2

n?

2

1

2

(1 + en? ; ) ? nn?? [en? ; ? en? ; ] = 0 1 0

1 0

1)

2

1



1

n? n?

en;

n? n?

en;

2(

2)

2

2

i

2

1

3

1

2(

2

n? n?

2(

2

1

0

2)

For even n  2, we have en; = en; and thus 0

2

0

and therefore 0

1

n?

2

2

1) 1

h

2

n?

2

2

(1 + en? ; ) ? 1 1

n? n?

2(

2

2) 2

i en; ? 3

2(

2

2) 1

3

1 1

where the last equality follows from the rst part of the Lemma. As an easy corollary we get

2

Lemma 4.2 en; = en; for even n 6= 6. 1

2

0

0

Proof : By the de nition we have en; = en; and en; = ?en; and thus the result follows 2

0

1

1

from the second part of the previous lemma. 2 Note that 1-moves are currently not allowed from positions of the form (n; 0). The previous lemma says however that it would not matter if we were to allow them from these positions with even n 6= 6. Furthermore, the 1-moves would be co-optimal in these positions and 0

8

0

we could therefore use the relation en; = en; as the de ning relation for even n 6= 6. This removes the anomaly of the column k = 0 seen in Table 1. The two remaining exceptions are e ; = e ; and e ; = e ; . Since the parity of n + k plays a major role in the following analysis, it will be convenient to denote en;k by an;k when n + k is even, and by bn;k when n + k is odd. It is also convenient to write the recurrence relations de ning an;k and bn;k with the help of an auxiliary sequence cn;k as follows an;k = pn;k (1 + an? ;k? ) ? qn;k bn;k bn;k = [pn;k (1 + bn? ;k? ) ? qn;k cn;k ]  In;k cn;k = p0n;k (1 + an? ;k? ) + qn;k bn;k where pn;k = nk?k ; p0n;k = kn??k ; qn;k = nn??kk and  n In;k = 1 if k  : 0 otherwise These relations hold for any (n; k) with the exception of (6; 0) and (6; 1). The only initial condition required is that a ; = 0. Note that cn;k corresponds to the expected loss from position (n; k) if one new card had already been ipped and did not match any of the previously inspected cards. 1

0

6 0

2

6 1

6 0

0

1

6 1

1

1

1

+1

1

1

+1

1

+1

2(

2

2

2

)

2

2

+1

3

0 0

+1

4.2 Operator notation The following analysis is facilitated by introducing operator notation. De ne an operator  by 0 1 0 01 a0n;k = pn;k an? ;k? ? qn;k bn;k aC Ba C B 0  @ b A = @ b A where b0n;k = pn;k bn? ;k? ? qn;k cn;k c c0 c0n;k = p0n;k an? ;k? + qn;k bn;k and an operator Z by 1

1

+1

1

1

+1

1

1

+1

0 1 0 1 aC B a C  n B 0 0 Z @ b A = @ b A where bn;k = bn;k if k  0 otherwise c c 2

+1

3

:

We again assume that  has the anomalous behaviour a0 ; = b0 ; = (1 + b ; ) ? a ; : If we let e = (a; b; c)T and h = (p; p; p0 )T then it is easy to see that e satis es the following equation 10

1

6 0

6 1

e

5 0

11

11

= ( + ) : Z

e

Our task is to solve this operator equation. 9

h

6 2

(1)

4.3 Bootstrapping We start by trying to solve the equation obtained by ignoring the presence of the operator Z in equation (1) e

= + e

:

h

(2)

The solution of this equation will not only give us some useful information about the solution of equation (1), it also has some interest in its own right. It corresponds to the analysis of the variant of the game in which 1-moves and 2-moves are the only moves allowed. Solving equation (2) amounts to inverting the operator (I ? ), which does not seem to be an easy task. We approach this by approximating  by an operator b for which b is much easier. Using a method that bears some resemblance to the inverting (I ? ) `bootstrapping' method described in , we de ne a sequence of re ning terms E ; E ; : : : whose sum E + E + : : : converges, we hope, to the required solution. This sequence is obtained in the following way 0

0

1

1

E h

c ?1 = ( ? ) +1 = ( ? c )

i

I

i

h

i

E

i

;

i

;

i

0 0

where h = h. Let e = e, and ei = ei? ? E i? for i  1 be the error of the i'th approximation. It is easy to verify that 0

0

1

e

i

= + e

i

h

i

1

;

i

0

:

We de ne b as follows

0 1 0 01 a0n;k = pn;k an;k ? qn;k bn;k aC Ba C B 0 b @ b A = @ b A where b0n;k = pn;k bn;k ? qn;k cn;k c0n;k = pn;k an;k + qn;k bn;k c0 c

or equivalently Thus

1 0 p ? q 0 b = B @ 0 p ?q CA : p q 0

1 0 1?p q 0 b = [email protected] 0 1 ? p q CA (I ? ) ?p ?q 1

1 0 1 + q ? 1 q b ? = 1 [email protected] ?p (I ? ) 1 ?q C A 2q p q?p q

;

1

2

10

and

0 1 0 01 0 = pn;k (an? ;k? ? an;k ) ? qn;k (bn;k ? bn;k ) a a a n;k b [email protected] b C : ( ? ) A=B @ b0 C A where b0n;k = pn;k (bn? ;k? ? bn;k ) ? qn;k (cn;k ? cn;k ) 0 0 0 cn;k = (pn;k an? ;k? ? pn;k an;k ) + qn;k (bn;k ? bn;k ) c c 1

1

1

1

1

1

+1

+1

+1

The terms E i obtained in this way become horrendously complicated even for very small values of i and it seems almost impossible to handle them manually. We used Mathematica to do these computations. We now note that for k < n, for some  < 1 we have h = O(1) and thus it can easily be seen that E = O(1). The operator  ? b has the characteristics of a discrete di erence operator. Since each component of E = (A ; B ; C )T is a rational function in n and k and thus continuous, in the sense that An? ;k? ? An;k = O(n? ) and so on, it is easy to see that h = O(n? ). By induction, we can prove in this way that as long as  = k=n is bounded away from 1, we have E i = O(n?i ). Therefore each additional term E i that we compute allows us to obtain an additional term in the asymptotic expansions of a,b and c. These computations can again be done using Mathematica and the expansions obtained are 0

0

0

0

0

0

0

0

1

1

an;k = bn;k =

1

1

1

? 3 ? 2 ? ? 3  n + ? 5 ?  ?  + 3? 2 ?  n2 ? 3 n ? 5  ?

2(1

(2

)

3

+

2 +4

16(1

)(2

16(1

)

1

4

1

2

4

)

+5

16(1

4

)

14

+11

16(1

)

2

)

4 ?  3

13

1

2

+

1

2

n +

62

2 ?  ? 7 ?  n3

+112

64(1

4? 3 ? 2 ? 7

9

12

60

64(1

+80

)

64

+8

)

1

24

 n + ::: 1

3

+ :::

The expansion of cn;k is easily obtained from these two. We claim that by truncating these expansions after the O(n?i ) terms we get an approximation to the solution e = (a; b; c)T of (2) with errors of O(n? i ). In particular, if we let An;k = ? +  ??  n +  ? ? ?  n (3) Bn;k = ? ??  n +  ? ? ?  n Cn;k = ? ?  ? ?  n + ?  ? ?   n where as usual  = k=n, we claim that for any  < c < 1, where c is constant, we have an;k = An;k + O(n? ), bn;k = Bn;k + O(n? ) and cn;k = Cn;k + O(n? ). Furthermore, we prove in this section that these expansions are also valid for the solution e = (a; b; c)T of (1), corresponding to the full version of the game, provided that  is less than and bounded away from 2/3. We thus see that in this region there is hardly any di erence between the two variants of the game. ( +1)

2 +4

2(1

(2

)

3

)(2

16(1

3

)

3

1

4

1

)

2

16

16(1

2

3

2 +5

4

5

16(1

3

)

3

2(1

4

)3

16(1

+12 )3

3

14

2 +11 5

16(1

)

1

14

2

1

2

)

2

41

1

2

+36

16(1

2

5

8

3

1

2

)

3

4.4 Boundary layer in uence In this subsection we return to the study of equation (1) that corresponds to the full version of the game. 11

Let  be the operator de ned as follows

0 1 0 01 aC Ba C B   @ b A = @ b0 A where c c0

a0n;k

(

= ppn;k aan? ;k? ? qn;k bn;k n;k n? ;k?

(

1

1

1

1

b0n;k = p0n;k bn? ;k? ? qn;k cn;k ( 0 0 cn;k = pp0n;k aann?? ;k;k?? + qn;k bn;k n;k 1

1

1

1

1

1

k k k k k k

if if if if if if

+1

+1

+1

n? n?

2

2

2

3

1

3

n n

2

+1

2

3 +2

:

3

n? n?

2 2

2

3

1

3

It is easy to verify that Z  =  and that if e = Ze then e = e. If we let h0 = Zh we get that equation (1) is equivalent to e

=  + e

h

0

:

(4)

Examining this equation, we see that the values of an;k for k  n , the values of bn;k for k  n , and the values of cn;k for k  n do not depend on values outside these regions. We denote this `closed' region by and consider the behaviour of e on it rst. The values of an;k for n?  k  n , of bn;k for n?  k  n and of cn;k for n?  k  n are the values in a ected most directly by the vanishing of the b n;k terms for k  n . We call the narrow region of containing these values the boundary layer of and denote it by @ . It is convenient to think of the di erences between the actual values an;k , bn;k and cn;k in and those predicted by the asymptotic expansion of the previous subsection as being caused by this boundary layer. The shapes of the region

and the boundary layer @ are depicted in Figure 4. Note that on ? @ the operators  and  agree, while on @ the operator  has missing qn;k bn;k terms. Since in the boundary layer bn;k = O(n? ) (or more precisely Bn;k = O(n? )), we expect the boundary layer to have only an O(n? ) in uence on values close to the boundary layer. We shall further see that this in uence fades very quickly as we move away from the boundary area. We will now try to nd an approximation E with O(n? ) error for the solution of (4), valid for the whole of . This approximation will enable us to establish in Subsection 4.7 the validity of the alleged optimal strategy. As implied by the previous paragraph, this approximation must include not only the rst terms obtained by the bootstrapping process but also terms corresponding to the boundary layer in uence. If e = e + h0 and " = e ?E = O(n? ) in , then we must also have H = (I ? )(e ?E ) = h0 ? (I ? )E = O(n? ) in . Note that " satis es the equation " = " + H. In the next subsection we will see that under certain conditions, the last implication can be reversed. More precisely, if H = O(n? ) and if it satis es a certain additional condition then " = e ? E = O(n? ). Let us rst look at H = (R; S; T )T = h0 ? (I ? )E where E = (A; B; C )T with A; B; C de ned in (3). Easy manipulations show that Rn;k ; Sn;k ; Tn;k = O(n? ) in ? @ (this 2

2

2

+1

3

3

2

2

1

3

+3

3

+4

2

+4

3 2

2

1

3

+3

2

3

4

2

3

+1

3

+2

3

+1

+1

+1

2

2

2

3

3

3

3

3

3

12

m?

4

m?

6

m?

6

m?

6

m?

6

4

1

3

+1

m

+2

m

+3

m

+4

m

+5

6

6

6

6

m?

4

m

1

4

0

?

0

?

?

0

2

3

3

0

2

4

9

4

1

7

m

2

?

5

1

m

m?

4

2

6

6

3

1

6

3

8

0

5

2

7

4

6

m

4

+1

m

4

+2

m

4

+3

m

4

m

+4

4

m

+5

4

+6

0 0 0

0

?

0

?

0

?

0

?

?

0

1

2

1

0

3

3

0

5

0

2

1

4

1

0 0

4

0

Figure 4: The region and the boundary layer @ . is ensured by the bootstrapping process) but that Rn;k = n? k?  n + O(n? ) and Tn;k = ? n? k?  n + O(n? ) in @ . The quantity 2n?3k measures the horizontal distance of position (n; k) from the boundary layer @ . This suggests trying to work with an approximation E = (A; B; C )T of the form 9(2

3

8

9(2

3

8

1)

1

1)

1

3

2

3

2

An;k = An;k + nn? k ; Bn;k = Bn;k + nn? k ; Cn;k = Cn;k + nn? k 2

3

2

2

3

2

2

3

2

(5)

where the An;k ; Bn;k ; Cn;k are again those of (3), and thus represent the global behaviour in , while the sequences f `g,f `g and f `g represent the e ect of the boundary layer @ . We expect the sequences f `g,f `g and f ` g to be quickly, in fact exponentially, diminishing so that their contribution far from the boundary layer will indeed be negligible. The sequences f ` g,f `g and f `g should be chosen in a way that ensures that H = O(n? ) 3

13

; ; ;  

1 2 3 4 5 6 7 8

' ?1:108812  0:625391i ' 1:121061  0:562315i ' ?0:018515  1:239618i ' 0:539036 ' 0:473498

' 0:021830  0:048470i v ; ' 0:060084  0:035674i ' ?1:027472  0:663188i v ; ' ?0:227399  1:791415i ' ?0:122426  0:028318i v ; ' ?0:015567  0:142098i

u; u; u; u u

1 2

1 2

3 4

3 4

5 6

5 6

= 0:000000 = 0:000000

v = 0:000000 v = 0:000000 Table 3: The values of the roots i and the coecients ui and vi. 7 8

7 8

in the whole of . To that end, as we shall see shortly in the proof of Theorem 4.3, the sequences f ` g,f `g and f ` g should satisfy the following linear recurrence relations ` ? ` ? `? = 0 ; ?3  `  1 ` ? ` + `? = 0 ; 1 < ` 9(

1

+1

2

1

1

+1

2

1)

8

3

2

` ? ` + `? = 0 ; ?1  `

` ? ` ? `? = 0 ; ?4  `  1

` ? ` ? `? = 0 ; 1 < `

(6)

1

1

+1

2

3

2

9(

1

+1

2

1)

8

1

1

+1

2

3

2

together with the additional requirement that ` ; `; ` ! 0 as ` ! 1. The values of ` and ` are easily computed using generating function techniques. The rst values are ? ' ?6:83199877, ? ' ?4:66399755, ? ' ?2:57799510 and ? ' P ?2:08745613, ' ?1P:96591166, = ?1:76382209. In general ` = i uii?` , ` = P ?` ?` i vi i and ` = i wi i where ui ; vi ; wi are some xed complex numbers and  ; : : : ;  are the six complex roots of the equation x ? x + 4x ? 4x + 1 = 0 with modulus greater than 1. The values of the roots i and of the coecients ui and vi are given in Table 3. Assuming that E does indeed approximate e to within an O(n? ) error we get (for xed values of `) the following behaviour of an;k and bn;k near the boundary layer   an; n?` = 1 ? `  n + ` ` + `  n + O( n ) ;   bn; n?` = ` + `  n + O( n ) : In particular 3

2

1

1

6

0

1

6

=1

6

=1

=1

1

8

6

7

2

3

2

2

3( +1)

3

2 +1 3

2

1

:

n2

1

; bn; n ' 2 3

1

2

3

1

2

4

0 162544

+2 +3) 4

9( +1)

3

bn; n '

3(2

1

2

3

:

2 534088

n2

; bn; n? ' 2

3

1

:

4 986178

n2

:

Having chosen the sequences ` ; ` and ` in this way, we can indeed prove that H = O(n? ) in the whole of . Furthermore, we show that H satis es an additional `continuity' condition that together with the condition H = O(n? ) will allow us to infer in the next subsection that " = O(n? ). 3

3

3

Theorem 4.3

100 ; jH jHn;k j  100 n;k ? qn;k Hn;k j  (1 ? qn;k )  n n (2)

(2)

+2

3

14

3

where qn;k = qn;k qn;k , for all positions in with n  1000. (2)

+1

Proof : We rst clarify the statement of the theorem. If H = (R; S ; T )T then we claim that jRn;k j; jSn;k j; jTn;k j  n for n  1000 and k  n ; k  n ; k  n respectively, and that jRn;k ?qn;k Rn;k j; jSn;k ?qn;k Sn;k j; jTn;k ?qn;k Tn;k j  (1?qn;k) n for n  1000 and k  n? ; k  n? ; k  n? respectively. 100

2

3

(2)

(2)

+2

2

3

2

3

+3

2

2

2

3

+4

3

(2)

+2

5

+1

3 (2)

100

3

+2

2

3

3

The rigorous proof of these inequalities is rather lengthy and technical. We shall only `demonstrate' here the validity of two of them (those involving Rn;k ) using high level asymptotic analysis. Assume at rst that k  n? (the case n?  k  n will be dealt with separately). Consulting the de nition of (I ? ), we get that 2

2

2

3

1

2

+3

3

3

Rn;k = ?An;k + pn;k (1 + An? ;k? ) ? qn;k Bn;k = ?An;k + pn;k (1 + An? ;k? ) ? qn;k Bn;k g = Rn;k ? nn? k + pn;k  nn?? k ? qn;k  n?n k? g = n;k 2

2

3

2

(

1

1

1

1

+1

+1

3 +1 1)2

2

3 2

3

The term Rn;k is a rational expression in n and k and automatic manipulations show that

Rn;k = ?

?  2 3  ? ? 5 n3

8

26

1

+11

16(2

)(1

)

+ O( n ) : 1

4

The coecient of n above attains its maximum absolute value in the range [0; 2=3] at  ' 0:57 where it evaluates to approximately ?4:73. We thus see that this term does not give us any cause for concern. If we let ` = 2n ? 3k we get 1

3

n;k =

n2

=

n2

1

1

i h ? ` + pn;k  n?n  ` ? qn;k  `?  h     i 1 1 ? ` + 2 ` ? 2 `? + n pn;k  n?n ? ` ? qn;k ? `? : | {z } 2

1)2

(

+1

3

2

1

+1

2

3

(

1)2

1

1

+1

2

3

2

0

The rst expression in the last line disappears as it is one of the de ning relations of the sequences f `g; f `g; f `g. We may assume now that ` = o(n) since otherwise ` and `? are exponentially small and we have nothing to worry about. We can therefore use the relations pn;k = nn?`` = ? n` + o( n ) qn;k = nn `` = + n` + o( n ) together with the fact that n?n = 1 + n + O( n ), to get that +1

3

1

3

+

2

8

+ )

1

3

+

2

8

2

4

2(

4

2

2

1)2

(

1 1

1

2

i h n;k = (1 ? ` ) ` ? ` `?  n + o( n ) : 8

1

3

3

+1

8

3

3

1

3

The coecient of n here is maximised when ` = 5, where we get n; n? ' ? n: : Hence, for large enough n, and k  n? we even expect to have jRn;k j  n . 1

2

3

2

10

2

3

3

15

3

4

2 80

3

Assume now that

n?

2

1

3

k

n

2

+3

3

. Proceeding in a similar way, we get that

Rn;k = ?An;k + pn;k (1 + An? ;k? ) = ?An;k + pn;k (1 + An? ;k? ) ? n?n k? g = R0n;k g = 0n;k ? nn? k + pn;k  nn?? k + n?n k? Again if ` = 2n ? 3k then `? `  R0n;k  ? n and the maximum of this expression in the range ?3  `  1 is attained when ` = ?3 and R0n; n  ? :n . As for 0n;k we get 1

1

9(2

1

2

2

2

3

9(2

3

36

2

1)

2

8

135+198

1)

2

8

3 +1 1)2

(

3

1

1

3

16

65 8125

2 +3 2

3

i h n  + n? k? ? + p  ` ` n;k n n? h i h  i = n ? ` + ` + `? + n pn;k  n?n ? ` | {z }  `  1 ? `  n :

0n;k =

2

1

2 2

+1

9(

1

1

9(2

1)2

(

+1

2

3

1)

8

1)

2

1

2

8

(

1

1)2

+1

2

0

3

8

1

3

+1

The maximum absolute value is again attained when ` = ?3 where 0n; n ' ? n: . So, for large enough n, and any k  n , we expect to have jRn;k j  n . The slackness that we have introduced by requiring only that jRn;k j  n , allows us to prove this inequality for every n  1000. Turning our attention to the second inequality involving Rn;k , we note that for k  n? we have Rn;k ?qn;k Rn;k n;k ?qn;k n;k Rn;k ?qn;k Rn;k = + : ?q ?q ?q 2

+3

80

9 91

2 +3 2

3

3

2

100

3

2

8

3

(2)

(2)

+2

(2)

n;k

1

(2)

n;k

1

A simple manipulation yields

(2) Rn;k ?qn;k Rn;k+2 (2) ?qn;k

+2

(2)

n;k

1

(2) qn;k (2) (Rn;k ? Rn;k ?qn;k

= Rn;k +

1

(2)

+2

1

+2

) :

Note now that Rn;k ? Rn;k = O(n? ) or more precisely 4

+2

Rn;k ? Rn;k = ?



88+152

+2

2? 3 ? 2 ? 6

+64

16(2

) (1

126

)

4

+33

 n + O( n ) : 1

1

4

5

The coecient of n here is of course twice the derivative of the coecient of n in the corresponding expansion of Rn;k . It can be easily checked that jRn;k ? Rn;k j  n for say   . Now qn;k =(1 ? qn;k ) < 2n for every k  0 and furthermore qn;k =(1 ? qn;k ) = O(1) whenever  is bounded away from 0. The term (n;k ? qn;k n;k )=(1 ? qn;k ) attains a maximum of about ?2:33=n for ` = 12 and thus we can again obtain the desired inequality. Combining these facts we get the desired bound for k  n? . The case n?  k  n? should again be treated separately. We omit the details. The inequalities involving Sn;k and Tn;k can be `veri ed' in a similar manner. 2 1

1

4

3

3

4

+2

1

(2)

(2)

(2)

(2)

10

(2)

(2)

3

+2

2

8

3

16

2

7

3

2

3

3

4.5 Bounding the errors We saw in the previous subsection that ", the error of our estimation satis es the equation " = " + H where H satis es the conditions of Theorem 4.3. We now show that this implies " = O(n? ). 3

Theorem 4.4 If e = e + h where e = (a; b; c)T ,h = (r; s; t)T and

jhn;k j  nH ; jhn;k ? qn;k hn;k j  (1 ? qn;k )  nH (2)

(2)

+2

3

for all positions in with n  n  1000, and 15H

3

0

jan;k j; jcn;k j  n

3

; jbn;k j  10nH 3

for all positions in with n = n ; n + 1, then the same bounds on an;k ,bn;k and cn;k hold for all positions in with n  n . 0

0

0

Proof : What conditions should two constants A and B satisfy if we are to succeed in proving by induction that jan;k j  nA and that jbn;k j  nB ? Assuming the basis of the 3

3

induction to be already established, we check what conditions on A and B enable us to derive the induction step. Using the induction hypothesis and the conditions on hn;k , we can bound an;k as follows

jan;k j  p"n;k  jan? #;k? j + qn;k  jbn;k j + jrn;k j  qn;k  1 p n;k  (n ? 1)  A + n  B + n  H : 1

1

+1

3

3

3

If A > B + 2H then the last expression is less than nA for any suciently large n and k  n . This is because in we have pn;k  + o(1). In particular, if we choose A = 15H; B = 10H we must verify that 3

2

+3

1

2

2

"

#

 qn;k  1 A  A +  B +  H  (n ? 1) n n n for any n  1000 and 0  k  0:67n. This inequality involves only quantities like pn;k

pn;k

3

3

3

3

and qn;k that were explicitly de ned. Expanding these de nitions we nd that the claim to be veri ed is equivalent to the claim that

?2(4 + 3)(1 ? 3n + 3n ) + (8 ? 9)n  0 for any n  1000 and 0   = k=n  0:67. This inequality is easily veri ed. 2

3

The choice that A > B has so far been to our advantage. It will however make our lives much more dicult in the sequel. 17

a b

+

R ? a a b + R + R + R  R+  b ? c + b ? c + b

Figure 5: Expanding the de nition of bn;k . By expanding the recursive de nitions of an;k ,bn;k and cn;k in the way depicted in Figure 5 we get that

bn;k =

[pn;k ]  bn? ;k? + [qn;k ]  bn;k [qn;k(qn;k pn;k ? p0n;k qn? ;k )]  bn? ;k [qn;kpn;k ]  an? ;k? + [qn;k p0n;k ]  an? ;k [qn;kpn;k ]  rn? ;k + (sn;k ? [qn;k ]  sn;k ) [qn;k]  (tn;k ? [qn;k ]  tn;k ) (4)

? ? ? ?

1

1

+1

+4

+2

1

+1

(2)

1

+1

(3)

2

+1

1

1

+3

(2)

+2

(2)

1

+1

+2

(2)

+1

+3

+1

where as before qn;k = qn;k qn;k , qn;k = qn;k qn;k , qn;k = qn;k qn;k and pn;k = pn;k pn? ;k? . We assume here that k  n? so that all the terms given are indeed present. The case n?  k  n must be dealt with separately and the details are omitted. The important point to note here is the fact that bn? ;k contributes to bn;k along two di erent paths, once with a positive sign and once with a negative sign. Since qn;k pn;k  p0n;k qn? ;k these two contributions almost cancel each other out. Thus, when we add up (the absolute values of) the coecients of all the an0;k0 and bn0;k0 appearing in this expansion for bn;k we get a quantity n;k which for 0 <  is signi cantly less than 1. In fact, it is easy to check that n;k  () = ?  ? ?  . The function () attains the value at  = , the minimal value of (' 0:704) at  = and the maximal value of 1 at  = 1. We see therefore that a choice A; B  H should enable us to prove the induction step when  is bounded away from 0 and n is large enough. We might expect trouble when  ' 0 but this is exactly the place where the additional condition of Theorem 4.3 comes to our rescue. We have gone far enough in the expansion shown in Figure 5 to obtain a con guration in which the driving terms tend to cancel each other in pairs. Relying on the induction hypothesis and the conditions on hn;k we get that (2)

(3)

(2)

(4)

+1

2

2

2

10

3

(3)

(2)

+2

+3

1

11

3

+1

3

1

+1

+2

+1

+1

1

8

20

+22

(2

2

)3

9

3

3

2

19

1

4

3

27

2

2 qn;k pn;k + qn;k p0n;k 4 jbn;k j  (n ? 2) (n ? 1) 2 q (q + 4 (np?n;k1) + n;k n;k (3)

(2)

+1

+3

3

3

+1

3

18

3 5A

3 pn;k ? p0n;k qn? ;k ) qn;k 5 + n B (n ? 1) (4)

+2

+1

3

1

3

1

2 3 q p (1 ? q )(1 + q ) n;k 5 n;k + 4 n;knn;k + H n (2)

(2)

+1

3

3

where qn;k pn;k ? p0n;k qn? ;k = n?k?n?k?n?k? is indeed positive for all relevant values of n and k. We want to nd values for A and B for which this last expression is less than or equal to B n for all large enough n and k in the appropriate range. Since we are not interested in nding the optimal constants A and B , we just point out that again the choice A = 15H and B = 10H suces, i.e., the bound in the last inequality is less than nB for any n  1000 and k  0:67n. Expanding again the de nitions of pn;k ; qn;k and of pn;k ; qn;k ; qn;k ; qn;k we get that the condition that we have to verify is that the expression 6(

+1

+2

1

+1

(2

1)

1)(2

2)

3

3

(2)

? ?? ? ??

+

8

+

4

+

2

+ + + + + +

?

272





2 ? ?  ? ? ?  ?? ? ? ?  ?? ? ? ? ? ?   ? ? 

48

422

+ 141

9904 + 18558

51824

115326

247232

170768

(2

)

112

)

69032

1756

80

220

+ 3652

+ 178

+ 1692

+ 130959

415735

630812

+ 275520

4808 + 34920

(2

(4)



22071

350617

+ 861216

122384 + 473052

34392

+ 1551

+ 81991

782580

(3)

2 3 n  2  ? 3 4 n2  2 3 ? 4 5 n3 2 ? 3 4 ? 5 n4 2 3 4   ?   5 n5  2 3 4 5  ?   ?  n6 2 3 4   ?  5 n7 2 3 4 8  ?   n 2 ? 3 n9

9863

147888 + 391146

(2)

18428

+ 84636

+ 377241

198141

+ 58361

2590

100814

+ 65080

22308

+ 564

5076

+ 9306

7857

+ 3159

+ 567

39

is non-negative for n  1000 and 0    0:67. To show that this is plausible we note that the function  (2 ? ) (80 ? 220 + 178 ? 39 ) which is the coecient of n in the above expression is positive for 0 <   0:67. For values of  close to 0 we also have to consider the coecient of n which is approximately 224 when  ' 0. With slightly more technical work the positivity of this expression can be established rigorously. Finally, for cn;k we get 2

3

9

8

jcn;k j  p0n;k jan? ;k? j + qn;k jbn;k j  1

1

+1

p0n;k

(15

qn;k H

+10

n3

)



:

:H n3

12 5

2

Theorem 4.5 If e = (a; b; c)T is the solution of equation (1) (or (4)) and E = (A; B; C )T

is de ned by (3),(5) and (6) then 1500

jan;k ? An;k j  n for n  1000 and 0  k  jbn;k ? Bn;k j  1000 n for n  1000 and 0  k 

n

;

n

;

n

:

2

+3

2

3

2

jcn;k ? Cn;k j  1500 n for n  1000 and 0  k  3

+1

2

3

2

+4

2

Proof : It can be veri ed directly that these inequalities hold for n = 1000; 1001 and

all admissible values of k. The theorem then follows by combining Theorem 4.3 and Theorem 4.4. 2 19

4.6 Beyond the boundary layer We only have to consider the values of an;k for k  n . The values of bn;k for k  n are identically zero, by de nition, and the values of cn;k for k  n are of no interest since they are never used. For an;k in this region we have the simple relation 2

+4

2

3

2

+2

3

+5

3

an;k = pn;k (1 + an? ;k? ) for k  n? : By induction we can prove that for k  n? we have   : (7) an;k = n?kk ? nk?k  nn??kk??  nn??kk? ? a n?k ? ; n?k? Note that the value a n?k ? ; n?k? lies in , just outside the boundary layer as it is of the form an0; n0 ? . 2

1

2

1

1

3

1

3

[4(

!

2(

)+1

3(

2

3

(2

)

)!

)

[2(

2 2(

2]!

2(

1)

1)]!

2(

)+1

3(

)

2 2(

1)

1)

2

Using Stirling's formula we get, for k = n with <  < 1, that 2

3

k n?k !

(2

)!



n?k ? n?k?

[4(

)

[2(

2]!

1)]!

where



q

 ?L  n ?  e (

)

2

i h L() = ln  ?? ? ? : It can be checked that L(2=3) = L(1) = 0 while L() > 0 for  2 (2=3; 1). Thus, for any k with  = k=n bounded away from both 2=3 and 1 we get that an;k ' n?kk with an exponentially small error! The most accurate approximation is obtained for k = n where  = 1 ? p ' 0:875965 for which L() ' 0:249353. For an;n?` , equation (7) becomes   : an;n?` = n`?` ? nn?``  ``??  ``? ? a `? ; `? We can thus get explicit formulae for an;n?` where ` is constant. All we have to know for this purpose is the single value of a `? ; `? . In particular we get an;n = n an;n? = n? ? n n n n? an;n? = n? ? n n ::: n? (2

)

(2

)

)]2(1

[8(1

)

2(

)+1

1

65

2 +1

(

)!

(

+ )!

3

2

[2(2 [2(

2 2(

1)]!

2(

1)]!

and in general

3

2 2(

1)

1)

48

2

5

(

+2)(

4

4

1)

2 +1

+1)

(

1)

2983680

9

(

+4)(

+3)

(

3)

an;n?` = n`?` + O(n? ` ) : Hence, the diagonals in the en;k table behave essentially as linear progressions. 2

2 +1

4.7 Verifying the optimal strategy For n  1000 the validity of the optimal strategy can be veri ed directly. We now prove the validity of the optimal strategy for n > 1000 by induction. Suppose that we have already veri ed the claimed optimal strategy for all positions (n0; k0) with 20

either n0 < n or n0 = n and k0 > k. This means that, so far, the values of the positions agree with those obtained from equation (1), and thus all the estimations of the previous subsections are valid. If n + k is even and k 6= 0; n, we use these estimates to show that en;k > 0; en;k (if k = 0 or n we already know that en;k = en;k ). If n + k is odd and k  n we use these estimates to show that en;k > 0; en;k , and if n + k is odd and k > n we use them to show that en;k ; en;k < 0. This will prove by induction the validity of the optimal strategy for every position. As can be seen from Figures 2 and 3, the only inequalities for which we really need the O( n ) terms in our approximations are those that claim that en;k = bn;k > 0 when n + k is odd and k  n , and that en;k < 0 when n + k is odd and k  n . Even here, the O( n ) terms are needed only when  ' . 1

2

1

2

1

+1

+1

3

3

2

2

2

2

2

2

1

1

2

2

1

+1

3

2

2

+2

3

2

3

5 Variants of the game As the reader has probably realised by now, there is no point in ipping back the cards after inspection if both players will remember them anyway. This convention also allows the game to be played as a game of strategy by players with imperfect memories. A 0-move now simply corresponds to a decision to end the game, while a 1-move will mean literally the inspection of one new card, without the useless ritual of inspecting an old one too. With these new conventions it seems natural to allow 0-moves and 1-moves from all positions (even those of the form (n; 0) and (n; 1)) and we shall do so throughout this section. What is the e ect of allowing 0- and 1-moves from positions of the form (n; 0) and 0-moves from positions of the form (n; 1)? Since the value of every position in the new game is by de nition non-negative some changes are bound to occur but, as we shall soon see, the overall e ect is minimal. The values of the simplest positions under the new rules are given in Table 4. These new values will of course in uence the values of almost all other positions, but it turns out that the changes are exponentially diminishing in n for every k = n with  < c < 1. The new optimal moves from positions (n; k) with k  n  15 are given in Table 5. There are again some exceptions when n  5 but, apart from that, the only di erence between Table 5 and Table 2, giving the optimal moves in the original version of the game, is that a 0-move is now used from positions (n; 0) with n even. This was to be expected as the values of these positions were hitherto negative. The analysis of this version of the game is almost identical to the one carried out in the previous section. The only di erence is that a second boundary layer now exists when  ' 0, caused by the 0-moves used from positions (n; 0) with n even. We now turn to the study of variants of the game obtained by restricting the set of allowed moves. We have already encountered an example of this kind in section 4.3 where we have assumed that 1-moves and 2-moves are the only moves allowed. We consider two other restricted versions.

21

n=1 n=2 n=3 n=4 n=5 n=6 n=7

k=0 k=1 k=2 k=3 k=4 k=5 k=6 k=7 1 0 0 0 0 0

1 2 3

0

2

1

1

7

3

3 0

1

4

7

7

4 0

0

1 3

1

11

5

11

231

105

42

14

5 0

151

151

20

272

19

125

3003

3003

693

1155

210

126

6 0

7

Table 4: The expected values of the simplest positions when 0- and 1-moves are allowed everywhere.

5.1 Version 1 In this subsection we investigate the version of the game in which 1-moves are the only moves allowed. While there is no question of nding the optimal strategy in this case, the analysis of the expected gains from the di erent positions turns out to be interesting. If we denote again by en;k the expected gain from position (n; k), we get immediately the following recurrence relation en;k = pn;k (1 + en? ;k? ) ? qn;k en;k (8) where the only initial condition required is e ; = 0. It turns out that in this version, each diagonal en;n?r for a xed r forms an arithmetical progression, en;n?r = r n + r : (9) By substituting this relation back into (8), we can prove (9) by induction and get the following recurrence relations for r  1 1

1

+1

0 0

  r = r?r r ? r? ; r = ( r ? 1) ? r? ; where = 1, = 0. By expanding the de nition of r we get h r = (?1)r  ::::::r r 1 ? +  ?   + : : : + (?1)r 2

2

1

1

1

2

1

1

2

0

0

2 4

3 5

2

(2 +1)

1

1 3

1 3 5

2

2 4

2 4 6

Recalling the Wallis product we have

 = 2  2  4  4  6  6 ::: ; 2 1  3  3  5  5  7 ::: s  2  4  : : :  2r  3  5  : : :  (2r + 1) 2(2r + 1) : 22

 ::: r?  ::: r

1 3

2 4

(2

1)

2

i

:

n=1 n=2 n=3 n=4 n=5 n=6 n=7 n=8 n=9 n = 10 n = 11 n = 12 n = 13 n = 14 n = 15

21 021 0021 02101 002101 0212101 21212101 021212101 2121212101 02121212101 212121210101 0212121210101 21212121210101 021212121210101 2121212121210101

Table 5: The optimal moves for n  15 when 0- and 1-moves are allowed everywhere. The terms inside the square bracket have decreasing absolute values and alternating signs. By Leibnitz'spTheorem the limit of the sum of this series exists as r ! 1, and can be shown to be 2=2. We conclude that    = (?1)r pr : r  8 1 2

Similarly we can expand the de nition of r and get that r =  ( r ? 1) ?  ( r? ? 1) +  ( r? ? 1) ? : : : +  (?1)r ( ? 1) ; or equivalently ( r X if r odd : 1 r ? s r = 2  (?1) s ? 0 otherwise 1

1

2

2

1

1

1

2

2

0

2

1

s

2

=0

Since r  (=8) = (?1)r r? = , we immediately get that 1 2

1 2

r 

  =

(?1)r r :

en;k = n?k n + n?k 

 =

(?1)n?k

 =

p

Hence, if n ? k ! 1 then and, in particular,

1 2

8

1 2

8

p

h

pnn?k

p

+ n?k

i

;

(?1)n n : The behaviour of the en;k , as well as the method used to nd it, are therefore quite di erent in this case.

en;  0

1 2

2

23

5.2 Version 2 In this subsection we check what happens if 2-moves are the only moves allowed. The analysis in this case can serve as an introductory example to the use of the bootstrapping method of Subsection 4.3. We omit the details but point out that, in contrast to what we have seen so far, the parity of n + k does not play a major role, unless  = k=n ' 1. The asymptotic expansion for en;k obtained by bootstrapping is en;k = ? ? + ? ?   ??   n + ?  ? ? ?   n + : : : and it is again valid whenever  is bounded away from 1. 2

4(2

)(1

16

)

64

16(2

+64

2

2

) (1

19 )

2

3

1

64

144

+216

64(2

2

3

198

) (1

)

3

3

+69

4

1

2

6 More possibilities How should one play against players that only use 1-moves? The optimal strategy against such players is to play 1-moves from positions (n; k) with n + k even, and 0-moves from positions (n; k) with n + k odd. The expected gains are then the absolute values of the corresponding expected gains when both players always use 1-moves. This is just Version 1 of the game analysed in the previous section. How should one play against players that only use 2-moves? The optimal strategy here is to play 1-moves from `almost' all positions. The exact details here are more complicated and not entirely known to us. What happens if the objective of the players is to maximise their probability of winning? A position is now characterised by a triplet (n; k; `) where ` is the lead of the player to play next. The lead is the di erence between the number of pairs held by the two players. When a player is in the lead, or at least even (i.e. `  0), her optimal moves are almost identical to those of the gain maximising strategy. If a player is trailing, then she has no choice but to take her chances and play 2-moves whenever 0-moves are suggested by the gain optimising strategy. Obtaining an exact formulation of the optimal strategy here is an interesting problem. What happens if more players join the game? The right move to make depends in this case mainly on (n ? k) mod p, where p is the number of players. The optimal move from position (n; k) in the three player game, for example, is a 0-move if n ? k  2 and k  3, a 1-move if n ? k  0 and k  1, and a 2-move otherwise. All these congruences are, of course, modulo 3. What happens if the players have imperfect memories?

7 Concluding remarks The optimal strategy for playing the memory game turned out to be very simple. The analysis and proof presented here were however extremely involved. Is there an easier 24

way of proving the results stated in Section 3? While the results of this work are mainly of recreational value, we hope that the methods used here will prove useful elsewhere. We would like to stress again the indispensable role played in this work by experimentation and by automated symbolic computations.

Acknowledgement The rst author would like to thank Tamir Shalom and his daughter Loran for interesting him in the problem, and Yuval Peres for his help in the initial analysis attempts.

Note added in proof: After completing this work, we heard that Sabih H. Gerez and Frits Gobel  had previously considered the analysis of the memory game. They had empirically found the optimal strategy of Section 3 and explained parts of it theoretically. They also considered the version of the game in which 0-moves are not allowed. They discovered that in this version a surprising move optimises the expected pro t from positions of the form (n; n ? 1) where n  8. In this move, a new card is ipped in the rst ply. If this does not match any known card, a second new card is ipped. But if the rst card ipped does match a known card then an old card not matching the rst card is chosen in the second ply. This sacri ce deliberately leaves a matching pair on the table! The next player would collect this pair but then be in a similarly awkward position in which the sacri ce move is again optimal. With this new move en;n?  ? + n . 3

1

2

5

2

References  S.H. Gerez, An analysis of the \Memory" game (in Dutch), 65-afternoon project report, Department of Electrical Engineering, University of Twente, Holland, June 1983.  D.H. Greene, D.E. Knuth, Mathematics for the analysis of algorithms, second edition, Birkhauser, 1982.  Oxford English Dictionary, 2nd edition, Oxford University Press, 1989.  I.N. Stewart, \Concentration: A Winning Strategy," Mathematical Recreations section of Scienti c American, October 1991.

25