Ant on a cube probability

An ant is on one face of a cube. At every step, the ant crawls to one of its four neighboring faces with equal probability.

What is the expected number of steps for it to reach the face opposite its starting face?


The answer is 6.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Fletcher Mattox
Aug 8, 2020

In lieu of an analytical solution, I'll offer

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import random
import numpy as np

d = dict()
d['N'] = ['S', 'W', 'U', 'D'] 
d['S'] = ['N', 'E', 'U', 'D'] 
d['E'] = ['S', 'W', 'U', 'D']
d['W'] = ['N', 'E', 'U', 'D'] 
d['U'] = ['N', 'S', 'E', 'W']
d['D'] = ['N', 'S', 'E', 'W'] 

steps = []
for i in range(10**6):
    pos = 'N'
    dst = 'E'
    step = 0
    while pos != dst:
        pos = random.choice(d[pos])
        step += 1
    steps.append(step)
print(np.mean(steps))

1
5.99812

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...