Last active
November 2, 2021 14:28
-
-
Save mrmeszaros/3818ffa409094e9466f4243c775e22c8 to your computer and use it in GitHub Desktop.
Pandigital number generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import string | |
DIGITS = string.digits + string.ascii_letters | |
def pandigital(base): | |
if base < 2: | |
return '1', 1 | |
def digits(): | |
yield 1 | |
yield 0 | |
for d in range(2, base): | |
yield d | |
v = 0 | |
for d in digits(): | |
v *= base | |
v += d | |
return ''.join(DIGITS[d] for d in digits()), v | |
for b in range(len(DIGITS)): | |
base = b + 1 | |
p_digits, p_value = pandigital(base) | |
print(base, p_digits, p_value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment