Skip to content

Instantly share code, notes, and snippets.

@cetaSYN
Last active February 4, 2020 17:38
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 cetaSYN/69dbe14b7d060448e1cc8a962b799ad8 to your computer and use it in GitHub Desktop.
Save cetaSYN/69dbe14b7d060448e1cc8a962b799ad8 to your computer and use it in GitHub Desktop.
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.

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