NIM


Rules:

Normally there are 3 or 4 stacks of coins, with a random number of coins in each stack. Each player takes turns removing coins from a stack. You can remove as many coins as you want, but only from one stack. The person who removes the very last coin wins.

Note: You must be familiar with boolean algebra before attempting to read this (See! You should have stayed awake in math class that day!).


Strategy:

Step I: Exor (EXCLUSIVE-OR) all the stacks together.

If the ANSWER is zero, there is nothing you can do and you are at your opponent's mercy. In this case, remove only one coin from the tallest stack to delay the game; the longer the game is, the better chance your opponent has time to screw up!

If the answer is NOT zero, then...

Step II: Take the ANSWER and exor it with the tallest pile. The NEW answer will tell you what number that stack has to be reduced down to. If that doesn't work, try the 2nd tallest stack, the 3rd, etc.

What you are really trying to do is to always leave your opponent with a losing combination. In other words, make sure that AFTER your turn is over, the exor of all the stacks is ZERO.


Example #1:

It is your move, and there are three stacks:

[1] [2] [7]

Exor the three stacks together:

1 exor 2 exor 7 = 4

Exor the answer (4) with the largest stack (7):

4 exor 7 = 3

Reduce the stack of 7 down to 3 by merely removing 4 coins from it. The three stacks are now:

[1] [2] [3]

...leaving your opponent with a losing combination. Why? Because (1 exor 2 exor 3) = 0, and as long as your opponent is faced with a total EXOR of ZERO, he will continue to lose move after move.


Example #2:

It is you move, and there are four stacks:

[3] [4] [8] [8]

Exor the four stacks together:

3 exor 4 xor 8 exor 8 = 7

Exor the answer (7) with the tallest stack (8):

7 exor 8 = 15

You simply cannot reduce ANY stack of 8 down to 15... it's just impossible. Because the two tallest stacks won't work out, try the next tallest (the one with with 4 coins in it):

7 exor 4 = 3

This will work, as you can easily reduce a stack of 4 down to 3 by merely removing one coin away from it, leaving your opponent with:

[3] [3] [8] [8]

...another losing combination! (As 3 exor 3 exor 8 exor 8 = 0.)


Example #3

It's your move, and there are three stacks:

[3] [5] [6]

Exor the three stacks togerther:

3 exor 5 exor 6 = 0

Now the answer is zero on YOUR side, and there is nothing you can do except hope that your opponent screws up. To delay the game, remove only a single coin from the tallest stack:

[3] [5] [5]

You are still leaving your opponent with a winning combination, but by slowing down the game, you'll increase the odds that he might make a bad move later on in the game.



Return to the MATHEMATICA PAGE
Hosted by www.Geocities.ws

1