Skip to content

Instantly share code, notes, and snippets.

@mrmeszaros
Last active November 2, 2021 14:28
Show Gist options
  • Save mrmeszaros/3818ffa409094e9466f4243c775e22c8 to your computer and use it in GitHub Desktop.
Save mrmeszaros/3818ffa409094e9466f4243c775e22c8 to your computer and use it in GitHub Desktop.
Pandigital number generation
#!/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