Sexy Primes, What are they?
They are prime numbers that differ by 6. For example, 5 & 11, 7 & 13. The name comes from the Latin word for six; sex. What we are going to do is, write a program to generate all the sexy prime pairs within a given interval of natural numbers.
Sexy Prime Pairs
This is a program to generate all the sexy prime pairs below 10000.
Program
def check_prime(n):
for i in range(2,n//2+1):
if n%i == 0:
return False
return True
def primes_list(a,b):
primes_list = []
for i in range(a,b):
if check_prime(i):
primes_list.append(i)
return (primes_list)
def sexy_list(primes_list):
sexy_list = []
for i in primes_list:
for j in primes_list:
if j-i == 6:
sexy_list.append((i,j))
return(sexy_list)
primes = primes_list(2,1000)
print(sexy_list(primes))
Output
[(5, 11), (7, 13), (11, 17), (13, 19), (17, 23), (23, 29), (31, 37), (37, 43), (41, 47), (47, 53), (53, 59), (61, 67), (67, 73), (73, 79), (83, 89), (97, 103), (101, 107), (103, 109), (107, 113), (131, 137), (151, 157), (157, 163), (167, 173), (173, 179), (191, 197), (193, 199), (223, 229), (227, 233), (233, 239), (251, 257), (257, 263), (263, 269), (271, 277), (277, 283), (307, 313), (311, 317), (331, 337), (347, 353), (353, 359), (367, 373), (373, 379), (383, 389), (433, 439), (443, 449), (457, 463), (461, 467), (503, 509), (541, 547), (557, 563), (563, 569), (571, 577), (587, 593), (593, 599), (601, 607), (607, 613), (613, 619), (641, 647), (647, 653), (653, 659), (677, 683), (727, 733), (733, 739), (751, 757), (821, 827), (823, 829), (853, 859), (857, 863), (877, 883), (881, 887), (941, 947), (947, 953), (971, 977), (977, 983), (991, 997)]