blob: 346c160fb4d105c8812df3cdcabb5365042f098d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#!/usr/bin/python3
# Challenge 022
#
# Task #1
# Write a script to print first 10 Sexy Prime Pairs. Sexy primes are prime
# numbers that differ from each other by 6. For example, the numbers 5 and 11
# are both sexy primes, because 11 - 5 = 6. The term "sexy prime" is a pun
# stemming from the Latin word for six: sex. For more information, please
# checkout wiki page.
import sys
from primePy import primes
def next_prime(n):
if n <= 1:
return 2
else:
n += 1
while not primes.check(n):
n += 1
return n
def sexy_primes_iter():
a = 1
while True:
a = next_prime(a)
b = a
while b < a+6:
b = next_prime(b)
if b == a+6:
yield (a, b)
count = 0
for a, b in sexy_primes_iter():
print(f"({a}, {b})")
count += 1
if count >= 10:
break
|