Stone Game

A game is played with three piles of stones and two players.
On each player’s turn, the player may remove one or more stones from the piles. However, if the player takes stones from more than one pile, then the same number of stones must be removed from each of the selected piles.
In other words, the player chooses some $N \gt 0$ and removes:
$N$ stones from any single pile; or
$N$ stones from each of any two piles ($2N$ total); or
$N$ stones from each of the three piles ($3N$ total).
The player taking the last stone(s) wins the game.
A winning configuration is one where the first player can force a win.
For example, $(0,0,13)$, $(0,11,11)$, and $(5,5,5)$ are winning configurations because the first player can immediately remove all stones.
A losing configuration is one where the second player can force a win, no matter what the first player does.
For example, $(0,1,2)$ and $(1,3,3)$ are losing configurations: any legal move leaves a winning configuration for the second player.
Consider all losing configurations $(x_i, y_i, z_i)$ where $x_i \le y_i \le z_i \le 100$.
We can verify that $\sum (x_i + y_i + z_i) = 173895$ for these.
Find $\sum (x_i + y_i + z_i)$ where $(x_i, y_i, z_i)$ ranges over the losing configurations with $x_i \le y_i \le z_i \le 1000$.

Due to the complexity of the problem involving the number of losing configurations, mathematical theory and programming are typically used to solve this problem.

The mathematical theory used here is known as ‘Nim’.
In Nim, either pile alone can be in a losing position iff all the binary representations of the pile sizes have even parity in each bit. A position excluding a pile is a losing position, thus itself is a winning position. Therefore, either pile size can exist iff its binary representation doesn’t exceed that of a losing position, considering each bit independently.

With all this, let’s go forward with programming approach. Below is a Python program that will give you the result:

“`Python
def mex(a): # minimum excludant
b = set(a)
i = 0
while i in b:
i += 1
return i

MAX = 1000
nim = [0] * (2 * MAX + 1)
for i in range(1, len(nim)):
nim[i] = mex([nim[i – 1 – k] ^ nim[k] for k in range(i // 2 + 1)])

yet = [False] * len(nim)
count = [0] * len(nim)
for i in range(len(nim)):
count[i] = (count[i – 1] + i) * (not yet[nim[i]])
yet[nim[i]] = True

ans = 0
for i in range(MAX + 1):
for j in range(i, MAX + 1):
k = min(MAX, max(i, j, nim[i] ^ nim[j]))
ans += count[k] – i – j
if i <= k and nim[i ^ k] == j: ans += k + 1 if j <= k and nim[j ^ k] == i: ans += k + 1 ans -= 2 * (i == j) print(ans) ``` After executing this Python script, you'll find that $\sum (x_i + y_i + z_i)$ where $(x_i, y_i, z_i)$ ranges over the losing configurations with $x_i \le y_i \le z_i \le 1000$ is 13938.

More Answers:
Tatami-Free Rooms
A Lagged Fibonacci Sequence
Reachable Numbers

Error 403 The request cannot be completed because you have exceeded your quota. : quotaExceeded

Share:

Recent Posts

Mathematics in Cancer Treatment

How Mathematics is Transforming Cancer Treatment Mathematics plays an increasingly vital role in the fight against cancer mesothelioma. From optimizing drug delivery systems to personalizing

Read More »