Can You Win at “Rock, Paper, Scissors, Lizard, Spock?”
This Week's Fiddler
To calculate the scenarios that result in decisive victory, we multiply possible winners, possible elements chosen by the winner, losing element options for one of the losing players, and losing element options for the other losing player.
This makes scenarios out of in all.
Brute force check
import itertools
edges = {
"RS",
"RL",
"PR",
"PV",
"SP",
"SL",
"LP",
"LV",
"VR",
"VS",
}
wins = 0
for a, b, c in itertools.product("RPSLV", repeat=3):
wins += (
((a + b) in edges and (a + c) in edges)
or ((b + a) in edges and (b + c) in edges)
or ((c + a) in edges and (c + b) in edges)
)
print(wins)
Output:
60
Which matches the 60/125 result we got.
Answer: 48%
Extra Credit
We can make a recursive function which traverses all the directed edges.
Each edge represents one element that beats another. Letters stand for their respective element, except for V, which stands for Vulcan/Spock (S already stands for scissors) :)
edges = {
"RS",
"RL",
"PR",
"PV",
"SP",
"SL",
"LP",
"LV",
"VR",
"VS",
}
def find_paths(edges: set[str], last: str | None = None):
if not edges:
return [[]]
paths = []
for edge in edges:
if last and not edge.startswith(last):
continue
for path in find_paths(edges - {edge}, edge[-1]):
paths.append([edge, *path])
return paths
paths = sorted(
path[0][0] + "".join(node[1] for node in path)
for path in find_paths(edges)
)
print('\n'.join(paths))
print(len(paths))
Output:
... (truncated for brevity)
110
Full output (including all valid paths)
LPRLVRSPVSL
LPRLVSPVRSL
LPRSLVSPVRL
LPRSPVRLVSL
LPRSPVSLVRL
LPVRLVSPRSL
LPVRSLVSPRL
LPVRSPRLVSL
LPVSLVRSPRL
LPVSPRLVRSL
LPVSPRSLVRL
LVRLPRSPVSL
LVRLPVSPRSL
LVRSLPVSPRL
LVRSPRLPVSL
LVRSPVSLPRL
LVSLPRSPVRL
LVSLPVRSPRL
LVSPRLPVRSL
LVSPRSLPVRL
LVSPVRLPRSL
LVSPVRSLPRL
PRLPVRSLVSP
PRLPVSLVRSP
PRLVRSLPVSP
PRLVRSPVSLP
PRLVSLPVRSP
PRLVSPVRSLP
PRSLPVRLVSP
PRSLVRLPVSP
PRSLVSPVR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