예제 #1
0
def main():
    truncatable = []
    generator = prime_generator()
    print 'Searching for truncatable primes...'
    while len(truncatable) < 11:
        prime = generator.next()
        if is_truncatable(prime):
            truncatable.append(prime)
    print 'Found {0} truncatable primes'.format(len(truncatable))
    print 'Sum:', sum(truncatable)
예제 #2
0
파일: e010.py 프로젝트: correl/euler
def main():
    print 'Fetching all primes for n < 2,000,000'
    total = 0
    generator = prime_generator()
    while True:
        prime = generator.next()
        if prime >= 2000000:
            break
        total += prime
    print 'Sum:', total
예제 #3
0
파일: e010.py 프로젝트: correl/euler
def main():
    print "Fetching all primes for n < 2,000,000"
    total = 0
    generator = prime_generator()
    while True:
        prime = generator.next()
        if prime >= 2000000:
            break
        total += prime
    print "Sum:", total
예제 #4
0
def main():
    MAX = 1000000
    circular_primes = []
    print 'Searching for circular primes for p < {0}...'.format(MAX)
    for prime in prime_generator():
        if prime >= MAX:
            break
        try:
            # Ensure the prime *can* be circular
            if prime > 9:
                for c in [n for n in str(prime) if n not in ['1', '3', '7', '9']]:
                    raise NotCircular()
            # Check all permutations
            for rotation in cyclic_rotation(prime):
                if not is_prime(rotation):
                    raise NotCircular()
            circular_primes.append(prime)
        except NotCircular:
            pass
        # Clear all permutations from the list?
    print 'Circular Primes ({0}): {1}'.format(len(circular_primes), circular_primes)