# The Game of Nim

A position in Nim consists of some piles of coins. Two players alternate, with each move removing a portion of one pile. The winner is the player who takes the last coin.

Suppose that the starting piles have size $n_1,...,n_k$. Prove that Player 2 has a winning startegy if and only if for every $j$, an even number of $n_1,...,n_k$ have a $1$ in position $j$ in their binary representation. For example, when the sizes are $1,2,3$, the binary representation are $1, 10, 11,$ and the condition holds.

-
Have you even read the Wikipedia article on Nim?! –  kahen Jul 18 '11 at 10:23

This is a well known result. Surely you can google up something, or failing that, go to a math library and read a solution from "Winning Ways I-II" by Berlekamp, Conway and Guy.

But I'm glad to hear that you want to work it out yourself. Here are a couple of hints. Call a position in the game of Nim balanced, if the sequence of numbers of remaining coins in the piles satisfies the condition "even number of 1s in any position", and call it unbalanced otherwise.

1) Show that if a player is given a balanced position, then any move s/he will make leaves an unbalanced position.

2) Show that if we are given an unbalanced position, there exists a move (at least one, possibly more) that will leave the other player with a balanced position.

3) Note that the desired all-zeros end position is balanced. Apply a little bit of recursive thinking (or induction, if you like).

-
"glad to hear..." -? It sounds like he wants us to work it out! –  The Chaz 2.0 Jul 18 '11 at 13:17
@The Chaz: Given that the OP didn't just use a Wikipedia article or some such, my inner optimist wants to hang on to a positive world view. The role of the teacher is to inspire! </tongue-in-cheek> –  Jyrki Lahtonen Jul 18 '11 at 13:24
My browser didn't complie the tongue in cheek! Regardless, I appreciate your optimism –  The Chaz 2.0 Jul 18 '11 at 16:11
Sorry if it came off as me asking for the answer. It sort of was. I was stuck on a problem and you pointed me in the right direction, I'm thankful for that. –  rapidash Jul 21 '11 at 22:05