else: cPossibles = possibles[:] for c in possibles: monotone( result * 10 + int(c), cPossibles, nb_digits - 1, results ) cPossibles.remove( c ) def monotone_call( LIMIT ): possibles = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] results = [] #monotone( "", possibles, 3, results ) monotone( 0, possibles, len(str(LIMIT))-1, results ) return results LIMIT = 1000000 print "Compute primes until", LIMIT,"..." primes_until(LIMIT) primes_map = {} for p in primes: primes_map[ p ] = True print "Creates testable numbers..." #monotones = monotone_call( LIMIT ) #testables = [ m for m in monotones if m in primes ] #testables = [ p for p in primes if p < LIMIT ] testables = [ p for p in range(LIMIT) ] testables_map = {} for p in testables: testables_map[ p ] = True
# -*- coding:utf-8 -*- from utils.primes import primes, primes_until # Euler's project: problem 50 """ Which prime, below one-million, can be written as the sum of the most consecutive primes?""" LIMIT = 1000000 primes_until( LIMIT ) # compute primes until LIMIT # only considers suites beginning from 2: incomplete solutions. def from_beginning(): global LIMIT sum = 0 i = 0 while sum < LIMIT: sum += primes[i] i += 1 if sum in primes: print sum # Generator used for the next solution, which makes all the sums and yields them def extender( init, max ): t = [ primes[init] ] i = init+1 while i < max: t.append( primes[ i ] ) daSum = sum(t) daLen = len(t) if daSum in primes: