Of ladybugs and clocks
written on January 25, 2026
While scrolling mindlessly, I came across a Grant Sanderson (3b1b) video with a short and sweet puzzle about a ladybug jumping around a clock. The puzzle is essentially this: imagine that a ladybug lands on an analog clock, specifically on the number 12 (so, top and center). Every second, the ladybug randomly moves to the number immediately to the left or right of the one she's currently on. For example, after one second, she would move either to the number 1 (clockwise) or 11 (counterclockwise), with each move being equally likely (50% chance). The ladybug stops after landing on each number at least once. Then, the question is: what is the probability that the last number the ladybug lands on is the number 6?
WARNING: Obviously, MAJOR spoilers ahead, for the puzzle itself and possible solutions or hints. I highly recommend you try this for yourself before reading ahead!
First ideas
As always, I started by trying to get an intuition for the problem by focusing on different parts
(and not just on the puzzle's actual question).
For instance, what is the probability that the ladybug visits the number 11 last?
Well, we know that the upper bound is at least as low as 50%,
since after the first second there is a 50% chance that the ladybug will move from 12 to 11
(in which case, obviously, 11 will not be the last number).
But that can't be the end of the story:
for instance, maybe the ladybug will go from 12, to 1, then back to 12, then to 11.
Since there is a 50% probability for each branch
taken,
we just multiply them together for the number of branches.
For the 12, 1, 12, 11
example, it would be \(0.5^4 = 0.0625\).
Taking that into account,
we can update the upper bound of the probability that the last number will be 11 to 43.75%,
but obviously there are still more scenarios we need to go through in order to reach the actual answer.
My next thought was something that—when I checked after solving the puzzle—a lot of people in the comments of the original video seemed to share:
for 6 to be the last number,
the ladybug would essentially need to go all the way down to 5 and once more to 7
(no matter the order of course, and she can move around the 5–7 range arbitrarily)
before hitting 6 from one side or the other.
Intuitively, this seems quite unlikely,
because the ladybug must simultaneously go down low
enough to hit 5 and 7,
but also she must mostly gravitate toward the top
(since she needs to go down
both sides without touching 6):
Then, I got to drawing.
Reduced version and graphs
Yet again, there are two strategies that always help me with problems: hacking on a reduced version of the original problem and drawing it out. For the first part, we can just dream up a clock having only numbers 1-4:
For the drawing part, we can use a Markov chain. Don't be alarmed if you're not familiar with the term—the graph itself is pretty intuitive: I'm simply going to mark the states of the clock (i.e., which numbers are visited and which number the ladybug is currently on) as the nodes and the probability of switching from one state to another as the edges. In the reduced example, let's say we start on number 1:
The graph above shows the possible states of the 4-number clock after the first move.
Numbers contained in each node have been discovered
by the ladybug:
for instance, in the first (leftmost) node,
the only number which has been discovered so far is 1
(because the ladybug starts by landing on it).
There is exactly one number in red per node,
and it symbolizes the number that the ladybug is currently sitting on.
Lastly, the edges between nodes mark the type of move:
c
for clockwise and cc
for counterclockwise.
Using the same logic,
we can continue drawing out the graph,
starting with the clockwise
branch:
Note that in the case where the ladybug moves clockwise and then counterclockwise, she lands again on the number 1. However, it's very important to note that these two states are not the same: in the first (leftmost) node, the ladybug has only discovered the number 1, while in the new node it has also discovered the number 2.
Let's finish drawing out the second level (depth 3):
We observe a sort of symmetry between the two initial branches (for example in terms of number of discovered numbers). Let's continue with the top and rightmost node for now:
From the aforementioned node, the ladybug can hit an end state by moving clockwise, symbolized by the double line around the node. The counterclockwise move yields a new, unseen state, where 1, 2 and 3 have been discovered but the ladybug is sitting on 2.
Let's keep going with the second node from the top, at depth 3 (i.e., the counterclockwise variant of the node we expanded from last):
And here comes our first loop. Indeed, if have discovered both 1 and 2, we can hop between them endlessly without creating new states. This, of course, is true for any two neighboring numbers.
Anyway, let's just draw out the rest of the graph until we exhaust all states:
Since we've now exhausted all possible states, as well as marked the end states,
we could assign \(\mathrm{c} = \mathrm{cc} = 0.5\) and go through manually computing the probability that the last discovered number is 3.
This becomes a little difficult to deal with once loops come into play.
For example, how do we deal with an edge going back
to a previously examined node?
We would sort of have to compute up to an iteration bound for loops,
and maybe reason about how the more iterations the ladybug goes through in a given loop the less likely that specific scenario is.
But, there is a much simpler way, which is revealed when we realize the following fact: we don't actually care about the loops! In fact, we only care about the end states themselves. No matter how many loops or what convoluted path the ladybug takes through this graph, she is bound to land on an end state. Suddenly, our probability computation becomes much simpler: We can find the number of end states where the last discovered number is 3 (2 states) and the total number of end states (6 states), and all we have to do is divide the one by the other: $$ P(\textrm{3 is the last number to be discovered}) = \frac{2}{6} = \frac{1}{3} $$
Generalizing to clocks of arbitrary sizes
Let's take a closer look at those end states (with the last discovered number being highlighted):
- 1 2 3 4
- 4 1 2 3
- 4 1 2 3
- 3 4 1 2
- 3 4 1 2
- 2 3 4 1
See it yet? Since the clock is, well, round, all end states are basically the same, modulo rotational symmetry. Furthermore, when written in this way, the last discovered number will always be either on the very left or very right!
Let's forget about the graph for a second. We can enumerate all possible end states trivially:
- 1 2 3 4
- 1 2 3 4
- 2 3 4 1
- 2 3 4 1
- 3 4 1 2
- 3 4 1 2
- 4 1 2 3
- 4 1 2 3
Now, let's remove impossible end states, basically everything where 1 is highlighted since it's discovered first (and thus can never be the last number):
1 2 3 4- 1 2 3 4
- 2 3 4 1
2 3 4 1- 3 4 1 2
- 3 4 1 2
- 4 1 2 3
- 4 1 2 3
Unsurprisingly, we discover the exact same end states from our graph!
To generalize, for a clock of size (i.e., number of numbers) \(N\),
we can enumerate all possible states in \(2N\) ways,
since there are \(N\) ways to write the sequence (or discover the numbers) and there are 2 possible end states for each of those.
We can strike out 2 of those end states as invalid,
as there will always be 2 end states with the last discovered number being the one which the ladybug first landed on.
That means we have \(2N - 2 = 2(N - 1)\) total end states.
For any given number
(except the number the ladybug first landed on, of course),
it will be at one end or the other
(i.e., at the very left or right)
in 2 end states total.
Therefore, the probability that a number \(x\) will be the last one to be discovered in a clock of size \(N\) (with \(x \leq N\) of course) is: $$ P(x, N) = \begin{cases} \frac{2}{2(N - 1)} = \frac{1}{N - 1} & \textrm{if} & x \lt N \\ 0 & \textrm{if} & x = N \end{cases} $$
Notice how the probability is actually the same for all numbers!
This was initially a bit counterintuitive to me:
in the original puzzle, 6 seems further away
from 12,
therefore surely the probability would be smaller than for, say, 3.
But actually, it makes perfect sense:
in order for any number to be the last one to be discovered,
the ladybug has to basically jump around it in both directions,
going almost fully around the clock but not quite.
This is equally likely for all numbers.
Also, as a sanity check, summing up the probabilities for all numbers does come up to 1
(with the probability of \(N\) being the last discovered number of course being 0):
$$
\sum_{i = 1}^{N} P(i, N) = \sum_{i = 1}^{N - 1} P(i, N) + P(N, N)
= (N - 1) \frac{1}{N - 1} + 0
= 1
$$
Checking via other examples and simulation
Alright, so how do we confirm? Let's first check with an even more trivial example, using a clock size of 3 (1 in the middle, 2 on the right, 3 on the left). In this case, we have a 50% chance of hitting 2 or 3 right out of the bat; we would expect the probability of, say, 2 being the last discovered number to be 50%: $$ P(2, 3) = \frac{1}{3 - 1} = \frac{1}{2} = 0.5 $$
Of course, the same is true for 3. Alright, let's write some code to simulate the ladybug's movements for a given clock size:
ladybug-clock-simulation.py
import random
CLOCK_SIZE = 12
TRIALS = 10_000
SELECTED = 6
def run_experiment(clock_size: int):
starting_position = clock_size
discovered = [starting_position]
current_position = starting_position
while len(discovered) < clock_size:
direction = random.choice([1, -1])
current_position = (current_position + direction) % clock_size
if current_position == 0:
current_position = clock_size
if current_position not in discovered:
discovered.append(current_position)
return discovered
runs = []
for i in range(TRIALS):
runs.append(run_experiment(CLOCK_SIZE))
selected = list(filter(lambda run: run[-1] == SELECTED, runs))
print(len(selected) / len(runs))
The run_experiment function performs one full run of the ladybug moving around the clock,
until all numbers are discovered
(ensuring we wrap around
when hitting either 0 or clock_size + 1).
The rest of the script just runs the experiment a number of times (set by TRIALS),
and finally, we print the number of times when a selected number was the last to be discovered over the total number of trials.
Running it for a clock size of 12 and selecting for 6 (just like in the original puzzle), we get this:
$ shell
$ python3 ladybug-clock-simulation.py 0.0906 $ python3 ladybug-clock-simulation.py 0.0927 $ python3 ladybug-clock-simulation.py 0.0933
Our formula predicts \(P(6, 12) = \frac{1}{11}\), which is about 0.090, so this seems right!
We can also confirm with the clock of size 4 we used for the graph, selecting the number 2.
For this to work with the script, our clock numbers are shifted around
so that 4 is at
the top and 2 is at the bottom, which does not change a thing for us:
$ shell
$ python3 ladybug-clock-simulation.py 0.33290906 $ python3 ladybug-clock-simulation.py 0.3311 $ python3 ladybug-clock-simulation.py 0.3295
Our formula predicts \(P(2, 4) = \frac{1}{3}\), which is about 0.333, so this again is right! Of course, these results stay the same regardless of the selected number, as our formula predicts.
This was a fun little puzzle to hack on!