diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-17 17:52:53 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-23 18:03:42 +0100 |
| commit | e633a0f727f4eaa5175b1fbd068125c89886825e (patch) | |
| tree | 427a1fd86d0ca59619360603bc0a38b0bc23029b /challenge-022 | |
| parent | 48cc0fc870731750968868ac20233873e70eb24b (diff) | |
| download | perlweeklychallenge-club-e633a0f727f4eaa5175b1fbd068125c89886825e.tar.gz perlweeklychallenge-club-e633a0f727f4eaa5175b1fbd068125c89886825e.tar.bz2 perlweeklychallenge-club-e633a0f727f4eaa5175b1fbd068125c89886825e.zip | |
Challenge 022 task 1
Diffstat (limited to 'challenge-022')
| -rwxr-xr-x | challenge-022/jo-37/perl/ch-1.pl | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/challenge-022/jo-37/perl/ch-1.pl b/challenge-022/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..85c9f56511 --- /dev/null +++ b/challenge-022/jo-37/perl/ch-1.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use Math::Prime::Util qw(is_prime next_prime); +use List::Gen; + +our ($tests, $examples, $verbose); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [N] + +-examples + run the examples from the challenge + +-tests + run some tests + +N + print the first N "sexy prime pairs" + +EOS + + +### Input and Output + +sexy_prime_pairs()->map(sub {"(@$_)"})->say(shift); + + +### Implementation + +sub sexy_prime_pairs { + iterate(sub {next_prime($_)}) + ->from(2) + ->filter(sub {is_prime($_ + 6)}) + ->map(sub {[$_, $_ + 6]}); +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is sexy_prime_pairs()->while(sub {$_->[1] < 500})->apply, + [[5,11], [7,13], [11,17], [13,19], [17,23], [23,29], [31,37], + [37,43], [41,47], [47,53], [53,59], [61,67], [67,73], + [73,79], [83,89], [97,103], [101,107], [103,109], [107,113], + [131,137], [151,157], [157,163], [167,173], [173,179], + [191,197], [193,199], [223,229], [227,233], [233,239], + [251,257], [257,263], [263,269], [271,277], [277,283], + [307,313], [311,317], [331,337], [347,353], [353,359], + [367,373], [373,379], [383,389], [433,439], [443,449], + [457,463], [461,467]], + 'example from Wiki'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
