From 341287fb7780a3c5ee45ec0521ef99d11dbdbcce Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Sat, 28 Sep 2024 19:23:13 +0100 Subject: Add Python solution to challenge 155 --- challenge-155/paulo-custodio/python/ch-1.py | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 challenge-155/paulo-custodio/python/ch-1.py (limited to 'challenge-155/paulo-custodio/python/ch-1.py') 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())))) -- cgit