Skip to content

Instantly share code, notes, and snippets.

@nathan-osman
Last active April 5, 2020 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathan-osman/751d77fe57a9eb9bce2b73571fb53664 to your computer and use it in GitHub Desktop.
Save nathan-osman/751d77fe57a9eb9bce2b73571fb53664 to your computer and use it in GitHub Desktop.
Calculate the answer to this puzzle: https://i.stack.imgur.com/4MMS7.jpg
# Build a list of all possible combinations
a = []
for i in range(0, 10):
for j in range(0, 10):
for k in range(0, 10):
a.append('{}{}{}'.format(i, j, k))
# For each of the possible answers, check the five constraints
for v in a:
pass_1 = \
(v[0] == '6' and '8' not in v and '2' not in v) or \
(v[1] == '8' and '6' not in v and '2' not in v) or \
(v[2] == '2' and '6' not in v and '8' not in v)
pass_2 = \
((v[1] == '6' or v[2] == '6') and '1' not in v and '4' not in v) or \
((v[0] == '1' or v[2] == '1') and '6' not in v and '4' not in v) or \
((v[0] == '4' or v[1] == '4') and '6' not in v and '1' not in v)
pass_3 = \
((v[1] == '2' or v[2] == '2') and (v[0] == '0' or v[2] == '0') and '6' not in v) or \
((v[0] == '0' or v[2] == '0') and (v[0] == '6' or v[1] == '6') and '2' not in v) or \
((v[1] == '2' or v[2] == '2') and (v[0] == '6' or v[1] == '6') and '0' not in v)
pass_4 = '7' not in v and '3' not in v and '8' not in v
pass_5 = \
((v[1] == '3' or v[2] == '3') and '8' not in v and '0' not in v) or \
((v[0] == '8' or v[2] == '8') and '3' not in v and '0' not in v) or \
((v[0] == '0' or v[1] == '0') and '3' not in v and '8' not in v)
if pass_1 and pass_2 and pass_3 and pass_4 and pass_5:
print(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment