The game Same-Nim is a two player game played with piles of stones. A valid move consist of removing a positive number of stones from one of the piles, such that there is some pair of piles that contains the same number of stones. The players alternate turns to make a move. A player loses the game if they are unable to remove any stones on their turn.
A game of Same-Nim is played with 5 piles of sizes ( 1 0 , 1 0 , a , b , c ) , where a , b , c are integers from 1 to 10 inclusive. For how many of the 1 0 0 0 possible ordered triples ( a , b , c ) does the first player have a winning strategy?
Details and assumptions
A valid move may result in more than 1 pair of piles that contain the same number of stones.
The pair of piles with the same number of stones may both have 0 stones, if the piles had stones in them when the game started.
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.
Theorem . In a normal Nim game, the player making the first move has a winning strategy if and only if the nim-sum (or vastly known as xor. ⊕ , sum) of the sizes of the heaps is nonzero. Otherwise, the second player has a winning strategy.
Proof : Notice that the nim-sum ( ⊕ ) obeys the usual associative and commutative laws of addition ( + ), and also satisfies an additional property, x ⊕ x = 0 (technically speaking, the nonnegative integers under ⊕ form an Abelian group of exponent 2).
Let x 1 , … , x n be the sizes of the heaps before a move, and y 1 , … , y n the corresponding sizes after a move. Let s = x 1 ⊕ ⋯ ⊕ x n and t = y 1 ⊕ ⋯ ⊕ y n . If the move was in heap k , we have x i = y i for all i = k , and x k > y k . By the properties of ⊕ mentioned above, we have
t
=
0
⊕
t
=
s
⊕
s
⊕
t
=
s
⊕
(
x
1
⊕
⋯
⊕
x
n
)
⊕
(
y
1
⊕
⋯
⊕
y
n
)
=
s
⊕
(
x
1
⊕
y
1
)
⊕
⋯
⊕
(
x
n
⊕
y
n
)
=
s
⊕
0
⊕
⋯
⊕
0
⊕
(
x
k
⊕
y
k
)
⊕
0
⊕
⋯
⊕
0
=
s
⊕
x
k
⊕
y
k
(*) t = s ⊕ x k ⊕ y k .
The theorem follows by induction on the length of the game from these two lemmas.
Lemma 1 . If s = 0 , then t = 0 no matter what move is made.
Proof : If there is no possible move, then the lemma is vacuously true (and the first player loses the normal play game by definition). Otherwise, any move in heap k will produce t = x k ⊕ y k form (*). This number is nonzero, since x k = y k .
Lemma 2 . If s = 0 , it is possible to make a move so that t = 0 .
Proof : Let d be the position of the leftmost (most significant) nonzero bit in the binary representation of s , and choose k such that the d -th bit of x k is also nonzero. (Such a k must exist, since otherwise the d -th bit of s would be 0 .) Then letting y k = s ⊕ x k , we claim that y k < x k : all bits to the left of d are the same in x k and y k , bit d decreases from 1 to 0 (decreasing the value by 2 d ), and any change in the remaining bits will amount to at most s d − 1 . The first player can thus make a move by taking x k − y k objects from heap k , then, by (*)
t
=
s
⊕
x
k
⊕
y
k
=
s
⊕
x
k
⊕
(
s
⊕
x
k
)
=
0
.
So, based on the winning formula, we only need list of combinations of (
a
,
b
,
c
) which makes
S
=
0
, where
S
=
1
0
⊕
1
0
⊕
a
⊕
b
⊕
c
=
a
⊕
b
⊕
c
. To make every combinations have such property, we could make a simple list based on
a
's value,
for
a
=
1
, (
b
,
c
) would be permutation of (
2
,
3
), (
4
,
5
), (
6
,
7
), and (
8
,
9
),
for
a
=
2
, (
b
,
c
) would be permutation of (
1
,
3
), (
4
,
6
), (
5
,
7
), and (
8
,
1
0
),
for
a
=
3
, (
b
,
c
) would be permutation of (
1
,
2
), (
4
,
7
), (
5
,
6
), and (
9
,
1
0
),
for
a
=
4
, (
b
,
c
) would be permutation of (
1
,
5
), (
2
,
6
), and (
3
,
7
),
for
a
=
5
, (
b
,
c
) would be permutation of (
1
,
4
), (
2
,
7
), and (
3
,
6
),
for
a
=
6
, (
b
,
c
) would be permutation of (
1
,
7
), (
2
,
4
), and (
3
,
5
),
for
a
=
7
, (
b
,
c
) would be permutation of (
1
,
6
), (
2
,
5
), and (
3
,
4
),
for
a
=
8
, (
b
,
c
) would be permutation of (
1
,
9
) and (
2
,
1
0
),
for
a
=
9
, (
b
,
c
) would be permutation of (
1
,
8
) and (
3
,
1
0
),
for
a
=
1
0
, (
b
,
c
) would be permutation of (
2
,
8
) and (
3
,
9
).
Therefore, there would be
4
∗
3
∗
2
+
3
∗
4
∗
2
+
2
∗
3
∗
2
=
6
0
ways for the player that moves second to have foolproof winning strategy, which equivalent to
1
0
0
0
−
6
0
=
9
4
0
order of triples (
a
,
b
,
c
) that makes the first player wins.
The main idea of this problem is that winning strategies in Same Nim correspond to winning strategies in regular Nim as long as the starting position has at least one pair of piles with the same number of stones.
In fact, we can prove this: Suppose ( a 1 , a 2 , . . . , a n ) is a position in regular Nim. Then ( b , b , a 1 , a 2 , . . . , a n ) is a losing position in Same-Nim if ( a 1 , a 2 , . . . , a n ) is losing. The analogous result is true if ( a 1 , a 2 , . . . , a n ) is winning. In other words, we can predict the result of a game of Same-Nim which begins with a pair of piles which contain the same number of stones by removing that pair of piles and looking at the resulting position in a game of regular Nim.
Proof: We treat the set of piles as two sets: pile A = ( a 1 , a 2 , . . . , a n ) and pile B = ( b , b ) . Then the entire set (the position) is A ∪ B .
Suppose that A is a losing position in regular Nim. It is clear that B is a losing position in regular Nim, and so if the second player develops a winning strategy for each of the two positions separately, he can win by playing according to the winning strategy for the position that the first player played in. For example, if the first player plays some move in position A , A is transformed into a winning position (by the definition of a losing position) and then the second player has a winning move in A , which he plays.
The added condition of Same-Nim does not change this game at all. The winning strategy for the second player in position B is to ensure that the two piles have the same number of stones after his move, and so any move is possible in position A at any point in the game if the second player plays optimally (since there will be at least one pair of piles which have the same number of stones, namely the two in position B ).
Very similarly, we can show that if A is a winning position in regular Nim, then A ∪ B is a winning position in Same-Nim. Essentially, since A is winning and A ∪ B has a pair of piles which have the same number (the two piles in B ), there is some move which transforms A into a losing position with the second player acting as the first player, and so the second player loses, which means that A ∪ B is a winning position. This is precisely what we wanted to show. □
We now apply this to the given games, namely those with starting position ( 1 0 , 1 0 , a , b , c ) where 1 0 ≥ a , b , c ≥ 0 . We showed above that a game of Same-Nim with a starting position of the form ( 1 0 , 1 0 , a , b , c ) is losing if and only if ( a , b , c ) is losing in regular Nim (replace b with 1 0 above). We can very simply calculate the number of losing positions in regular Nim with this form, using nim-sums, a simple computer program, or even brute-force, and we get that there are 6 0 such losing positions. Since there are 1 0 0 0 total starting positions, and any of these 6 0 losing positions in regular Nim is losing in Same-Nim, there must be 1 0 0 0 − 6 0 = 9 4 0 starting positions in Same-Nim which satisfy the conditions of the problem and are winning.
This title is appropriate, as "Same-Nim" is just the same as standard 3-pile Nim on the three piles a , b , c .
More specifically, if a position is L (i.e. loses for the current player) in standard 3-pile, then it is also L in Same-Nim, so long as the first two piles maintain equal sizes; and similarly for W positions.
This is because if the first two piles have equal sizes then there are no restrictions on moves in the other 3 piles, so the player who would win the standard 3-pile Nim can execute his strategy without restriction; and if the losing player takes stones from one of the first two piles, the winning player takes the same number of stones from the other one of the first two piles, restoring his ability to continue his winning strategy on the last 3 piles.
We have looked at standard Nim in a Calvin vs Lino problem several weeks ago, and it turned out that a position is L if and only if it has a "Nim-sum" of 0 , where the Nim-sum is the binary XOR of the sizes of the piles.
Actually this is easy to prove: If the Nim-sum is 0 then any move must toggle at least one bit leaving a non-zero Nim-sum. And if the Nim-sum is nonzero then the following move will make it 0 : select a pile that has a 1 -bit in the same position as the most significant bit of the Nim-sum, and remove the number of stones that is the XOR of that pile's size, and the Nim-sum.
Finally we just have to count how many positions have a Nim-sum of 0 and subtract that from 1 0 0 0 .
I actually did this by counting positions with a ≤ b ≤ c by inspection and then considering the number of combinations of each. The losing positions are:
(1,2,3) (1,4,5) (1,6,7) (1,8,9) (2,4,6) (2,5,7) (2,8,10) (3,4,7) (3,5,6) (3,9,10)
and each one has six possible orderings for a total of 6 0 losing positions. So there are 9 4 0 winning positions.
Well, it's not exactly the same as Nim. Yes, a Same-Nim board is in a winning position in Same-Nim precisely when it is a winning position in Nim, but there are winning moves available in Nim that are not available in Same-Nim. For example, a player could have the Same-Nim board ( 5 , 5 , 4 , 6 , 7 ) and make the winning move ( 0 , 5 , 4 , 6 , 7 ) in Nim, but not in Same-Nim.
Problem Loading...
Note Loading...
Set Loading...
If a Same-Nim board position G has Nim-score N ( G ) = 0 , then two of the five piles are equal, and hence the Nim-sum of the sizes of the other three piles must be equal to N ( G ) , and is therefore nonzero. Thus there is a standard Nim move on those three piles which gives them a Nim-score of 0 ; since this move does not affect the two equal piles, this is a legal Same-Nim move, and the Nim-score of the Same-Nim board is now 0 .
On the other hand, if G is a Same-Nim board position with Nim-Score N ( G ) = 0 , then any possible legal Nim move, and so certainly any legal Same-Nim move, will result in a Same-Nim board position with nonzero Nim-score.
Thus the additional requirement of Same-Nim is largely unimportant, since the opening positions that are winning ones for the first player are those with nonzero Nim-score, and the losing positions are those with Nim-score zero. The Nim-score of the board position ( 1 0 , 1 0 , a , b , c ) is the Nim-sum a ⊕ b ⊕ c . Thus losing positions for the first player are those for which c = a ⊕ b . The following table for a ⊕ b : 1 2 3 4 5 6 7 8 9 1 0 1 0 3 2 5 4 7 6 9 8 1 1 2 3 0 1 6 7 4 5 1 0 1 1 8 3 2 1 0 7 6 5 4 1 1 1 0 9 4 5 6 7 0 1 2 3 1 2 1 3 1 4 5 4 7 6 1 0 3 2 1 3 1 2 1 5 6 7 4 5 2 3 0 1 1 4 1 5 1 2 7 6 5 4 3 2 1 0 1 5 1 4 1 3 8 9 1 0 1 1 1 2 1 3 1 5 1 5 0 1 2 9 8 1 1 1 0 1 3 1 2 1 4 1 4 1 0 3 1 0 1 1 8 9 1 4 1 5 1 2 1 3 2 3 0 shows that there are 6 0 triples ( a , b , c ) with 1 ≤ a , b , c ≤ 1 0 and c = a ⊕ b . Thus there are 9 4 0 winning opening positions for the first player.