Exemplo n.º 1
0
def solve():
    digits = [str(x) for x in range(1, 10)]
    while len(digits) > 1:
        seq = copy.deepcopy(digits)
        pandigitals = [int(x) for x in mathlib.permute(seq)]
                       #if int(x[len(digits)-1]) % 2 != 0 and x[len(digits)-1] != '5']

        # we do some optimization here, to filter the element could be divid by
        # any number in range 2 to 9
        optimization = []
        for item in pandigitals:
            op = True
            for i in range(2, 10):
                if item % i == 0:
                    op = False
                    break
                else:
                    pass
            if op == True:
                optimization.append(item)
        optimization.sort()
        digits.pop()
        
        for i in range(len(optimization)-1, -1, -1):
            if mathlib.isPrime(optimization[i]):
                return optimization[i]
        
    return ''
Exemplo n.º 2
0
def solveSlow():
    numbers = mathlib.permute(list('1234567890'))
    result = 0
    for item in numbers:
        if int(item[7:10]) % 17 == 0:
            if int(item[6:9]) % 13 == 0:
                if int(item[5:8]) % 11 == 0:
                    if int(item[4:7]) % 7 == 0:
                        if int(item[3:6]) % 5 == 0:
                            if int(item[2:5]) % 3 == 0:
                                if int(item[1:4]) % 2 == 0:
                                    result += int(item)
                                
    return result