Esempio n. 1
0
import sys
sys.path.append('C:\\Users\\bob\\comp-sci\\project-euler\\toolkit')
from performance import memoize, make_timed

def next_num(n):
    return sum([x**2 for x in [int(n) for n in str(n)]])

next_num = memoize(next_num)

def solve(n):
    count = 0
    for i in range(1,n):
        while i not in (1, 89):
            i = next_num(i)
        if i == 89:
            count += 1
    return count

solve = make_timed(solve)
    
Esempio n. 2
0
            while(j*i < n):
                abund_dict[j*i] = None
                j += 1
        if is_perfect(i):
            j = 2
            while(j*i < n):
                abund_dict[j*i] = None
                j += 1
    abund_list = list(abund_dict.keys())
    abund_list.sort()
    return (abund_list, abund_dict)

binary_str = memoize(binary_str)
prime_factors = memoize(prime_factors)
sum_prop_divs = memoize(sum_prop_divs)
make_abund_structures = make_timed(make_abund_structures)

ABUND_LIST, ABUND_DICT = make_abund_structures(MAX_NUM)

def is_sum_of_abund(n, abund_list=ABUND_LIST):
    for a in abund_list:
        if a > n:
            return False
        for b in abund_list:
            if a + b > n:
                break
            if a + b == n:
                return True
    return False

def nums_not_sum_of_abund(n, abund_list=ABUND_LIST):