diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-04-03 17:11:42 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-04-19 18:48:48 +0200 |
| commit | de1eff9d708294f0b792abfc818fba8ea649f05c (patch) | |
| tree | 246b5086e68f2077eef43bc81c10af5adf446953 | |
| parent | 272ebe60462117f69703b6fab517eadb8ed43f81 (diff) | |
| download | perlweeklychallenge-club-de1eff9d708294f0b792abfc818fba8ea649f05c.tar.gz perlweeklychallenge-club-de1eff9d708294f0b792abfc818fba8ea649f05c.tar.bz2 perlweeklychallenge-club-de1eff9d708294f0b792abfc818fba8ea649f05c.zip | |
Challenge 049 task 1
| -rwxr-xr-x | challenge-049/jo-37/perl/ch-1.pl | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/challenge-049/jo-37/perl/ch-1.pl b/challenge-049/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..87df8f6094 --- /dev/null +++ b/challenge-049/jo-37/perl/ch-1.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; +use Math::Prime::Util qw(todigits fromdigits todigitstring); +use experimental 'signatures'; + +our ($tests, $examples); + +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 + find the smalles zero-one product of N + +EOS + + +### Input and Output + +say mult01(shift); + + +### Implementation + +# Interpret the binary representation of a number as decimal. This +# enumerates the possible products. +sub mult01 ($n) { + my $i; + 0 while fromdigits([todigits ++$i, 2]) % $n; + todigitstring($i, 2); +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is mult01(55), 110, 'example'; + } + + SKIP: { + skip "tests" unless $tests; + + is mult01(333), 111111111; + is mult01(33333), 111111111111111; + } + + done_testing; + exit; +} |
