Example #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)
Example #2
0
File: e010.py Project: 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
Example #3
0
File: e010.py Project: 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
Example #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)