Example #1
0
    for i in range(12, n+1):
        if (i not in abund_dict) and is_abundant(i):
            j = 1
            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
Example #2
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)
    
Example #3
0
from primes import Primes
from performance import memoize
from itertools import permutations as list_perms
p = Primes(10000)
is_prime = p.is_prime
p_list = p.primes_list


def permutations(n):
    return {
        int(''.join(x)): None
        for x in list(list_perms(str(n))) if x[0] != '0'
    }


permutations = memoize(permutations)


def solve():
    results = []
    for delta in range(3330, 5000):
        for i in range(1000, 10000 - 2 * delta):
            perms = permutations(i)
            if (is_prime(i) and is_prime(i + delta) and is_prime(i + 2 * delta)
                    and (i + delta) in perms and (i + 2 * delta) in perms):
                results.append((i, i + delta, i + 2 * delta))
                print(i, i + delta, i + 2 * delta)
    return results