Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Shell Game by Orthomonalus
def shell_game(start_pos, swaps):
swap_map = {
1: {'A': 'B', 'B': 'A', 'C': 'C'}, # A ↔ B
2: {'A': 'A', 'B': 'C', 'C': 'B'}, # B ↔ C
3: {'A': 'C', 'B': 'B', 'C': 'A'} # A ↔ C
}
pos = start_pos
for swap in swaps:
pos = swap_map[swap][pos]
return pos
print("Example:")
print(shell_game("A", [1, 2, 3]))
# These "asserts" are used for self-checking
assert shell_game("A", [1, 2, 3]) == "A"
assert shell_game("C", [1, 2, 3, 3, 1, 1]) == "B"
assert shell_game("B", [3]) == "B"
assert shell_game("B", []) == "B"
print("The mission is done! Click 'Check Solution' to earn rewards!")
July 16, 2025
Comments: