diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-02-26 21:29:48 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-03-01 15:16:15 +0100 |
| commit | 7570e857351225497f3b92034be0fc7155c10db1 (patch) | |
| tree | b1f7cac539da7cec3e950fac0717b540fdc7127b /challenge-258 | |
| parent | d9b3f6be44bf5cdfd4b2cdc3a4e60f96285e2dbe (diff) | |
| download | perlweeklychallenge-club-7570e857351225497f3b92034be0fc7155c10db1.tar.gz perlweeklychallenge-club-7570e857351225497f3b92034be0fc7155c10db1.tar.bz2 perlweeklychallenge-club-7570e857351225497f3b92034be0fc7155c10db1.zip | |
Solution to task 1
Diffstat (limited to 'challenge-258')
| -rwxr-xr-x | challenge-258/jo-37/perl/ch-1.pl | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/challenge-258/jo-37/perl/ch-1.pl b/challenge-258/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..510091a56d --- /dev/null +++ b/challenge-258/jo-37/perl/ch-1.pl @@ -0,0 +1,62 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; +use Math::Prime::Util 'todigits'; + +our ($tests, $examples, $base); +$base ||= 10; + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [-base=BASE] [N...] + +-examples + run the examples from the challenge + +-tests + run some tests + +-verbose + enable trace output + +-base=BASE + regard numbers in base BASE. Default: 10 + +N... + list of numbers + +EOS + + +### Input and Output + +say cedn($base, @ARGV); + + +### Implementation + +sub cedn { + my $base = shift; + scalar grep !(scalar(todigits($_, $base)) % 2), @_ +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is cedn(10 => 10, 1, 111, 24, 1000), 3, 'example 1'; + is cedn(10 => 111, 1, 11111), 0, 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
