Skip to content

Instantly share code, notes, and snippets.

@cetaSYN
Last active Feb 4, 2020
Embed
What would you like to do?
SANS Holiday Hack 2019 Dormitory Keypad Solver
# SANS Holiday Hack 2019 Dormitory Keypad Solver
from itertools import product
# https://stackoverflow.com/questions/46841968/fastest-way-of-testing-if-a-number-is-prime-with-python
def is_prime(n):
if n & 1 == 0:
return False
d= 3
while d * d <= n:
if n % d == 0:
return False
d= d + 2
return True
digits = [1, 3, 7]
for opt in product(digits, repeat=4):
if set(digits).issubset(opt): # Must contain all digits at least once
opt = int(''.join(str(c) for c in opt))
if is_prime(opt):
print(opt)
@cetaSYN
Copy link
Author

cetaSYN commented Jan 7, 2020

Output:

1373
1733
3137
3371
7331

Solution was 7331 AKA 1337 backwards, because of course it is.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment