# Disc Game Prize Fund

Editorial · 8 July 2026 · [Project Euler 121](https://projecteuler.net/problem=121)

## The prize and the probability of winning

The banker collects £1 on every play and pays the prize only on a win. If
the prize is $F$ pounds and the probability of winning is $p$, the expected
payout is $pF$ pounds. The banker's expected profit is therefore $1-pF$.
Requiring $1-pF\geq 0$ gives the largest whole-pound prize

$$
F_{\max}=\left\lfloor\frac{1}{p}\right\rfloor.
$$

In $n$ draws, a player who sees blue $k$ times sees red $n-k$ times.
Winning requires $k>n-k$, so for 15 turns we need the probability of
drawing at least eight blues.

## Count the blues after each turn

Returning the disc makes the bag on the next turn predictable. Whatever the
previous colours were, on turn $i$ the bag holds one blue disc and $i$ red
discs. To decide whether the player has won, the only part of the history
we need to keep is the number of blues drawn so far.

Let $A_i(k)$ be the probability of exactly $k$ blues after $i$ turns.
A red disc on the last turn leaves the count at $k$, so it contributes
$A_{i-1}(k)\,i/(i+1)$. A blue disc brings the count up from $k-1$ and
contributes $A_{i-1}(k-1)/(i+1)$. Every history ending with $k$ blues
falls into exactly one of these cases. Adding them gives

$$
A_i(k)=\frac{i A_{i-1}(k)+A_{i-1}(k-1)}{i+1}.
$$

Initially $A_0(0)=1$. A count outside $0\leq k\leq i$ has probability
zero, which also covers the boundary cases of the recurrence.

To take the floor of $1/p$ exactly, keep the numerators as integers. Every
history through turn $i$ has the same denominator
$D_i=2\cdot3\cdots(i+1)=(i+1)!$, with $D_0=1$. Set
$W_i(k)=D_iA_i(k)$. Since $D_i=(i+1)D_{i-1}$, the recurrence becomes

$$
W_i(k)=iW_{i-1}(k)+W_{i-1}(k-1),\qquad W_0(0)=1.
$$

## Four turns by hand

With four draws the player needs at least three blues. Four blues have
weight $1$. If there is exactly one red, its turn determines the weight,
since red on turn $j$ contributes a factor of $j$ and every blue contributes
a factor of $1$. The winning weight is therefore $1+(1+2+3+4)=11$.
The denominator is $5!=120$, so the maximum prize is
$\lfloor 120/11\rfloor=10$ pounds. A winner keeps £9 after accounting for
the stake.

For 15 turns the recurrence gives $\sum_{k=8}^{15}W_{15}(k)=9\,219\,406\,943$.
The denominator is $16!=20\,922\,789\,888\,000$, so the largest prize is
**£2,269**.

## Time and space

The table has one row per turn and one column per possible blue count.
Filling it takes $O(n^2)$ arithmetic operations and $O(n^2)$ storage for
$n$ turns. Through turn 15 every row sums to at most $16!$, so all the
weights and the final denominator fit in an `unsigned long long`.

## C++ implementation

```cpp
#include <array>
#include <iostream>

int main() {
  constexpr unsigned turns = 15;
  std::array<std::array<unsigned long long, turns + 1>, turns + 1> weights{};
  weights[0][0] = 1;
  unsigned long long denominator = 1;

  for (unsigned turn = 1; turn <= turns; ++turn) {
    denominator *= turn + 1;
    for (unsigned blues = 0; blues <= turn; ++blues) {
      weights[turn][blues] = turn * weights[turn - 1][blues];
      if (blues > 0) {
        weights[turn][blues] += weights[turn - 1][blues - 1];
      }
    }
  }

  unsigned long long winning_weight = 0;
  for (unsigned blues = turns / 2 + 1; blues <= turns; ++blues) {
    winning_weight += weights[turns][blues];
  }
  std::cout << denominator / winning_weight << '\n';
}
```

[Problem](https://xyzmaths.org/pow/disc-game-prize-fund/index.md) · [Solution](https://xyzmaths.org/pow/disc-game-prize-fund/solution/index.md)
