User:Vel!/pu/infinite nim

In this page, we will explore the game of infinite nim.

Single-pile nim
Nim is a very simple game. In its simplest form, it involves a "pile" of "stones". Players take turns taking stones from the pile. Players must take at least one stone, and at most a certain number. The player who takes the last stone either loses or wins. Variants are categorized as (x,y), where x is the number of stones in the pile and y is the maximum number of stones a player may take.

Analysis of single-pile nim (5,2)
The smallest "interesting" version of nim is (5,2). Actually, it isn't really that interesting. But here is how the game goes: That was a mess. The game can 7 different ways, and can end in as few as 3 or as many as 5 turns. Player 1 has a winning strategy (assuming the person who takes the last stone wins). On the first turn, take 2, then on your second, you can always remove all the remaining stones.
 * Player 1 takes 1 stone, leaving 4
 * Player 2 takes 1 stone, leaving 3
 * Player 1 takes 1 stone, leaving 2
 * Player 2 takes 1 stone, leaving 1.
 * Player 2 takes 2 stones, leaving none. The game ends.
 * Player 1 takes 2 stones, leaving 1
 * Player 2 takes 1 stone, leaving none. The game ends.
 * Player 2 takes 2 stones, leaving 2
 * Player 1 takes 1 stone, leaving 1
 * Player 2 takes 1 stone, leaving none. The game ends.
 * Player 1 takes 2 stones, leaving none. The game ends.
 * Player 1 takes 2 stones, leaving 3
 * Player 2 takes 1 stone, leaving 2
 * Player 1 takes 1 stone, leaving 1
 * Player 2 takes 1 stone, leaving none. The game ends.
 * Player 1 takes 2 stones, leaving none. The game ends.
 * Player 2 takes 2 stones, leaving 1
 * Player 1 takes 1 stone, leaving none. The game ends.

The perfect strategy
To guarantee a win, try to keep the number of stones at x minus a multiple of y+1. This is because for any number of stones the opponent removes, you can always get it back to such a number. If your opponent causes the number of stones to be such a multiple, you will need to wait for an opportunity. If both players are playing perfectly, player 1 always wins if y is a multiple of x+1, and player 2 always wins otherwise.