Alice and Bob are playing a game called Moving Chips . The game is played on an board where some cells have some chips on it. Two players move alternately. Each turn consists of one person moving a chip to any cell to its left or any cell to its top. For example, the possible movements of chip A on a board is:
The last player who moves all the chips to the top left cell wins.
Consider the configuration of a
board in
this
file.
.
denotes an empty cell and a digit denotes the number of chips on that cell.
Alice will move first. Assume that both players move optimally, who will win the game?
Clarifications :
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Let the rows be numbered 1 to 100 from top to bottom, and the columns be numbered 1 to 100 from left to right.
First, how can we figure out who wins?
If you're familiar with the game Nim , this is actually very similar to it. Suppose a chip is in row r + 1 and in column c + 1 . Interpret this as two Nim piles, one of size r and one of size c . If we move the chip to row r ′ + 1 (with r ′ < r ), this is equivalent to reducing the pile of size r to size r ′ . Likewise, if we move the chip to column c ′ + 1 , this is equivalent to reducing the pile of size c to size c ′ .
This interpretation is correct:
Thus, we can interpret this as a game of Nim. And conveniently, we know how to solve Nim; we take the XOR of the sizes of the piles, and if it's 0, then the second player wins, otherwise the first player wins.
Now that we've shown that, we can code it: convert it to a game of Nim, and find the winner.