Esempio n. 1
0
#!/usr/bin/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?

import myMath

poss = [x for x in range(1,8)]
largest = 0

while len(poss) > 2:
  perms = myMath.getAllPermutations(poss)
  for perm in perms:
    if perm > largest and myMath.isPrime(perm):
      largest = perm
  poss = poss[:-1]

print largest
Esempio n. 2
0
import myMath

myMath.initPrimeSieve(10000)

def digits(num):
  return [int(dig) for dig in str(num)] 

def findArithmeticSequence(numSet):
  if len(numSet) >= 3:
    numSet = sorted(numSet)
    for x in numSet:
      numSetCopy = numSet[:]
      numSetCopy.remove(x)
      for y in numSetCopy:
        diff = abs(y-x)
        if y + diff in numSetCopy: 
          return (x,y,y+diff)
  return ()

answers = []

for i in xrange(1001,10000):
  perms = list(set(myMath.getAllPermutations(digits(i))))
  perms = [x for x in perms if myMath.isPrime(x) and x > 1000]
  result = findArithmeticSequence(perms)
  if result != () and result not in answers:
    print result
    answers.append(result)