Esempio n. 1
0
                ts += 1
                tiranum = tria(ts)
                if tiranum == current:
                    equal += 1
                    break
                elif tiranum < current:
                    pass
                else:
                    current = tiranum
                    ref = 0
                    break
            # the hexagonal loop
            while True:
                ps += 1
                pentnum = pent(ps)
                if pentnum == current:
                    equal += 1
                    break
                elif pentnum < current:
                    pass
                else:
                    current = pentnum
                    ref = 1
                    break
            # if  triangle == pentagonal == hexagonal
            if equal == 2:
                return current, ts, ps, hs

print solve()
print runningTime('solve()', 10)
Esempio n. 2
0
    return sum([x*x for x in mathlib.getDigits(num)])

def solve():
    to01, to89 = [1], [89]
    result = 10000000 - 1
    for ref in range(1, 9*9*7+1):
        if ref == 1 or ref == 89:
            pass
        else:
            i = squareAdd(ref)
            while True:
                if i in to89:
                    to89.append(ref)
                    break
                elif i in to01:
                    to01.append(ref)
                    break
                else:
                    i = squareAdd(i)

    for num in range(1, 10000000):
        if squareAdd(num) in to01:
            result -= 1
        else:
            pass
    return result

print solve()
print utillib.runningTime("solve()", 1)
        
Esempio n. 3
0
#       way, we note the following:
#           * d2d3d4=406 is divisible by 2
#           * d3d4d5=063 is divisible by 3
#           * d4d5d6=635 is divisible by 5
#           * d5d6d7=357 is divisible by 7
#           * d6d7d8=572 is divisible by 11
#           * d7d8d9=728 is divisible by 13
#           * d8d9d10=289 is divisible by 17
#       Find the sum of all 0 to 9 pandigital numbers with this property.

#brute force method~
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

print solveSlow()
print utillib.runningTime('solveSlow()', 1)