ans.add(x) x=x%tensPow(l) l-=1 return ans def tensPow(x): ans=1 for i in range(x): ans*=10 return ans print rTrunks(1234) print lTrunks(1234,3) pSet=p.smartPrimesUnder(1000000) c=0 s=0 for x in pSet: r=rTrunks(x) l=len(r) if r.issubset(pSet) and lTrunks(x,l-1).issubset(pSet): print x c+=1 print c s+=x if c==15: break print s
import sys sys.path.append("..") import prime as p import math #digSet=set([1,2,3,4,5,6,7,8,9]) #digList=[1,2,3,4,5,6,7,8,9] relevantPrimes=p.smartPrimesUnder(31427) relevantPrimes=list(relevantPrimes) relevantPrimes.sort() ##def getNextNPand(curPands): ## rtnVal=[] ## curLen= ## for n in curPands: ## news=buildOn(n) ## rtnVal.extend(news) ## return rtnVal ## ##def buildOn(n,x): ## toAdd=len( ## n*=10 ## rtnVal=[] ## nums=numSet(n) ## toAdd=digSet - nums ## for x in toAdd: ## cur = n+x ## rtnVal.append(cur) ## return rtnVal ## ##def numSet(x):
##If I later examine the number [1,2,9,4,9,6] where indices [2,4] are varaible, ##I would also be examining the class [1,2,*,4,*,6]. SO, if i were smart, ##I would recognize that the pair ([1,2,4,6],[2,4]) was already used, ##and not bother computing with it. import sys sys.path.append("..") import math as m import prime as p import itertools as i import time #assume answer < 1000000 primes=p.smartPrimesUnder(1000000) print "primes calculated. starting cool stuff" class NumChangeEquivalenceClass: """ (equivalence)CLASS definition: EXAMPLE: For the class [1,2,*,4,*,6], we will have: var_indices=[2,4] and digit_list=[1,2,-1,4,-1,6]. elements is everything in {1,2,*,4,*,6] """
##The heuristic for finding this first string is as follows: ##take the longest list of consecutive primes summing to less than P. ##L=[2,3,5,7...73]. ##Now, until L has length 0, we will do the following process: ##1: append the next prime to L, ##2: remove a bunch of primes from the beginning of L until sum(L)<=P ##3: if sum(L)=P: win, ## else: repeat import sys sys.path.append("..") import prime as p primesUnderMil=list(p.smartPrimesUnder(1000000)) primesUnderMil.sort() print "has finished computing primes under million. now doing cool work" def getMaxConsecutiveSummands(sortedSummands, x, sumOfFirstNSummands, curMaxConsecPrimes): #This function calculats the maximum number consecutive summands #in sortedSummands, which sum to x. #Arg sumOfFirstNSummands is a tuple representing the sum of some consecutive #summands summing to less than "x" #Arg curMaxConsecPrimes represents the current "best" answer to the problem.