# Empty one pile of balls and win

There are two piles of balls. One contains $5$ balls and the other contains $18$ balls.

$A$ and $B$ are playing the following game: In each round, a player has to move balls from the larger pile to the smaller pile such that the number moved was a non-zero multiple of how many were previously in the smaller pile. $A$ starts, and $A$ and $B$ alternate until a pile of balls is empty. The person who emptied it is the winner.

Who will win this game?

• To clarify: the first turn would consist of A moving either 5, 10 or 15 balls from the pile of 18 to the pile of 5. Let's say he chose 15. There would now be 20 balls in one pile and 3 balls in the other. Player B would then have to move 3,6,9,12,15, or 18 back to the other pile. Do I have that right? – Kevin Feb 23 '16 at 13:46
• If I got the calculations right, you will get the longest game if the initial distribution of the balls was 8 and 15. And who wins depends on whether the ratio between the sizes of the piles is more or less than 2. – kasperd Feb 23 '16 at 17:12

A wins.

A moves 5 balls over, which leaves piles of 10-13.

The only legal move for B is moving 10, leaving 20-3.

A responds by moving 9, leaving 11-12.

The only legal move for B is moving 11, leaving 22-1.

A moves all 22 balls, leaving 0-23.

The total number of balls always remains 23, a prime number, meaning:

1. Being left with only 1 ball in the smaller pile is the only way to immediately win.

2. Scenario 1 can only be forced on the loser right away if he/she's left with 11 balls in the smaller one and 12 in the bigger one.

3. 2's condition can be forced on the loser right away only if (s)he leaves 2, 3, 4 or 6 (factors of 12 save 1 and itself) balls in the small pile, leading to a 12-ball pile.

4. The loser can be forced to leave a 3-ball pile if left with a 10-ball one, which can be done in the very first move by A.