Skip to content

Instantly share code, notes, and snippets.

@pbassut
Last active September 17, 2015 13:35
Show Gist options
  • Save pbassut/b57dab63b591855a801d to your computer and use it in GitHub Desktop.
Save pbassut/b57dab63b591855a801d to your computer and use it in GitHub Desktop.
def is_pandigital(num):
num = str(num)
beg = set(num[0:len(num)])
end = set(num[-len(num):])
if beg != end:
return False
return beg == set(map(str, range(1, len(num) + 1)))
def calculate_unusuals():
l = []
for m in range(2, 9876):
nbegin = 123 if m > 9 else 1234
nend = 10000 / m + 1
for n in range(nbegin, nend):
prod = n * m
concatenated = str(n) + str(m) + str(prod)
if is_pandigital(concatenated):
l.append(prod)
print reduce(lambda x, y: x + y, l)
if __name__ == '__main__':
assert is_pandigital(1234)
assert is_pandigital(1234)
assert is_pandigital(321465)
assert is_pandigital(123456789)
assert not is_pandigital(11234357)
calculate_unusuals()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment