about The Game of Nim's Theorem 1 which almost like SG

2. The Game of Nim.
The most famous take-away game is the game of Nim, played as follows. There are
three piles of chips containing x1, x2, and x3 chips respectively. (Piles of sizes 5, 7, and 9
make a good game.) Two players take turns moving. Each move consists of selecting one
of the piles and removing chips from it. You may not remove chips from more than one
pile in one turn, but from the pile you selected you may remove as many chips as desired,
from one chip to the whole pile. The winner is the player who removes the last chip. You
can play this game on the web at ( http://www.chlond.demon.co.uk/Nim.html ), or at Nim
Game ( http://www.dotsphinx.com/nim/).
2.1 Preliminary Analysis. There is exactly one terminal position, namely (0, 0, 0),
which is therefore a P-position. The solution to one-pile Nim is trivial: you simply remove
the whole pile. Any position with exactly one non-empty pile, say (0, 0, x) with x > 0
is therefore an N-position. Consider two-pile Nim. It is easy to see that the P-positions
are those for which the two piles have an equal number of chips, (0, 1, 1), (0, 2, 2), etc.
This is because if it is the opponent’s turn to move from such a position, he must change
to a position in which the two piles have an unequal number of chips, and then you can
immediately return to a position with an equal number of chips (perhaps the terminal
position).
If all three piles are non-empty, the situation is more complicated. Clearly, (1, 1, 1),
(1, 1, 2), (1, 1, 3) and (1, 2, 2) are all N-positions because they can be moved to (1, 1, 0) or
(0, 2, 2). The next simplest position is (1, 2, 3) and it must be a P-position because it can
only be moved to one of the previously discovered N-positions. We may go on and discover
that the next most simple P-positions are (1, 4, 5), and (2, 4, 6), but it is difficult to see
how to generalize this. Is (5, 7, 9) a P-position? Is (15, 23, 30) a P-position?
If you go on with the above analysis, you may discover a pattern. But to save us
some time, I will describe the solution to you. Since the solution is somewhat fanciful and
involves something called nim-sum, the validity of the solution is not obvious. Later, we
prove it to be valid using the elementary notions of P-position and N-position.
2.2 Nim-Sum. The nim-sum of two non-negative integers is their addition without
carry in base 2. Let us make this notion precise.
Every non-negative integer x has a unique base 2 representation of the form x =
xm2m+xm.12m.1+· · ·+x12+x0 for some m, where each xi is either zero or one. We use
the notation (xmxm.1 · · · x1x0)2 to denote this representation of x to the base two. Thus,
22 = 1 · 16 + 0 · 8 + 1 · 4 + 1 · 2 + 0 · 1 = (10110)2. The nim-sum of two integers is found
by expressing the integers to base two and using addition modulo 2 on the corresponding
individual components:
Definition. The nim-sum of (xm · · · x0)2 and (ym · · · y0)2 is (zm · · · z0)2, and we write
(xm · · · x0)2 ⊕ (ym · · · y0)2 = (zm · · · z0)2, where for all k, zk = xk + yk (mod 2), that is,
zk = 1 if xk + yk = 1 and zk = 0 otherwise.
I – 9
For example, (10110)2 ⊕ (110011)2 = (100101)2. This says that 22 ⊕ 51 = 37. This is
easier to see if the numbers are written vertically (we also omit the parentheses for clarity):
22 = 101102
51 = 1100112
nim-sum = 1001012 = 37
Nim-sum is associative (i.e. x ⊕(y ⊕ z) = (x⊕ y)⊕z) and commutative (i.e. x⊕y =
y ⊕ x), since addition modulo 2 is. Thus we may write x ⊕ y ⊕ z without specifying the
order of addition. Furthermore, 0 is an identity for addition (0⊕x = x), and every number
is its own negative (x ⊕ x = 0), so that the cancellation law holds: x ⊕ y = x ⊕ z implies
y = z. (If x ⊕ y = x ⊕ z, then x ⊕ x ⊕ y = x ⊕ x ⊕ z, and so y = z.)
Thus, nim-sum has a lot in common with ordinary addition, but what does it have to
do with playing the game of Nim? The answer is contained in the following theorem of C.
L. Bouton (1902).
Theorem 1. A position, (x1, x2, x3), in Nim is a P-position if and only if the nim-sum of
its components is zero, x1 ⊕ x2 ⊕ x3 = 0.
As an example, take the position (x1, x2, x3) = (13, 12, 8). Is this a P-position? If not,
what is a winning move? We compute the nim-sum of 13, 12 and 8:
13 = 11012
12 = 11002
8 = 10002
nim-sum = 10012 = 9
Since the nim-sum is not zero, this is an N-position according to Theorem 1. Can you find
a winning move? You must find a move to a P-position, that is, to a position with an even
number of 1’s in each column. One such move is to take away 9 chips from the pile of 13,
leaving 4 there. The resulting position has nim-sum zero:
4 = 1002
12 = 11002
8 = 10002
nim-sum = 00002 = 0
Another winning move is to subtract 7 chips from the pile of 12, leaving 5. Check it out.
There is also a third winning move. Can you find it?
2.3 Nim with a Larger Number of Piles. We saw that 1-pile nim is trivial, and
that 2-pile nim is easy. Since 3-pile nim is much more complex, we might expect 4-pile
nim to be much harder still. But that is not the case. Theorem 1 also holds for a larger
number of piles! A nim position with four piles, (x1, x2, x3, x4), is a P-position if and only
if x1 ⊕ x2 ⊕ x3 ⊕ x4 = 0. The proof below works for an arbitrary finite number of piles.
2.4 Proof of Bouton’s Theorem. Let P denote the set of Nim positions with nimsum
zero, and let N denote the complement set, the set of positions of positive nim-sum.
We check the three conditions of the definition in Section 1.3.
I – 10
(1) All terminal positions are in P. That’s easy. The only terminal position is the
position with no chips in any pile, and 0 ⊕ 0⊕· · · = 0.
(2) From each position in N, there is a move to a position in P. Here’s how we
construct such a move. Form the nim-sum as a column addition, and look at the leftmost
(most significant) column with an odd number of 1’s. Change any of the numbers that
have a 1 in that column to a number such that there are an even number of 1’s in each
column. This makes that number smaller because the 1 in the most significant position
changes to a 0. Thus this is a legal move to a position in P.
(3) Every move from a position in P is to a position in N. If (x1, x2, . . .) is in P
and x1 is changed to x
1 < x1, then we cannot have x1 ⊕ x2 ⊕ · · · = 0 = x
1
⊕ x2 ⊕ · · ·,
because the cancellation law would imply that x1 = x
1. So x
1
⊕ x2 ⊕ · · · = 0, implying
that (x
1, x2, . . .) is in N.
These three properties show that P is the set of P-positions.
It is interesting to note from (2) that in the game of nim the number of winning
moves from an N-position is equal to the number of 1’s in the leftmost column with an
odd number of 1’s. In particular, there is always an odd number of winning moves.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值