diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-19 16:51:45 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-23 18:03:43 +0100 |
| commit | 39788799057dc2c8a7aaf3821c9d84b1383a1e63 (patch) | |
| tree | 220665f4904f6a3f97a136098c4d89cbb393a205 | |
| parent | e4508767cb48be672ec35bbd4bc7d1645640af4e (diff) | |
| download | perlweeklychallenge-club-39788799057dc2c8a7aaf3821c9d84b1383a1e63.tar.gz perlweeklychallenge-club-39788799057dc2c8a7aaf3821c9d84b1383a1e63.tar.bz2 perlweeklychallenge-club-39788799057dc2c8a7aaf3821c9d84b1383a1e63.zip | |
Challenge 026 task 1
| -rwxr-xr-x | challenge-026/jo-37/perl/ch-1.pl | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/challenge-026/jo-37/perl/ch-1.pl b/challenge-026/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..987a7e3388 --- /dev/null +++ b/challenge-026/jo-37/perl/ch-1.pl @@ -0,0 +1,57 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use warnings FATAL => 'all'; +use Data::Dump qw(dd pp); +use experimental qw(signatures postderef); + +our ($tests, $examples, $verbose); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV == 2; +usage: $0 [-examples] [-tests] [STONES JEWELS] + +-examples + run the examples from the challenge + +-tests + run some tests + +STONES JEWELS + count alphabet from STONES in JEWELS + +EOS + + +### Input and Output + +say count_alphabet(@ARGV); + + +### Implementation + +sub count_alphabet ($stones, $jewels) { + my %jewels; + @jewels{split //, $jewels} = (1) x length($jewels); + scalar grep $_, @jewels{split //, $stones}; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is count_alphabet("chancellor", "chocolate"), 8, 'example'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
