The Vile, Dopy, Evil and Odious Game Players
Total Page:16
File Type:pdf, Size:1020Kb
The vile, dopy, evil and odious game players Aviezri S. Fraenkel¤ Department of Computer Science and Applied Mathematics Weizmann Institute of Science Rehovot 76100, Israel February 7, 2010 Wil: We have worked and published jointly, for example on graph focality. Now that one of us is already an octogenarian and the other is only a decade away, let's have some fun; let's play a game. Gert: I'm game. Wil: In the Fall 2009 issue of the MSRI gazette Emissary, Elwyn Berlekamp and Joe Buhler proposed the following puzzle: \Nathan and Peter are playing a game. Nathan always goes ¯rst. The players take turns changing a positive integer to a smaller one and then passing the smaller number back to their op- ponent. On each move, a player may either subtract one from the integer or halve it, rounding down if necessary. Thus, from 28 the legal moves are to 27 or to 14; from 27, the legal moves are to 26 or to 13. The game ends when the integer reaches 0. The player who makes the last move wins. For example, if the starting integer is 15, a legal sequence of moves might be to 7, then 6, then 3, then 2, then 1, and then to 0. (In this sample game one of the players could have played better!) Assuming both Nathan and Peter play according to the best possible strategy, who will win if the starting integer is 1000? 2000?" Let's dub it the Mark game, since it's due to Mark Krusemeyer according to Berlekamp and Buhler. Gert: To get a feel for the Mark game, I'd construct a small table listing its P -positions (P revious player wins) and N-positions (Next player wins). For example, 0 2 P, since the Next (¯rst) player cannot move, so the Previous (second) player wins by default, 1 2 N since Next can move to 0 2 P; and 2 2 P. In general, every position that has a follower in P is in N , and every position all of whose followers are in N is in P.(P and N are the set of all P - and N-positions respectively.) ¤[email protected] http://www.wisdom.weizmann.ac.il/~fraenkel 1 Wil: (Extracting his palm computer)... Here it is! n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 P=N PNPNNNPNPNPNNNPNNNPNNNPN Gert: It's hard to see what's going on...It might be useful to separate out the P -positions and the N-positions into two sequences. Wil: Alright, the rearranged table below suggests that bn = 2an for every nonnegative integer n, P = [n¸0bn, N = [n¸1an, where an = Nn, n ¸ 1; bn = Pn, n ¸ 0. But what's Nn?... Oh I see, Nn = mexfPi;Ni : 0 · i < ng for every n ¸ 0, where mex of a ¯nite subset of nonnegative integers is the least nonnegative integer not in the set. In particular, mex of the empty set is 0. Notice that the sequences (for n ¸ 1) are complementary: they split the positive integers n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 an 0 1 3 4 5 7 9 11 12 13 15 16 17 19 20 21 23 25 27 28 29 31 33 35 bn 0 2 6 8 10 14 18 22 24 26 30 32 34 38 40 42 46 50 54 56 58 62 66 70 Gert: Since 15 2 N which has the follower 14 2 P, we indeed see, as hinted by Berlekamp-Buhler, that Nathan could have played better by moving 15 ! 14 rather than 15 ! 7, thus securing his win! But for deciding 1000 and 2000, the recursive de¯nition of the P - and N-positions is not too convenient. Is there a \closed form" formula for them, I wonder? Wil: Well, the second sequence is not a \spectrum", i.e., there exist no real ®, γ such that bn = [n¸0bn® + γc (bxc is the integer part of the real x), since a necessary { though not su±cient { condition for that is that bn+1¡bn 2 fk; k+1g for some integer k, and here the di®erences are 2 and 4. Since the sequences are complementary, also the ¯rst sequence is not a spectrum... However, the fact that there are two followers and one of them is halving, suggests to consider some sort of binary numeration system. Gert: The simplest such system is the ordinary positional binary system... Indeed, it appears that P is the set of all dopy numbers and N is the set of all vile numbers. 2 Wil: What are dopy and vile numbers? Gert: The dopy numbers are those whose binary representations end in an odd number of 0s, and the vile numbers are those that end in an even number of 0s. Wil: ...No doubt their names are inspired by the odious and evil numbers, those that have an odd and an even number of 1's in their binary represen- tation respectively. To indicate that we count 0s rather than 1s, and only at the tail end, the \od" and \ev" are reversed to \do" and \ve" in \dopy" and \vile". \Odious" and \evil" where coined by Elwyn Berlekamp, John Conway and Richard Guy while composing their famous book Winning Ways. Gert: Precisely. Indeed, the sequence fangn¸1 consists of all alternately evil and odious numbers: a2n¡1 odious, a2n is evil (n ¸ 1); the same holds for bn, which is just a shift of an... The binary representations of 1000 and 2000 are 1111101000 and 11111010000 respectively, so Peter can win 1000 and Nathan can win 2000. This solves the puzzle for every positive integer k with a linear-time algorithm in its input size O(log k). Anything else? Wil: Yes, but before that my palm notices that the sequences fangn¸1 and fbngn¸1 are the sequences A003159 and A036554 respectively in the famous Neslopedia. Gert: Neslopedia?... Oh, you mean Neil Sloane's Encyclopedia of Integer Sequences, indeed a wonderful tool for doing math, especially discrete math. Wil: Yes! As to your question \anything else?", it would be nice to play this game in a sum of games. Gert: You mean, given a ¯nite collection of games, Nathan and Peter each select a game at each of their turns and make a legal move therein? The player making the last move in the last surviving game wins? Wil: Yes on both counts... I think that the P , N tool is not strong enough to decide sums of games. Gert: ...Right. For example, the sum of two Mark games with value 1 2 N is clearly a P -position in their sum, yet the sum of 1 and 2 2 N is an N-position in their sum. Indeed, the ¯rst player can move to (1; 1) and win. However, the sum of P -positions is always a P -position in the sum. Wil: To analyze sums, it's helpful to compute the Sprague-Grundy function, g-function for short, and then compute the Nim-sum (or XOR, or sum over GF(2)) of the g-values: Nim-sum 0 is equivalent to a P -position of a single game; nonzero Nim-sum { to an N-position of a single game... My palm computer 3 produced the following table. n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 g 010212010201210212012102 Gert: Notice that there can be no value larger than 2, since each game position has only two followers. All the 0s of g (beyond 0) clearly comprise all the dopy numbers | the P -positions. But which are 1s and which are 2s?... Oh, the odious and evil numbers raise their revolting heads again! All the 1s of g comprise all the vile-odious numbers and all the 2s of g comprise all the vile-evil numbers. Wil: So if I leave you in the 3-game position (1; 3; 4) where will you move to? Gert: Well, 1 + 3 + 4 = 8, so I see that you left me in a P -position from which, whatever I do, I'll lose. I expected a more gentlemanly gesture from you. Wil: You are indeed vile and evil! Gert: I think that we won't be friends anymore after all these unwarranted insults! Wil: All I meant is that the position I suggested to you is vile-evil: g(1) © g(3) © g(4) = 1 © 2 © 1 = 2, and g(n) = 2, is equivalent to a single game where n is vile-evil, as you had pointed out previously. I suggested to you a position from which you can win, namely, with the move 3 ! 2. Gert: Indeed, this move makes the position dopy. I apologize profusely. I erred twice: Instead of Nim-summing the g-values, I summed their arguments... The Neslopedia indicates that fn : g(n) = 1g seems to comprise all vile-odious numbers, and fn : g(n) = 2g comprises all vile-evil numbers... Incidentally, until now we considered normal games, that is, the player mak- ing the last move wins. What about mis`ere play of Mark, where the player making the last move loses? Wil: Then we can assume that 1 is the last move, so 1 2 P.