Created
December 12, 2011 21:55
-
-
Save jakedobkin/1469303 to your computer and use it in GitHub Desktop.
Problem 51: PRime Families
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # set up prime sieve to n- we'll need up to 999999 here, since we're investigating 6 figure combos | |
| total = 0 | |
| n=1000000 | |
| myPrimes = [True]*(n+1) | |
| mySum = [0]*(n+1) | |
| last = 0 | |
| for i in range (2,n): | |
| if myPrimes[i] == True: | |
| j = 2*i | |
| while j<=n: | |
| myPrimes[j]=False | |
| j=j+i | |
| # part one: there are 20 different ways to replace 3 characters- i've written them manually | |
| # but you could probably figure out a way to do this with a loop | |
| for k in range (100000,999999): | |
| if myPrimes[k] == True: | |
| text = str(k) | |
| string=[""]*20 | |
| myCount=[0]*20 | |
| for l in range (1,10): | |
| n = str(l) | |
| a=text[0:1] | |
| b=text[1:2] | |
| c=text[2:3] | |
| d=text[3:4] | |
| e=text[4:5] | |
| f=text[5:6] | |
| string[0]=n+n+n+d+e+f | |
| if myPrimes[int(string[0])]==True: | |
| myCount[0]+=1 | |
| string[1]=n+n+c+n+e+f | |
| if myPrimes[int(string[1])]==True: | |
| myCount[1]+=1 | |
| string[2]=n+n+c+d+n+f | |
| if myPrimes[int(string[2])]==True: | |
| myCount[2]+=1 | |
| string[3]=n+n+c+d+e+n | |
| if myPrimes[int(string[3])]==True: | |
| myCount[3]+=1 | |
| string[4]=n+b+n+n+e+f | |
| if myPrimes[int(string[4])]==True: | |
| myCount[4]+=1 | |
| string[5]=n+b+n+d+n+f | |
| if myPrimes[int(string[5])]==True: | |
| myCount[5]+=1 | |
| string[6]=n+b+n+d+e+n | |
| if myPrimes[int(string[6])]==True: | |
| myCount[6]+=1 | |
| string[7]=n+b+c+n+n+f | |
| if myPrimes[int(string[7])]==True: | |
| myCount[7]+=1 | |
| string[8]=n+b+c+n+e+n | |
| if myPrimes[int(string[8])]==True: | |
| myCount[8]+=1 | |
| string[9]=n+b+c+d+n+n | |
| if myPrimes[int(string[9])]==True: | |
| myCount[9]+=1 | |
| string[10]=a+n+n+n+e+f | |
| if myPrimes[int(string[10])]==True: | |
| myCount[10]+=1 | |
| string[11]=a+n+n+d+n+f | |
| if myPrimes[int(string[11])]==True: | |
| myCount[11]+=1 | |
| string[12]=a+n+n+d+e+n | |
| if myPrimes[int(string[12])]==True: | |
| myCount[12]+=1 | |
| string[13]=a+n+c+n+n+f | |
| if myPrimes[int(string[13])]==True: | |
| myCount[13]+=1 | |
| string[14]=a+n+c+n+e+n | |
| if myPrimes[int(string[14])]==True: | |
| myCount[14]+=1 | |
| string[15]=a+n+c+d+n+n | |
| if myPrimes[int(string[15])]==True: | |
| myCount[15]+=1 | |
| string[16]=a+b+n+n+n+f | |
| if myPrimes[int(string[16])]==True: | |
| myCount[16]+=1 | |
| string[17]=a+b+n+n+e+n | |
| if myPrimes[int(string[17])]==True: | |
| myCount[17]+=1 | |
| string[18]=a+b+n+d+n+n | |
| if myPrimes[int(string[18])]==True: | |
| myCount[18]+=1 | |
| string[19]=a+b+c+n+n+n | |
| if myPrimes[int(string[19])]==True: | |
| myCount[19]+=1 | |
| if 8 in myCount: | |
| print k, myCount | |
| break | |
| # you have to take the answer from part 1 and run it through the string 5 pattern, and take the lowest number | |
| text = "120383" | |
| for l in range (1,10): | |
| n = str(l) | |
| a=text[0:1] | |
| b=text[1:2] | |
| c=text[2:3] | |
| d=text[3:4] | |
| e=text[4:5] | |
| f=text[5:6] | |
| print n+b+n+d+n+f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment