1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
plist = [False,False,True]+[True,False]*500000 for n in xrange(3,1000,2): if plist[n]: plist[n*n::2*n]= [False]*len(plist[n*n::2*n]) primes=set(x for x in xrange(1000000) if plist[x]) for h in (1,5,7,11): for A in xrange(1,13): B,P,R,I,M,E,Y,Z = ( str(((A + (i-1)*h)-1)%12+1) for i in (2,16,18,9,13,5,25,26)) if int(Y) in primes and int(Z) in primes: if int(P+R+I+M+E) in primes: print "increment=",h, "P,R,I,M,E=",P,R,I,M,E, "PRIME=",P+R+I+M+E print "A,B=",A,B |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from primes import Primes # The number on which A is placed must be prime since # A, M and Y are on the same number whatever the step for pos_a in (2, 3, 5, 7, 11): # the number of steps clockwise between consecutive letters # - for only 2 numbers to have three letters means that the # step is co-prime with 12 for step in (1, 5, 7, 11): # B, N and Z are on the same number so it must be prime if (pos_a + step) % 12 in (2, 3, 5, 7, 11): # l2n maps letters to numbers for the 26 letters l2n = {chr(ord('A') + i):(pos_a + i * step) % 12 for i in range(26)} # find the value of 'PRIME' (noting that 0 on clock is labelled 12) nbr = ''.join(str(l2n[c] if l2n[c] else 12) for c in 'PRIME') # check that this is a six digit prime if len(nbr) == 6 and int(nbr) in Primes(): print('A and B correspond to {} and {} respectively (PRIME = {}).' .format(l2n['A'], l2n['B'], nbr)) |