Skip to content

Instantly share code, notes, and snippets.

@albal
Created January 19, 2021 18:25
Show Gist options
  • Select an option

  • Save albal/ca3ea955c94b4078c9d768b3bbb97cd4 to your computer and use it in GitHub Desktop.

Select an option

Save albal/ca3ea955c94b4078c9d768b3bbb97cd4 to your computer and use it in GitHub Desktop.
Make a third from the numbers 1 - 9
# You have the numbers 1 - 9, arrange them to make a third
from itertools import permutations
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
top = permutations(nums, 4)
bottom = permutations(nums, 5)
top_vals = list(top)
bottom_vals = list(bottom)
count = 0
for i in top_vals:
top_no = int(''.join([str(x) for x in i]))
for j in bottom_vals:
bottom_no = int(''.join([str(x) for x in j]))
if top_no * 3 == bottom_no:
for n in str(top_no):
if n not in str(bottom_no):
count += 1
print("Found", top_no, "/", bottom_no, "=", top_no / bottom_no)
print("Values found", count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment