diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2024-09-28 19:23:13 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2024-09-28 19:23:13 +0100 |
| commit | 341287fb7780a3c5ee45ec0521ef99d11dbdbcce (patch) | |
| tree | b7793f10622a828e704e919487e77ffcce8a21a8 /challenge-155/paulo-custodio/python/ch-1.py | |
| parent | 19698b60b5f8bbc16989a16c47fe41fa435cede3 (diff) | |
| download | perlweeklychallenge-club-341287fb7780a3c5ee45ec0521ef99d11dbdbcce.tar.gz perlweeklychallenge-club-341287fb7780a3c5ee45ec0521ef99d11dbdbcce.tar.bz2 perlweeklychallenge-club-341287fb7780a3c5ee45ec0521ef99d11dbdbcce.zip | |
Add Python solution to challenge 155
Diffstat (limited to 'challenge-155/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-155/paulo-custodio/python/ch-1.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-155/paulo-custodio/python/ch-1.py b/challenge-155/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..e1cdaebf76 --- /dev/null +++ b/challenge-155/paulo-custodio/python/ch-1.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +# Challenge 155 +# +# TASK #1 > Fortunate Numbers +# Submitted by: Mohammad S Anwar +# Write a script to produce first 8 Fortunate Numbers (unique and sorted). +# +# According to Wikipedia +# +# A Fortunate number, named after Reo Fortune, is the smallest integer m > 1 +# such that, for a given positive integer n, pn# + m is a prime number, where +# the primorial pn# is the product of the first n prime numbers. +# +# Expected Output +# 3, 5, 7, 13, 17, 19, 23, 37 + +from math import prod +from sympy import isprime, nextprime + +fortunate = {} + +primes = [2] +while len(fortunate) < 8: + p = prod(primes) + m = 2 + while not isprime(p + m): + m += 1 + fortunate[m] = 1 + primes.append(nextprime(primes[-1])) + +print(", ".join(map(str, sorted(fortunate.keys())))) |
