Ejemplo n.º 1
0
def panDigitProducts( permList ):
    """Take each permutation of digits and slice into 3 pieces.
    Check to see if each piece is a proper product.
    """
    for ai in range(1,9):
        for bi in range(ai):
            for perm in permList:
                i, j, k = perm[:ai], perm[ai:ai+bi], perm[ai+bi:]
                if number(i)*number(j) == number(k):
                    yield number(k)
Ejemplo n.º 2
0
def substringDivisibility( i ):
    """The substring divisibility property. The number
    is represented as a sequence of digits.

    >>> from euler43 import substringDivisibility
    >>> substringDivisibility( digits(1406357289) )
    True
    >>> substringDivisibility( digits(1406357298) )
    False
    """
    n2= number(i[1:4])
    n3= number(i[2:5])
    n5= number(i[3:6])
    n7= number(i[4:7])
    n11= number(i[5:8])
    n13= number(i[6:9])
    n17= number(i[7:10])
    test = (
        n2 % 2 == 0,
        n3 % 3 == 0,
        n5 % 5 == 0,
        n7 % 7 == 0,
        n11%11 == 0,
        n13%13 == 0,
        n17%17 == 0
    )
    return all( test )
Ejemplo n.º 3
0
def genPanDigitalProdConcat():
    """Get the list of pandigital products.

    >>> from euler38 import genPanDigitalProdConcat
    >>> pdpc= list( genPanDigitalProdConcat() )
    >>> pdpc.sort()
    >>> pdpc # doctest: +ELLIPSIS
    [123456789, 192384576, 219438657, ..., 927318546, 932718654]
    """
    for i in range(1000000):
        seq= prodConcat(i)
        if pandigital(seq):
            yield number(seq)
Ejemplo n.º 4
0
def PDSD_gen():
    """Generate pan-digital numbers with the substring divisibility property.
    The number is represented as a sequence of digits.

    >>> from euler43 import PDSD_gen
    >>> numbers= list( PDSD_gen() )
    >>> 1406357289 in numbers
    True
    >>> numbers
    [1406357289, 1430952867, 1460357289, 4106357289, 4130952867, 4160357289]
    """
    pandigital10= Permutation(range(10))
    for i in pandigital10.nextPerm():
        if substringDivisibility(i):
            yield number(i)
Ejemplo n.º 5
0
def reverseAndAdd( n ):
    """
    >>> from euler55 import reverseAndAdd
    >>> from euler04 import palindrome
    >>> reverseAndAdd(47)
    121
    >>> palindrome( reverseAndAdd(47) )
    True
    >>> reverseAndAdd( reverseAndAdd( reverseAndAdd( 349 ) ) )
    7337
    >>> palindrome( reverseAndAdd( reverseAndAdd( reverseAndAdd( 349 ) ) ) )
    True
    """
    d = digits(n)
    d.reverse()
    return n + number(d)
Ejemplo n.º 6
0
def pandigitalPrimes(size):
    """Generate all pan-digital primes of a given size.

    >>> from euler41 import pandigitalPrimes
    >>> pd4 = list( pandigitalPrimes(4) )
    >>> 2143 in pd4
    True
    >>> pd4
    [1423, 2143, 2341, 4231]
    """
    permN= Permutation( range(1,size+1) )
    for p in permN.nextPerm():
        ld= p[-1]
        if ld % 2 == 0: continue # skip even numbers
        if ld == 5: continue # skip 5's, also
        n= number( p )
        if isprime(n):
            yield n
Ejemplo n.º 7
0
def answer():
    for a,b,c in primeGapPerm():
        if a == 1487 and b == 4817 and c == 8147:
            continue
        return number( digits(a) + digits(b) + digits(c) )