Checklist IOAI Indonesia 2025 OSN 2025 AI Exhibition – Final · P1 task
Monte Carlo Simulation
Indonesian title: Simulasi Monte Carlo
Estimate expectations of dice experiments with Monte Carlo simulation.
The task
The notebook explains Monte Carlo estimation with a worked example (expected number of die rolls until an even number appears, which equals 2).
Problem A (30 points): estimate the expected number of rolls needed for the running total to reach at least 12. Problem B (70 points): rolling until a 6 appears, and given that exactly 5 rolls were made (the last being 6), estimate the expected number of odd results.
Abridged and translated by SOTA from the official Indonesian materials. The official statement has the exact rules, and it wins wherever this summary differs.
In English
This task was published in Indonesian. SOTA translated it into English on 17 September 2026. Only the words changed in the notebooks: markdown, code comments, messages and printed output. The code, file names and paths are the original's, so a translated notebook runs with the original data.
Read the task notebook in English
Monte Carlo Simulation
Monte Carlo simulation is a computational method used to calculate the properties of a probabilistic event by repeating a random sampling process many times. A probabilistic problem may well be solvable analytically in closed form, but it can be very complex. Monte Carlo simulation then applies the concept of randomness to solve such problems approximately.
As an example, you are given the following problem:
A die has 6 faces with the values . Each face value has the same probability of appearing in a throw of the die (equally likely). A person then carries out a die-throwing experiment by throwing the die repeatedly until an even number appears. It is assumed that a throw of the die does not depend on the previous throws (independent). What is the expectation (mean, or expected value) of the number of die throws made until an even number finally appears?
The problem above can be solved analytically as follows:
First, we need to calculate the probability that an even number appears in a single throw of the die. This event is calculated as:
\begin{equation} P({2,4,6}) = P({2}) + P({4}) + P({6}) = \frac{3}{6} = 0{,}5 , . \end{equation}
Second, we define a random variable that represents "the number of die throws made until an even value appears (including the last throw, which shows the even value)". Let us also write (Genap = even). The value of the random variable is always positive:
\begin{equation} P(X=1) = p \ P(X=2) = (1-p) \times p \ P(X=3) = (1-p) \times (1-p) \times p = (1-p)^2 \times p \ \dots \ P(X=n) = (1-p) \times \dots \times (1-p) \times p = (1-p)^{n-1} \times p \end{equation}
Finally, the expectation, or expected value, of , denoted by , is calculated as:
\begin{align} \mathbf{E}[X] &= \sum_{i=1}^{\infty} i . P(X = i) \ &= \sum_{i=1}^{\infty} i . (1-p)^{i-1} . p \ &= \frac{1}{1-p} \end{align}
So the expected number of die throws until an even number appears for the first time is .
The problem above can also be solved approximately using Monte Carlo simulation. One experiment reproduces the activity of throwing the die repeatedly and stopping at the first throw that gives an even value. This experiment is repeated times, where usually has to be sufficiently large. After that, we calculate the mean number of die throws over all experiments. This process is reproduced by the following Python code:
import random
# the following is how to "roll" a die at random; with each
# face of the die having the same probability
# if you run this many times, the result will differ
mata_dadu = random.randint(1, 6)
print(mata_dadu)
# Monte Carlo simulation to answer:
# What is the expectation (mean, or expected value) of the number
# of die throws made until an even number finally appears?
N = 1000 # number of experiments
hasil = []
for _ in range(N):
# one experiment: throw the die repeatedly until an even number appears
mata_dadu = random.randint(1, 6)
outcomes = [mata_dadu]
while mata_dadu % 2:
mata_dadu = random.randint(1, 6)
outcomes.append(mata_dadu)
hasil.append(len(outcomes))
print(sum(hasil) / len(hasil)) # compute the mean
You will see that the result of the program fragment above is .
Problem A (30 points)
Write a Monte Carlo simulation program to answer the following question:
What is the expected number of die throws needed for the total of the face values obtained to be at least ?
In this problem, some example experiments are:
- , , , , throws with a total of
- , throws with a total of
# Write your program here
Problem B (70 points)
Write a Monte Carlo simulation program to answer the following question:
Suppose we carry out a die-throwing experiment and stop when a appears. Given that we made die throws (the last throw being a ), what is the expected number of odd numbers that appear?
# Write your program here
Translated by SOTA. The Indonesian original is the official version and wins wherever the two differ. Variable names in the code stay in Indonesian (mata_dadu = die face, hasil = results). The worked example in the original ends with E[X] = 1/(1-p); the usual result for this distribution is 1/p, which gives the same value, 2, for p = 0.5. The translation keeps the original formula. If you organise this olympiad and would like the translation removed, email [email protected] and we will take it down.
At a glance
- You submit
- Python code in the notebook producing the estimates.
- Format
- Final (on-site) of the AI Exhibition at OSN 2025, Universitas Muhammadiyah Malang, 6–10 October 2025: an essay paper and programming tasks in Google Colab.