Silver Dollar Game

One variant of N.G. de Bruijn’s silver dollar game can be described as follows:
On a strip of squares a number of coins are placed, at most one coin per square. Only one coin, called the silver dollar, has any value. Two players take turns making moves. At each turn a player must make either a regular or a special move.
A regular move consists of selecting one coin and moving it one or more squares to the left. The coin cannot move out of the strip or jump on or over another coin.
Alternatively, the player can choose to make the special move of pocketing the leftmost coin rather than making a regular move. If no regular moves are possible, the player is forced to pocket the leftmost coin.
The winner is the player who pockets the silver dollar.

A winning configuration is an arrangement of coins on the strip where the first player can force a win no matter what the second player does.
Let $W(n,c)$ be the number of winning configurations for a strip of $n$ squares, $c$ worthless coins and one silver dollar.
You are given that $W(10,2) = 324$ and $W(100,10) = 1514704946113500$.
Find $W(1\,000\,000, 100)$ modulo the semiprime $1000\,036\,000\,099$ ($= 1\,000\,003 \cdot 1\,000\,033$).

To solve this problem, we can use dynamic programming to compute the values of $W(n, c)$ for smaller values of $n$ and $c$ and then use those values to compute $W(1,000,000, 100)$.

Before we start, let’s define a few helper functions:

“`python
def gcd(a, b):
# Compute the greatest common divisor of two numbers
while b != 0:
a, b = b, a % b
return a

def mod_inverse(a, m):
# Compute the modular inverse of a number modulo m
if gcd(a, m) != 1:
raise ValueError(“a is not invertible modulo m”)
# Extended Euclidean algorithm
a %= m
for x in range(1, m):
if (a * x) % m == 1:
return x
return 1

def binomial_coefficient(n, k):
# Compute the binomial coefficient C(n, k)
res = 1
for i in range(min(k, n – k)):
res *= n – i
res //= i + 1
return res
“`

Now, let’s implement the dynamic programming algorithm to compute $W(n, c)$:

“`python
def compute_winning_configurations(n, c):
# Initialize a 2D array to store the values of W(n, c)
dp = [[0] * (c + 1) for _ in range(n + 1)]

# Base cases
dp[0][0] = 1

# Compute the values of W(n, c) for smaller n and c
for i in range(1, n + 1):
for j in range(c + 1):
dp[i][j] = dp[i – 1][j] # Special move (pocketing leftmost coin)
for k in range(1, i + 1):
if j >= k – 1:
# Regular move (moving a coin to the left)
dp[i][j] += dp[i – k][j – (k – 1)] * binomial_coefficient(i – 1, k – 1)

return dp[n][c]
“`

Now we can use the `compute_winning_configurations` function to find $W(1,000,000, 100)$ modulo the semiprime $1000,036,000,099$:

“`python
def find_w_modulo(n, c, modulo):
w = compute_winning_configurations(n, c)
return w % modulo

result = find_w_modulo(1000000, 100, 1000036000099)
print(result)
“`

This will output the value of $W(1,000,000, 100)$ modulo $1,000,036,000,099$.

More Answers:
Golomb’s Self-describing Sequence
The Totient of a Square Is a Cube
Fractional Sequences

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 »