def panproducts(): count = 0 sum = 0 pandigitals = set() for pa in permutations(xrange(1, 10), 1): a = int(''.join([str(n) for n in pa])) for pb in permutations(xrange(1, 10), 4): b = int(''.join([str(n) for n in pb])) c = a * b if ispandigital(str(a) + str(b) + str(c)): print('{} x {} = {}'.format(a, b, c)) pandigitals.add(c) sum += c for pa in permutations(xrange(1, 10), 2): a = int(''.join([str(n) for n in pa])) for pb in permutations(xrange(1, 10), 3): b = int(''.join([str(n) for n in pb])) c = a * b if ispandigital(str(a) + str(b) + str(c)): print('{} x {} = {}'.format(a, b, c)) pandigitals.add(c) sum += c return pandigitals
def scan(): pandigitals = [] for n in range(1, UPPERLIMIT): if n % 1000 == 0: print n i = 1 candidate = '' while i < 10 and len(candidate) < 9: candidate = candidate + str( i * n) i += 1 if ispandigital(candidate): pandigitals.append(candidate) return pandigitals
#!/usr/bin/env python """ Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital. """ import time st = time.time() from euler import ispandigital product = {} for i in xrange(1, 101): for j in xrange(1, 2001): if ispandigital(str(i) + str(j) + str(i * j)): if not str(i * j) in product: product[i * j] = 1 print sum(p for p in product) print "Time taken: %s" % str(time.time() - st)
#!/usr/bin/env python """ Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital. """ import time st = time.time() from euler import ispandigital product = {} for i in xrange(1,101): for j in xrange(1,2001): if ispandigital(str(i)+str(j)+str(i*j)): if not str(i*j) in product: product[i*j] = 1 print sum(p for p in product) print "Time taken: %s" % str(time.time() - st)
from euler import ispandigital for i in range(1,10000): s=str(i) j = 2 while len(s) < 9: s += str(j * int(i)) j+=1 if (ispandigital(int(s))): print(i, s)
#!/usr/bin/env python """ We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime. What is the largest n-digit pandigital prime that exists? """ from euler import ispandigital, primes import time st = time.time() primes = primes(10000000) total = 0 for prime in primes: if ispandigital(prime, len(str(prime))): if prime > total: total = prime print total print "Time taken: %s" % str(time.time() - st)
def test_ispandigital(self): self.assertEqual(euler.ispandigital(1), True) self.assertEqual(euler.ispandigital(2), False) self.assertEqual(euler.ispandigital(2143), True) self.assertEqual(euler.ispandigital(2145), False)