Вы находитесь на странице: 1из 5

Here are solutions to some problems from homework 2, to help with preparations for the first 152 midterm.

Note that the examinable material is

everything in the first four sections of Part I of the textbook (that is the
material from homework 2 and homework 3).
(1) In the Misere version of the takeaway game, where on each
turn a player can take 1,2 or 3 coins, what are the Ppositions?
For practice, lets do a bit more than compute the Ppositions: we will
find the SpragueGrundy values for this game (remember that the P
positions are the positions with Sprague-Grundy equal zero, so this will
solve the stated problem too).
Recall the following procedure for computing SpragueGrundy values.
Begin with the terminal positions, and give them SpragueGrundy
value 0. Then look at the next position for which we have not computed the SpragueGrundy value. Determine which positions follow
this position (that is, what positions can I get to, if Im starting in the
current position?). Write down the SpragueGrundy values of the follower positions. Pick the smallest number from {0, 1, 2, 3, } that does
not appear on the list I wrote down. This value is the SpragueGrundy
value for the next position.
As always, the terminal position gets Sprague-Grundy 0. In the Misere
game, as mentioned in lecture, we will take 1 to be the terminal position. So g(1) = 0. The only position that is a follower of 2 is 1, which
has SpraagueGrundy value 0. So the SpragueGrundy values of the
followers of 2 are: {0}. The smallest number not in this list is 1, so
this is the SpragueGrundy value for 2: g(2) = 1.
The followers of position 2 are 1 and 2, which have SpragueGrundy
values 0, 1 respectively. The smallest number not appearing here is 2,
so g(3) = 2.
Continuing in this way, we see that g(4) = 3, g(5) = 0, g(6) = 1, g(7) =
2, g(8) = 3. Notice that because the subtraction set is 1, 2, 3, the
SpragueGrundy value of a position depends only on the previous three
values. This means that once we see a repeat of three consecutive
SpragueGrundy values, we know the whole sequence repeats. In this
case, g(5), g(6), g(7) are the same as g(1), g(2), g(3), so we see that
the sequence repeats every four values. (For the exam, it is important

to give some sort of justification like this when determining Sprague

Grundy values. It is not enough just to spot a pattern and say that it
is true.). In particular, the Ppositions are 1, 5, 9, 13, . The general
description of these numbers is 4x + 1.
(2) Determine whether the following positions are N or P, in the
takeaway game with given subtraction set.
(i) S = {1, 3, 5}, positions [72, 81]
(ii) S = {1, 2, 4, , 2k , }, positions [239, 244]
(i) As in question one, lets compute the SpragueGrundy values instead of the N/P postions, for practice. In this case the terminal
position is 0, so g(0) = 1. The first few values are
g(1) = 1, g(2) = 0, g(3) = 1, g(4) = 0, g(5) = 1, g(6) = 0, g(7) = 1
The subtraction set is {1, 3, 5}, so the SpragueGrundy value only
depends on the previous 5 values. Since g(0), g(1), g(2), g(3), g(4)
is the same as g(2), g(3), g(4), g(5), g(6), this 0, 1, 0, 1 pattern repeats. So between 72 and 81 the SpragueGrundy values are
0, 1, 0, 1, 0, 1, 0, 1, 0, 1
(ii) Determining the first few positions, we see:
0 : P, 1 : N, 2 : N, 3 : P, 4 : N, 5 : N, 6 : P
The pattern appears to be P,N,N repeating, with the P values
appearing exactly when the number of coins is a multiple of three.
Unlike the previous questions, the subtraction set here is infinite,
so we cannot simply say that the sequence depends on some finite
number of previous terms, and hence repeats. Instead, assue that
the P,N,N pattern holds up as far as some position 3x. Now the
followers of 3x are numbers of the form 3x 2k , for some k. This
is never a multiple of 3, and so the followers of 3x are never P
positions. Hence 3x is an Nposition. Finally notice that 3x + 1
and 3x + 2 both have 3x as a follower, and because 3x is a P
position, this means that 3x + 1 and 3x + 2 are Npositions. So
the pattern repeats.
2

Now 240 is a multiple of three, and hence

239 : N, 240 : P, 241 : N, 242 : N, 243 : P, 244 : N
A good exercise is to determine the SpragueGrundy values for
this question, with justification (it will be very similar to what we
have done here).
(3) In Nim, what are the possible winning moves from position
(17, 22, 27)?
We know that the Ppositions in Nim are exactly the positions (x, y, z)
where x y z = 0. A winning move is one that puts your opponent
in a Pposition, so we need to find out which possible moves from
(17, 22, 27) result in a Pposition.
Firstly, let us make sure that we arent in a Pposition (in which case
we are doomed if our opponent is clever so there are no winning
moves). Writing the three numbers in binary:
17 = (10001)2
22 = (10110)2
27 = (11011)2
The nimsum of these three numbers is (11100)2 . To make this zero,
we need to change the first three bits to zero. If we take from the
17chip pile, we need to change (10001)2 to (01101)2 = 13. If we take
from the 22chip pile, we need to change (10110)2 to (01010)2 = 10.
Finally, if we take from the 27chip pile, we need to change (11011)2
to (00111)2 = 13.
This means there are three winning moves: (17, 22, 27) (13, 22, 27),
(17, 22, 27) (17, 10, 27) and (17, 22, 27) (17, 22, 13). Notice that
there are three winning moves here. This is not always the case!. In
three pile Nim there are at most three winning moves, but sometimes
there are fewer moves than this (consider the case (2, 1, 1) what happens when we do what we did above in this case?).
(4) In Nimble (as described in homework two), find a winning
move from the position (0, 1, 0, 0, 2, 0, 5).
As suggested by the question, we should show that this game is just
3

Nim in disguise. Lets consider a simpler configuration: (0, 1, 0, 1, 0, 1).

This means there is one coin on board square 1, one coin on board
square 3 and one coin on board square 5. A move in Nimble consists
of taking a coin placed at board square and moving it to any board
square to the left.
Imagine that on each coin, its current board square is written on top
of it. A move then consists of picking a coin and reducing the number
written on it. In Nim, a move consists of picking a pile and reducing
the number of coins in it. So nimble with three coins is exactly the
same as Nim with three piles of coins. For example, nimble with coins
(0, 1, 0, 1, 0, 1) is the same as Nim with three piles, containing 1, 3 and
5 coins.
In this question, there are 10 coins. So this game is the same as Nim
with ten piles, one with 1 coin, two piles with 4 coins and six piles
with 5 coins. The nim sum here is 1, and this can be reduced to
zero by removing one coin from the pile with only 1 coin in it. The
corresponding winning move in Nimble is to move the coin in square
one to square zero.
(5) In Turning Turtles, find a winning move from the position
HHHHHT.
As suggested in the question, we can (almost) turn Turning Turtles
into Nim by viewing every H as a Nim pile, with number of chips equal
to the position that the H is in. A move in TT consists of taking H and
possible flipping a coin to the left. Let us consider what these moves
mean using our Nim interpretation.
If we flip an H at position j, and do nothing else, this corresponds in
Nim to removing the entire pile with j coins.
If we flip an H at position j, and then flip a T to an H at position i,
where i < j, this corresponds in Nim to replacing the pile with j coins
with a coin with i coins.
If we flip an H at position j and then flip an H to a T at position i, this
corresponds in Nim to removing two piles. This is a problem, because
it is not a valid Nim move. So Turning Turtles and Nim are slightly
different games. However, for our strategy to work, all that matters is
that there is always some move that makes the nim sum zero (assuming
4

the nim sum wasnt zero to begin with), and that if the nim sum is zero
than any move will make it non-zero.
Now lets return to the question. Consider the position in this question,
HHHHHT. This corresponds to Nim with five piles, with one, two,
three, four and five coins respectively. One winning move in Nim is to
take one coins from the pile with 5 coins. This resulting Nim configuration would be (1,2,3,4,4). This is another problem for us, because we
cannot represent a Nim game with two equal piles in Turning Turtles.
However all that matters is we reduce to a position where the nim sum
is zero. One way to do this is to remove all coins in both the pile with
four coins and the pile with five coins, which we are allowed to do in
Turning Turtles. So this is a winning move: HHHTTT.