diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-29 20:45:15 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-04-19 18:48:46 +0200 |
| commit | ab7170d2524e865fd9c5e81c65b73fcd7b22febf (patch) | |
| tree | c69c2efb3e5ad9235397e29f675af9b04c6084fd /challenge-041 | |
| parent | 5f3f255cbbb5eb1427ad0e2b75fab7fad0ce732f (diff) | |
| download | perlweeklychallenge-club-ab7170d2524e865fd9c5e81c65b73fcd7b22febf.tar.gz perlweeklychallenge-club-ab7170d2524e865fd9c5e81c65b73fcd7b22febf.tar.bz2 perlweeklychallenge-club-ab7170d2524e865fd9c5e81c65b73fcd7b22febf.zip | |
Challenge 041 task 1
Diffstat (limited to 'challenge-041')
| -rwxr-xr-x | challenge-041/jo-37/perl/ch-1.pl | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/challenge-041/jo-37/perl/ch-1.pl b/challenge-041/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..b2965ee40b --- /dev/null +++ b/challenge-041/jo-37/perl/ch-1.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use List::Gen; +use Math::Prime::Util qw(is_prime factor); + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV == 1; +usage: $0 [-examples] [-tests] [N] + +-examples + run the examples from the challenge + +-tests + run some tests + +N + print attractive numbers up to N + +EOS + + +### Input and Output + +gen_attractive_numbers()->while("<= $ARGV[0]")->say; + + +### Implementation + +sub gen_attractive_numbers { + <2..>->filter(sub {is_prime(scalar factor($_))}); +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is gen_attractive_numbers()->while('<= 50')->apply, + [4, 6, 8, 9, 10, 12, 14, 15, 18, 20, 21, 22, 25, 26, 27, 28, 30, + 32, 33, 34, 35, 38, 39, 42, 44, 45, 46, 48, 49, 50], + 'task 1 from OEIS A063989'; + } + + SKIP: { + skip "tests" unless $tests; + is gen_attractive_numbers()->take(63), + [4, 6, 8, 9, 10, 12, 14, 15, 18, 20, 21, 22, 25, 26, 27, 28, 30, + 32, 33, 34, 35, 38, 39, 42, 44, 45, 46, 48, 49, 50, 51, 52, + 55, 57, 58, 62, 63, 65, 66, 68, 69, 70, 72, 74, 75, 76, 77, + 78, 80, 82, 85, 86, 87, 91, 92, 93, 94, 95, 98, 99, 102, + 105, 106], + 'first 63 from OEIS A063989'; + } + + done_testing; + exit; +} |
