Exemplo n.º 1
0
def is_trunc(n):
    if not euler.is_prime(n):
        return False
    d = euler.digits(n)
    for c in range(1,len(d)):
        lt = euler.num_from_digits(d[:-c])
        rt = euler.num_from_digits(d[c:])
        if not (euler.is_prime(lt) and euler.is_prime(rt)):
            return False
    return True
Exemplo n.º 2
0
def has_div(d, os, denom):
    s = 9 - os
    if denom == 2:
        return d[s - 2] & 1 == 0
    if denom == 3:
        return sum(d[s:s - 3:-1]) % 3 == 0
    if denom == 5:
        return d[s - 2] == 5 or d[s - 2] == 0
    return euler.num_from_digits(d[s - 2:s + 1]) % denom == 0
Exemplo n.º 3
0
def is_pand_multiple(n):
    for f in range(1,5):
        nd = euler.digits(n)
        basen = euler.num_from_digits(nd[-f:])
        currn = basen
        nd   = nd[:-f]
        while nd:
            currn += basen
            cnd = euler.digits(currn)
            if (nd[-len(cnd):] != cnd):
                break
            nd = nd[:-len(cnd)]
        if not nd:
            return True
    return False
Exemplo n.º 4
0
#!/usr/bin/python
import euler
import math

def is_pand_multiple(n):
    for f in range(1,5):
        nd = euler.digits(n)
        basen = euler.num_from_digits(nd[-f:])
        currn = basen
        nd   = nd[:-f]
        while nd:
            currn += basen
            cnd = euler.digits(currn)
            if (nd[-len(cnd):] != cnd):
                break
            nd = nd[:-len(cnd)]
        if not nd:
            return True
    return False

for p in euler.perms(list(reversed(range(1,10))), rev=True):
    n = euler.num_from_digits(reversed(p))
    if (is_pand_multiple(n)):
        print(n)
        break
Exemplo n.º 5
0
primes = euler.sieve(UpTo)
circular = [0] * len(primes)


def rotate(d):
    return d[-1:] + d[:-1]


for x in range(0, len(primes)):
    if not primes[x]:
        continue
    if circular[x]:
        continue
    d = rotate(euler.digits(x))
    rd = euler.num_from_digits(d)
    while rd != x:
        if not primes[rd]:
            break
        d = rotate(d)
        rd = euler.num_from_digits(d)

    if rd == x:
        d = rotate(d)
        rd = euler.num_from_digits(d)
        circular[x] = 1
        while rd != x:
            circular[rd] = 1
            d = rotate(d)
            rd = euler.num_from_digits(d)
Exemplo n.º 6
0
import euler


def has_div(d, os, denom):
    s = 9 - os
    if denom == 2:
        return d[s - 2] & 1 == 0
    if denom == 3:
        return sum(d[s:s - 3:-1]) % 3 == 0
    if denom == 5:
        return d[s - 2] == 5 or d[s - 2] == 0
    return euler.num_from_digits(d[s - 2:s + 1]) % denom == 0


def has_property(d):
    return (has_div(d, 1, 2) and has_div(d, 2, 3) and has_div(d, 3, 5)
            and has_div(d, 4, 7) and has_div(d, 5, 11) and has_div(d, 6, 13)
            and has_div(d, 7, 17))


digits = range(10)
Valid = []

while digits:
    if (has_property(digits)):
        Valid.append(euler.num_from_digits(digits))
    digits = euler.next_perm(digits)

print(Valid)
print(sum(Valid))