def longest_chain(x): record, longest_chain = 0, 0 li = sorted(sieve_of_eratosthenes(x)) ceil = max(li) for idx, n in enumerate(li): tmp = n rest = li[idx + 1:] if len(rest) < longest_chain: break if len(rest) > 0: for idxx, num in enumerate(rest): tmp += num if tmp > ceil: break if tmp in rest: chain = idxx + 2 if chain > longest_chain: longest_chain = chain record = tmp else: continue return f'longest chain is {longest_chain} for {record}'
from prob_10 import sieve_of_eratosthenes primes = sorted(sieve_of_eratosthenes(1000000)) truncs = lambda n: [n[:i] for i in range(1,len(n))] + [n[i:] for i in range(1,len(n))] print(sum([n for n in primes[4:] if all([int(m) in primes for m in truncs(str(n))])]))
from prob_10 import sieve_of_eratosthenes primes = sieve_of_eratosthenes(100000) find_double_squares = lambda n: [i**2 * 2 for i in range(1, int(n**0.5))] def find_goldbach(num): squares = find_double_squares(num) for p in primes: if p < num: for sq in squares: if p + sq == num: return True return False composites = [i for i in set(range(100000)).difference(primes) if i % 2 != 0][1:] # omit 1 for n in composites: if not find_goldbach(n): print(n) break
from itertools import combinations from prob_10 import sieve_of_eratosthenes same_dig = lambda x, y, z: sorted(str(x)) == sorted(str(y)) == sorted(str(z)) same_dist = lambda x, y, z: x - y == y - z print([ i for i in combinations( [k for k in sieve_of_eratosthenes(10000) if k > 1000], r=3) if same_dist(*i) and same_dig(*i) ])