Exemple #1
0
from utils import isPrime, baseGen

from math import log10

s = set()

def isTrunc( n ):
    f = n
    while f:
        if not isPrime( f ):
            return False
        f //= 10

    m = int( log10( n ) + 1 )
    while m:
        if not isPrime( n % ( 10 ** m ) ):
            return False
        m -= 1
    return True

for x in baseGen( goods=( 0, 1, 2, 3, 5, 7, 9 ),
                  start=10 ):
    if isTrunc( x ):
        s.add( x )
        if len( s ) >= 11:
            break

print sum( s )

Exemple #2
0
from utils import primeGen, isPrime, rotated, baseGen
from math import log10

cps = { 2, 3, 5, 7, 11 }

def isCircular( n ):
    digits = int( log10( n ) )
    for _ in xrange( digits + 1 ):
        if not isPrime( n ):
            return False
        # rotate the number
        n = rotated( n, digits )
    return True

for x in baseGen( goods=( 0, 1, 3, 7, 9 ),
                  start=11,
                  end=10 ** 6 ):
    if isCircular( x ):
        cps.add( x )

print len( cps )
Exemple #3
0
numbersUsed = set()
passCodes = set()

def isGood( num, code ):
    numTup = map( int, str( num ) )
    numIndex = len( numTup )
    for digit in reversed( digits( code ) ):
        while numIndex:
            if digit == code:
                numIndex -= 1
                continue
            numIndex -= 1
        else:
            return False
    else:
        return True

for line in open( "txt/p079" ):
    passCodes.add( eval( line ) )
    for number in line[:3]:
        numbersUsed.add( eval( number ) )

for num in baseGen( goods=tuple( numbersUsed ) ):
    for code in passCodes:
        if not isGood( num, code ):
            continue
    else:
        print num
        break
# Urgent