def find_solution(): start_time = datetime.now() answer = 0 primes = [] progress = ProgressBar(1000000) for n in xrange(2, progress.max): progress.set_value(n) if is_prime(n, primes): primes.append(n) #~ digits = map(lambda x: int(x), str(n)) try: permutate(map(lambda x: x, str(n)), [], raise_if_not_prime) print "Found palindrome: %s" % n answer += 1 except IsNotPrimeError: pass #~ all_prime = True #~ for item in permutate(map(lambda x: x, str(n)), ""): #~ if not is_prime(int(item)): #~ all_prime = False #~ break #~ if all_prime: end_time = datetime.now() progress.finished() print "answer: %s" % answer print "number of primes: %s" % len(primes) print "first 10 primes: %s" % primes[:10] print end_time - start_time
def find_solution(): start_time = datetime.now() answer = 0 primes = [] progress = ProgressBar(1000000) for n in xrange(2, progress.max): progress.set_value(n) if is_prime(n, primes): primes.append(n) all_prime = True for item in rotate(n): if not is_prime(int(item)): all_prime = False break if all_prime: print "Found palindrome: %s" % n answer += 1 end_time = datetime.now() progress.finished() print "answer: %s" % answer print "number of primes: %s" % len(primes) print "first 10 primes: %s" % primes[:10] print end_time - start_time
""" if __name__ == "__main__": import sys, os sys.path.append( os.path.join( os.getcwd(), '..' ) ) from datetime import datetime from euler_tools.prime import is_prime from euler_tools.progress_bar import ProgressBar start_time = datetime.now() sum = 0 primes = [] progress = ProgressBar(2000000) for n in xrange(2, progress.max): progress.set_value(n) if is_prime(n, primes): sum += n primes.append(n) end_time = datetime.now() progress.finished() print "sum: %s" % sum print "number of primes: %s" % len(primes) print end_time - start_time #2,000,000: 142913828922