diff options
Diffstat (limited to 'challenge-022/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-022/paulo-custodio/python/ch-1.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-022/paulo-custodio/python/ch-1.py b/challenge-022/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..346c160fb4 --- /dev/null +++ b/challenge-022/paulo-custodio/python/ch-1.py @@ -0,0 +1,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 |
