Skip to content

Instantly share code, notes, and snippets.

@kleutzinger
Created January 27, 2024 18:02
Show Gist options
  • Save kleutzinger/97416454095dcfe23dcc91b383bd9ba0 to your computer and use it in GitHub Desktop.
Save kleutzinger/97416454095dcfe23dcc91b383bd9ba0 to your computer and use it in GitHub Desktop.
"""
how many valid answers are there on this "Math Spinner?"
https://i.imgur.com/HYiaxUN.jpeg
"""
nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
operators = "+-*"
# find all valid
tot = 0
valid = 0
for left in nums:
for mid in nums:
for a in nums:
for b in nums:
for op in operators:
right = int(f"{a}{b}")
calc = f"{left}{op}{mid}=={right}"
if eval(calc):
print(calc)
valid += 1
tot += 1
print(f"Valid: {valid}")
print(f"Total: {tot}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment