Fibonacci nim is a mathematical subtraction game, a variant of the game of nim. Players alternate removing coins from a pile, on each move taking at most twice as many coins as the previous move, and winning by taking the last coin. The Fibonacci numbers feature heavily in its analysis; in particular, the first player can win if and only if the starting number of coins is not a Fibonacci number. A complete strategy is known for best play in games with a single pile of counters, but not for variants of the game with multiple piles.
Fibonacci nim is played by two players, who alternate removing coins or other counters from a pile. On the first move, a player is not allowed to take all of the coins, and on each subsequent move, the number of coins removed can be any number that is at most twice the previous move. According to the normal play convention, the player who takes the last coin wins.
The game was first described by Michael J. Whinihan in 1963, crediting its invention to Oregon State University mathematician Robert E. Gaskell. It is called Fibonacci nim because the Fibonacci numbers feature heavily in its analysis.
This game should be distinguished from a different game, also called Fibonacci nim, in which players may remove any Fibonacci number of coins on each move.
The strategy for best play in Fibonacci nim involves thinking of the current number of coins as a sum of Fibonacci numbers. There are many ways of representing numbers as sums of Fibonacci numbers, but only one representation that uses each Fibonacci number at most once, and avoids consecutive pairs of Fibonacci numbers; this unique representation is known as its Zeckendorf representation. For instance, the Zeckendorf representation of 10 is 8 + 2; although 10 can also be represented as sums of Fibonacci numbers in other ways, such as 5 + 5 or 5 + 3 + 2, those other ways do not meet the condition of only using each Fibonacci number once and avoiding consecutive pairs of Fibonacci numbers such as the pairs 2, 3 and 3, 5. The Zeckendorf representation of any number may be found by a greedy algorithm that repeatedly subtracts the largest Fibonacci number possible, until reaching zero.
The game strategy also involves a number called the "quota", which may be denoted as . This is the maximum number of coins that can currently be removed. On the first move, all but one coin can be removed, so if the number of coins is then the quota is . On subsequent moves, the quota is two times the previous move.
Based on these definitions, the player who is about to move can win whenever is greater than or equal to the smallest Fibonacci number in the Zeckendorf representation, and will lose (with best play from the opponent) otherwise. In a winning position, it is always a winning move to remove all the coins (if this is allowed) or otherwise to remove a number of coins equal to the smallest Fibonacci number in the Zeckendorf representation. When this is possible, the opposing player will necessarily be faced with a losing position, because the new quota will be smaller than the smallest Fibonacci number in the Zeckendorf representation of the remaining number of coins. Other winning moves may also be possible. However, from a losing position, all moves will lead to winning positions.
The Zeckendorf representation of a Fibonacci number consists of that one number. So when the starting pile has a Fibonacci number of coins, the smallest Fibonacci number in the Zeckendorf representation is just, larger than the starting quota . Therefore, a Fibonacci number as the starting pile is losing for the first player and winning for the second player. However, any non-Fibonacci starting number of coins has smaller Fibonacci numbers in its Zeckendorf representation. These numbers are not larger than the starting quota, so whenever the starting number of coins is not a Fibonacci number, the first player can always win.
For example, suppose that there are initially 10 coins.[1]
Fibonacci nim is an impartial game in that the moves that are available from any position do not depend on the identity of the player who is about to move.Therefore, the Sprague–Grundy theorem can be used to analyze an extension of the game in which there are multiple piles of coins, and each move removes coins from only one pile (at most twice as many as the previous move from the same pile). For this extension, it is necessary to compute the nim-value of each pile; the value of the multi-pile game is the nim-sum of these nim-values. However, a complete description of these values is not known.
A different multiple-pile variant of the game that has also been studied limits the number of stones in each move to twice the number from the previous move, regardless of whether that previous move was to the same pile.