/the-coin-game

A CS problem solved purely for fun.

Primary LanguageJavaScript

Alice and Bob are playing a game. They start with the pile of N < 10000 coins. Alice and Bob take turns. In each turn, the player takes some positive number of coins away from the pile. Player can take only square number of coins, i.e. 1, 4, 9, 16, 25, etc.

For example, Alice starting his turn with 100 coins can reduce the pile to the size of 99, 96, 91, 84, ... , 0 coins, but not to 97, 98 or 1 coin. The player, who cannot make a next turn (because the pile is empty) loses the game.

The first turn is taken by Alice.

Who will win if both players play as good as possible?