1
$\begingroup$

There are 3 baskets each have N, N+1, N+2 balls. Two players take turns to take any number of balls from the any of the baskets. The player who takes the last ball wins. If both players play optimally, who (first-mover or second-mover) will win?

For example with boxes XYZ containing 1,2,3 balls respectively If A empties box X, B takes 1 ball from box Z leaving 2,2 forcing a win for B. If A takes 1 from box Y, B empties box Z forcing a win. If A empties box Y, B takes 2 from Z forcing a win. If A takes 1 from box Z, B empties box X forcing a win. If A takes 2 from box Z, B empties box Y forcing a win. If A empties box Z, B takes 1 from box Y forcing a win.

For 234: the first-mover draw 3 from 4 and convert it to 123. So the first-mover will win.

For 345: If move 4, to 3 B wins (take 5), to 2 B wins (take 5 to 1 and back to 123), to 1 B wins (take 5 to 2 and back to 123), to 0 B wins (take 5 to 3 and back to 033), hence the first-mover will not move 4. If move 5, to 4 B wins (take 3 to 0), to 3 B wins (take 4 to 0), to 2 B wins (take 4 to 1 back to 123), to 1 B wins (take 4 to 2 and back to 123), to 0 B wins (take 4 to 3), hence the first-mover will not move 5. If move 3, to 1 is a must-win strategy. So the first-mover will win.

For 456: move 6 to 1, then the first-mover will win.

So I guess that when N>1, it's always the first-mover win. But I don't know how to prove it.

$\endgroup$
2
  • 4
    $\begingroup$ Isn't this a special case of nim? $\endgroup$ Commented Oct 17 at 12:01
  • 1
    $\begingroup$ probably equally interesting perhaps is the n n+1 n+2 n+3 scenario where it seems n=odd wins and n=even loses $\endgroup$ Commented Oct 18 at 2:41

3 Answers 3

3
$\begingroup$

This is a classic game called

Nim

and a general strategy can be found on the linked page. The general case has also been asked here before:
Eat sweets and start your own business!

However, your question is specifically about the case with three piles, where their sizes are three consecutive numbers. In this case the strategy simplifies (and which you almost formulated in your question). It is a win for the first player, except for $N=1$ when the second player wins.

The strategy is:

Always leave either two equal baskets (and an empty one), or leave the three baskets $(1,2k,2k+1)$, i.e. a basket with 1 ball and two baskets with consecutive amounts where the largest is odd.
Whatever move the a player does when faced with such a position, the other player can recreate such a position. It is easy to show that those two types of position have nim-sum zero, so are winning moves.
If $N=1$ play already starts with such a position, namely $(1,2,3)$, and the first player loses. In all other cases the first player wins by leaving $(1,N+1,N+2)$ if $N$ is odd or $(N,N+1,1)$ if $N$ is even.

$\endgroup$
3
  • 1
    $\begingroup$ And for N=1 the strategy fails because you already start with a position matching (1,2k,2k+1). It is the only exception. $\endgroup$
    – Florian F
    Commented Oct 17 at 21:51
  • $\begingroup$ Yes for N=0 it's again OK $\endgroup$ Commented Oct 18 at 2:24
  • 1
    $\begingroup$ @FlorianF Excellent point. I have updated my answer. $\endgroup$ Commented Oct 18 at 6:49
0
$\begingroup$

The first player wins, by removing all but one ball from the basket with N+2 balls.

Strategy:

If the second player takes the single ball, remove one ball from the basket with N+1, leaving two baskets of N. If the second player removes the entire N+1 basket, take all but one ball from the basket with N, leaving two baskets of 1. Any other move in the N or N+1 basket can be copied to the other, which simply reduces the value of N. Since N is nonnegative, this can happen finitely many times. If N reaches 0, simply take the ball your opponent didn't, and win.

$\endgroup$
1
  • 3
    $\begingroup$ That is not quite right. Your strategy works if N is even, but if N is odd you want the first move to be from the basket with N balls, not from the basket with N+2 balls. For example, if N=3, you want to leave (1,4,5), not (3,4,1). $\endgroup$ Commented Oct 17 at 12:24
0
$\begingroup$

One basket:

The one leaving only one basket behind loses.

The one leaving $2$ baskets with $1$ ball each wins.

Two baskets:

The one leaving $2$ baskets with one having $1$ ball in it and the other more loses, because the player whose turn has come can just reduce the game to the second paragraph.

If a player wins when they leave $2$ baskets with $x$ and $y$ balls, then any combination of $x$ and $y+n$ or $x+n$ and $y$ loses, because the player whose turn has come can just reduce the latter to the former. Also, any combination of $x$ and $y-n$ or $x-n$ and $y$ loses.

If a player loses when they leave $2$ baskets with $x$ and $y$ balls, then there's at least one winning combination of $x$ and $y-n$ or $x-n$ and $y$.

$1,1$ is a win to the leaver.

$1,2$ is a loss.

$2,2$ doesn't directly lead to any winning combination for the first player to move, so it's a winning combination itself.

By extension, only $x,x$ combinations are winning ones for the one who left them behind.

Three baskets (no strategy):

So, if someone leaves behind $3$ baskets with $x,x,y$ ($y$ can be equal to $x$) balls, they lose because the other player can just reduce it to an $x,x$ game.

$1,1,1$ is a loss for the leaver. In fact, anything with only $1$s and $2$s is.

$1,2,3$ is the first win, making $1,2,x$, $1,3,x$, and $2,3,x$ ($x>3$) losses. Then $1,4,5$ doesn't directly lead to a winning game, so it's one.

The winning combos can be listed like this:

$1, 2, 3$
$1, 4, 5$
$2, 4, 6$ (max value as low as possible)
$3, 5, 6$
$1, 6, 7$
$2, 5, 7$
$3, 4, 7$
...

Every time the greatest value increases by $1$, it becomes clear that $1, X, X+1$ is a winning combination, so it rules out $X, X+1, X+2$ unless $X=1$, meaning Player 1 wins unless it's $1,2,3$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.