Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created March 30, 2012 14:31
Show Gist options
  • Save shieldsd/2251935 to your computer and use it in GitHub Desktop.
Save shieldsd/2251935 to your computer and use it in GitHub Desktop.
Project Euler #32
from math import sqrt
def divisors(n):
for x in xrange(1, int(sqrt(n)) + 1):
if n % x == 0:
yield x
if x != 1 and x * x != n:
yield n / x
def pandigital(l):
return ''.join(sorted(''.join(str(n) for n in l))) == '123456789'
print sum(set(i for i in range(1, 10000)
for j in divisors(i)
if pandigital([i, j, i/j])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment