diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-14 22:00:26 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-23 18:03:41 +0100 |
| commit | ab930ab08e41408f9f01ac692af12c7d74a2bae4 (patch) | |
| tree | 96d9f3f755308015a65c0ada48f6c83c3e35de49 /challenge-015/jo-37 | |
| parent | 69afb227563af5681b3ae017a6cad896ab0e5f7d (diff) | |
| download | perlweeklychallenge-club-ab930ab08e41408f9f01ac692af12c7d74a2bae4.tar.gz perlweeklychallenge-club-ab930ab08e41408f9f01ac692af12c7d74a2bae4.tar.bz2 perlweeklychallenge-club-ab930ab08e41408f9f01ac692af12c7d74a2bae4.zip | |
Challenge 015 task 1
Diffstat (limited to 'challenge-015/jo-37')
| -rwxr-xr-x | challenge-015/jo-37/perl/ch-1.pl | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-015/jo-37/perl/ch-1.pl b/challenge-015/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..cf2b43f615 --- /dev/null +++ b/challenge-015/jo-37/perl/ch-1.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl -s + +use v5.16; +use warnings; +use List::Gen; +use Math::Prime::Util qw(prev_prime next_prime); +use experimental 'signatures'; + +our $weak; + +die <<EOS unless @ARGV == 1; +usage: $0 [-weak] N + +-weak + print "weak" primes instead of "strong" ones + +N + print the first N primes from the selected category + +EOS + + +### Input and Output + +gen_sw_primes(!$weak)->say(shift); + + +### Implementation + +sub gen_sw_primes ($strong) { + iterate(sub {next_prime($_)}) + ->from(3) + ->filter(sub {!$strong ^ ($_ > (prev_prime($_) + next_prime($_)) / 2)}); +} |
