From Max Weinreich, a phantasmal puzzle:
Twenty ghostbusters are on their annual camping retreat. Two of them, Abe and Betty, have discovered that another pair, Candace and Dan, are in fact ghosts posing as ghostbusters. Abe and Betty hatch a plan: When all 20 campers are sitting in a circle around the campfire, Abe will fire his proton pack at Candace, and Betty will simultaneously fire her proton pack at Dan, annihilating the ghosts. However, if two proton streams cross, it means the end of all life on Earth.
If the ghostbusters are arranged randomly around the fire, what are the chances that Abe and Betty will cross streams?
In [12]:
import itertools
from math import factorial
The only people that are relevant for this problem are the 2 ghostbusters and the 2 ghosts. There are only a few ways they can be arranged. The other 16 people can be arranged in any manner and it doesn't affect the solution.
Because the direction also doesn't matter, I'll just label each shooter/ghost pair as either X or Y.
In [38]:
people = 'XY' * 2
In [41]:
cross_count = 0
total_count = 0
# use set to remove redundant permutations
for perm in set(itertools.permutations(people)):
perm_str = ''.join(perm)
# If there is a sequence where a single person from a pair is
# between the other pair, streams must cross.
cross = 'XYX' in perm_str or 'YXY' in perm_str
if cross:
cross_count += 1
total_count += 1
print(perm_str, cross)
In [42]:
(cross_count / total_count) * 100
Out[42]: