A bug is placed at one corner of a wire frame in the shape of a cube. This cube currently does not have any sugar for the hungry bug.
The bug crawls along the 12 wires of the frame searching for something to eat. At each of the 8 corners the bug randomly chooses one of the 3 wires to follow next (including the one it just traveled).
The moment the bug crosses the first wire to the next corner, a piece of sugar is placed on the original starting corner. At some point, the bug will return to the starting corner and reach the sugar.
What is the probability that the bug will have visited all 8 corners by the time it returns to the starting corner?
I did a simulation and got the same results as Charlie; slightly over 1/8.
0.128622
0.128486
0.128259
0.128987
0.128823
average
----------------
import random
corner_choices = {'A':['AE','AB','AD'],
'B':['BF','BA','BC'],
'C':['CG','CD','CB'],
'D':['DH','DA','DC'],
'E':['EF','EH','EA'],
'F':['FE','FG','FB'],
'G':['GH','GF','GC'],
'H':['HE','HG','HD']}
all8corners = 0
reps = 1000000
for r in range(reps):
loc = random.choice('EBD') # start loop after first move
path = 'A'+loc
free = False
while not free:
oldloc = loc
options = corner_choices[oldloc]
wire = random.choice(options)
loc = wire[1]
if loc == 'A':
if len(set(path)) == 8:
all8corners += 1
free = True
else:
path += loc
print(all8corners/reps)
|
Posted by Larry
on 2023-12-05 12:38:45 |