I was sitting in an airport, waiting to board a flight. I figured I’d use the time to write a computer simulation to solve the Ladybug on the Clock question.
Imagine a standard clock. A ladybug flies in and lands on the “12”. At each second, the ladybug randomly moves forward one number, or backwards one number. She continues doing this until she hits all 12 numbers. What is the probability that the last number she lands on is the “6”?
As it turns out, the counterintuitive answer is that all 11 numbers (1 through 11 — the 12 doesn’t count because the ladybug starts there) are equally likely to be the last number landed on. The probability of all 11 numbers is 1 / 11 = 0.0909.
The simulation was a bit trickier than I expected, but even so, it only took me about 20 minutes to code up a simulation, because I have written simulations like this many times over the past 50 years (starting with my school days at U.C. Irvine when I wrote a craps dice game simulation).
I ran the simulation 100,000 trials. The output:
Begin ladybug-clock simulation Setting n_trials = 100000 Done Last number landed frequencies: 1 0.0906 2 0.0910 3 0.0901 4 0.0897 5 0.0910 6 0.0913 7 0.0922 8 0.0911 9 0.0915 10 0.0910 11 0.0905
I could have gotten more accurate results by running the simulation longer.
Good fun sitting in an airport.
Demo program:
# ladybug_clock.py
#
# A ladybug starts on the "12" of a clock.
# Each second she randomly moves forward one number,
# or back one number.
# What is the prob that the last number she
# touches is the "6"?
import numpy as np
print("\nBegin ladybug-clock simulation ")
counts = np.zeros(13, dtype=np.int64)
rnd = np.random.RandomState(0)
n_trials = 100000
print("Setting n_trials = " + str(n_trials))
for trial in range(n_trials):
positions = np.zeros(13, dtype=np.int64)
spot = 12
positions[12] = 1
while np.sum(positions) != 11:
flip = rnd.randint(low=0, high=2) # 0 or 1
if flip == 0: # go backward
if spot == 1: spot = 12
else: spot -= 1
elif flip == 1: # go forward
if spot == 12: spot = 1
else: spot += 1
positions[spot] = 1
# find the missing spot
for i in range(1,13):
if positions[i] == 0:
# print("last landed = " + str(i))
counts[i] += 1
print("Done ")
print("\nLast number landed frequencies: \n")
for i in range(1,12):
print("%4d %0.4f" % (i, (counts[i] / n_trials)))


.NET Test Automation Recipes
Software Testing
SciPy Programming Succinctly
Keras Succinctly
R Programming
2026 Visual Studio Live
2025 Summer MLADS Conference
2026 DevIntersection Conference
2025 Machine Learning Week
2025 Ai4 Conference
2026 G2E Conference
2026 iSC West Conference
You must be logged in to post a comment.