Beispiel #1
0
def truncate(n, direction):
  if len(str(n)) == 1 and isPrime(n):
    return True
  elif isPrime(n):
    if direction == 'LR':
      num = int(str(n)[1:])
    elif direction == 'RL':
      num = int(str(n)[:-1])
    return truncate(num, direction)
  return False
Beispiel #2
0
def truncate(n, direction):
    if len(str(n)) == 1 and isPrime(n):
        return True
    elif isPrime(n):
        if direction == 'LR':
            num = int(str(n)[1:])
        elif direction == 'RL':
            num = int(str(n)[:-1])
        return truncate(num, direction)
    return False
Beispiel #3
0
#!/usr/bin/python
from primes_sieve import primes, isPrime
from time import time

start = time()
limit = 10**6
p = primes(limit)
prev_longest = 0


for i in xrange(0,len(p)):
    s, counter = 0, 0
    for num in p[i:]:
        s += num
        counter += 1
        if isPrime(s) and counter > prev_longest and s <= limit:
            prev_longest = counter
            print s, '| Terms:',counter
        elif s > limit: break

end = time()
print end-start
Beispiel #4
0
def isCircular(n):
    n = str(n)
    for k in xrange(len(n)):
        if not isPrime( int(n[k:] + n[:k]) ):
            return False
    return True
Beispiel #5
0
def isCircular(n):
    n = str(n)
    for k in xrange(len(n)):
        if not isPrime(int(n[k:] + n[:k])):
            return False
    return True