Perl Weekly Challenge 155: Fortunate Numbers and Pisano Periods
These are some answers to the Week 155 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on March 13, 2022 at 24:00). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.
Task 1: Fortunate Numbers
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
Fortunate Numbers in Raku
We first create an infinite (lazy) list (@primes
) of prime numbers. Then, we use it to create a list of primordials (@primorials
). And then, we use it to find fortunate numbers.