Dice Game #1— Who Wins First?
A Quant Interview Question — Are You Smarter Than an 8-Year-Old?
Dice Game #1— Who Wins First?
A Quant Interview Question — Are You Smarter Than an 8-Year-Old?

(Netica secretely installed)

This should be a fairly easy problem to model with a Bayesian Network
We will model this in three different ways.
Let’s first model a simple case, where players A and B each roll just once. What is the probability that A wins, B wins, or neither wins? Each will roll two fair dice (d1, d2) and (d3, d4), and their sums determine who wins.

The tost likely (72%) is that neither will win on the first roll.

But instead of rolling just once, they will keep rolling until someone wins. How do we do this? Watch:

We enter a NEGATIVE finding for ‘neither’ since they will reroll until someone eventually wins
More concisely (before and after):

Before and After we enter a NEGATIVE finding, meaning that they reroll until someone wins
I should say that I stumbled on this kind of solution quite by accident some time ago, by tinkering around with Bayesian Networks! But why does this work? I asked ChatGPT:
When you have a recursive or self-similar process, you can collapse the recursion by modeling a single round and then conditioning on termination. The game is a renewal process: after a
rerolloutcome, the game returns to exactly the same probabilistic state as before.
Let’s look at another way of modeling this.
This observation gives rise to another model:

https://openquant.co/questions/dice-game-1
There are 5 ways for player A to get a sum of 6, and 6 ways for player B to get a sum of 7. So player B seems to have an advantage, but Player A has the advantage of going first. Player A will win on condition that he takes fewer turns to reach his goal than Player B.

Notice that A wins IFF A ≤ B
Notice that we also have to include the possibility that A = B, since, for some given turn, each can get their desired sum, but A still wins by virtue of going first.
Note that the expected number of turns for player A is about 7.17 (36/5 = 7.2) and about 6 for player B.
THEIR SIMULATION WITH A PYTHON LOOP
import random
from typing import Callable
random.seed(42)
roll_dice: Callable[[None], int] = lambda: random.randrange(1, 7, 1)
def play_game() -> bool:
"""Returns a boolean indicating whether player A won"""
pa_turn = True
while True:
dice_roll_sum = roll_dice() + roll_dice()
if pa_turn and dice_roll_sum == 6:
return True
if not pa_turn and dice_roll_sum == 7:
return False
pa_turn = not pa_turn
iterations = 10_000
pa_win_prob = sum([play_game() for _ in range(iterations)]) / iterations
print(f"The probability of Player A winning is {pa_win_prob}")
With Netica, we can also run a brute-force simulation with 10,000 samples, generated from the net itself.

Past of the text file with 10000 cases below, for Sum_A, Sum_B, and who wins:

End of file for 10000 samples
Notice that because we generated 10000 random cases, the numbers are not entirely exact. We read back the file and just count the number of cases.

The raw (unnormalized) count gives the same final result
SOURCES & REFERENCES
메타데이터
- post_id
- cbdc7d48cc27
- slug
- dice-game-1-who-wins-first-cbdc7d48cc27
- url
- https://medium.com/@pbercker/dice-game-1-who-wins-first-cbdc7d48cc27
- canonical_url
- https://medium.com/@pbercker/dice-game-1-who-wins-first-cbdc7d48cc27
- author_url
- https://medium.com/@pbercker
- status
- ok
- fetched_at
- 2026-06-24 18:57:25