Exemplo n.º 1
0
def is_curious(n):
    sum = 0
    for c in str(n):
        sum = sum + factorial(int(c))
    if sum == n:
        return True
    else:
        return False
Exemplo n.º 2
0
def problem42():
    result = []
    pandigit = "0123456789"
    for x in xrange(factorial(10)-1):
        number = permutation(pandigit,x)
        if divisiontest(number):
            result.append(int(number))
    return sum(result)
Exemplo n.º 3
0
def permutator(digits, permutation):
    result = ""
    digits = [c for c in digits]
    while len(digits) > 0:
        selection = factorial(len(digits)-1)
        index = permutation / selection
        permutation = permutation % selection
        result = result + digits[index]
        del digits[index]
    return result
Exemplo n.º 4
0
def problem49():
    result = []
    primes = [x for x in prime_generator(10000)]
    d = 3330
    for n in xrange(1000, 10000):
        if n not in primes:
            continue
        n_str = str(n)
        per = [int(permutation(n_str, x)) for x in xrange(factorial(4))]
        pri = [x for x in per if x in primes]
        if n+d in pri and n+2*d in pri:
            result.append(str(n) + str(n+d) + str(n+d+d))
    return list(set(result))
Exemplo n.º 5
0
def problem34():
    result = []
    for x in xrange(3, factorial(9)):
        if is_curious(x):
            result.append(x)
    return sum(result)
Exemplo n.º 6
0
def problem41():
    pandigit = "987654321"
    for i in xrange(9):
        for x in xrange(factorial(9-i)-1):
            if is_prime(int(permutation(pandigit[i:], x))):
                return permutation(pandigit[i:], x)