Skip to content

Instantly share code, notes, and snippets.

@fela
Last active January 5, 2022 22:46
Show Gist options
  • Save fela/1b38ec9a656d7f976e965efb0d243c64 to your computer and use it in GitHub Desktop.
Save fela/1b38ec9a656d7f976e965efb0d243c64 to your computer and use it in GitHub Desktop.
from collections import defaultdict
def all_pairs():
for n1 in range(2, 65):
for n2 in range(n1+1, 65+1):
yield n1, n2
def prod(pair):
n1, n2 = pair
return n1 * n2
def find_numbers():
sum_to_pairs = defaultdict(list)
prod_to_pairs = defaultdict(list)
for pair in all_pairs():
sum_to_pairs[sum(pair)].append(pair)
prod_to_pairs[prod(pair)].append(pair)
draco_cant_tell = set()
for pair in all_pairs():
num_options = len(prod_to_pairs[prod(pair)])
if num_options > 1:
draco_cant_tell.add(pair)
assert num_options >= 1
harry_can_tell_draco_cant_tell = set()
for pair in draco_cant_tell:
options = sum_to_pairs[sum(pair)]
if all(p in draco_cant_tell for p in options):
harry_can_tell_draco_cant_tell.add(pair)
draco_can_now_tell = set()
for pair in harry_can_tell_draco_cant_tell:
options = [p for p in prod_to_pairs[prod(pair)] if p in harry_can_tell_draco_cant_tell]
if len(options) == 1:
draco_can_now_tell.add(options[0])
harry_can_now_tell = set()
for pair in draco_can_now_tell:
options = [p for p in sum_to_pairs[sum(pair)] if p in draco_can_now_tell]
if len(options) == 1:
harry_can_now_tell.add(options[0])
assert len(harry_can_now_tell) == 1, harry_can_now_tell
(n1, n2), = harry_can_now_tell
print(n1, n2)
if __name__ == '__main__':
find_numbers()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment