Sitemap

Dating Markov Chain

It starts with a puzzle

6 min readJun 30, 2025

--

Press enter or click to view image in full size

You and 3 others (B, C, D) sit in a circle. You start with a ball. Every second, the person with the ball can either:

- Pass it left,
- Pass it right, or
- Keep it (ending the game),
All with equal probability (1/3 each).
What is the probability that you (person A) end the game by keeping the ball?

Solution:

"""
Markov Chain graph representing the ball-passing game:
- Each node (A, B, C, D) represents a person.
- Arrows show the possible transitions each second.
- Edge labels indicate the transition probabilities (each 1/3).
- A self-loop means the person keeps the ball and ends the game.
"""import networkx as nx
import matplotlib.pyplot as plt
# Create directed graph
G = nx.DiGraph()
# Define states
states = ['A', 'B', 'C', 'D']
transitions = {
'A': [('A', 1/3), ('B', 1/3), ('C', 1/3)],
'B': [('A', 1/3), ('B', 1/3), ('D', 1/3)],
'C': [('A', 1/3), ('C', 1/3), ('D', 1/3)],
'D': [('B', 1/3), ('C', 1/3), ('D', 1/3)],
}
# Add edges with weights
for from_state, to_states in transitions.items():
for to_state, prob in to_states:
G.add_edge(from_state, to_state, weight=prob)
# Set layout
pos =…

--

--

No responses yet