Two players play a game with a single pile of coins. They alternate turns, and on each turn a player must remove exactly 1, 3 or 4 coins from the pile (never more than remain). The player who takes the last coin wins. Both play perfectly. For how many starting pile sizes from 1 to 2026 inclusive does the second player (the one who does not move first) win?
Enter an integer
Show solution
Call a pile size losing if the player to move loses. 0 is losing; n is winning iff one of n−1,n−3,n−4 is losing. Computing: 0 L, 1 W, 2 L, 3 W, 4 W, 5 W, 6 W, 7 L, 8 W, 9 L, ... The losing sizes are exactly n≡0 or 2(mod7): from such n every move lands on residues {6,4,3} or {1,6,5} (all winning), and from any other residue one move reaches 0 or 2 (from 1: take 1; from 3: take 1 or 3; from 4: take 4; from 5: take 3; from 6: take 4). Since 2026=7⋅289+3, there are 289 multiples of 7 and 290 numbers ≡2 (2,9,…,2025) in 1..2026: 289+290=579.