diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-02-14 04:03:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-14 04:03:58 +0000 |
| commit | 3ae730c1e6f1c97d68e7d808b2b039560275d956 (patch) | |
| tree | b34cf07060b2d00545f67a95067a0813c3c3c647 | |
| parent | b122f1d67de0344563df2c3f31e0b97cc70a4a5f (diff) | |
| parent | 4b6337b51c4f4715fd6abb380fed9307a6ad504a (diff) | |
| download | perlweeklychallenge-club-3ae730c1e6f1c97d68e7d808b2b039560275d956.tar.gz perlweeklychallenge-club-3ae730c1e6f1c97d68e7d808b2b039560275d956.tar.bz2 perlweeklychallenge-club-3ae730c1e6f1c97d68e7d808b2b039560275d956.zip | |
Merge pull request #3511 from aaronreidsmith/challenge-099
Challenge 99 - Raku
| -rw-r--r-- | challenge-099/aaronreidsmith/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-099/aaronreidsmith/raku/ch-1.raku | 28 | ||||
| -rw-r--r-- | challenge-099/aaronreidsmith/raku/ch-2.raku | 26 |
3 files changed, 55 insertions, 0 deletions
diff --git a/challenge-099/aaronreidsmith/blog.txt b/challenge-099/aaronreidsmith/blog.txt new file mode 100644 index 0000000000..56cee9a8f8 --- /dev/null +++ b/challenge-099/aaronreidsmith/blog.txt @@ -0,0 +1 @@ +https://aaronreidsmith.github.io/blog/perl-weekly-challenge-099/ diff --git a/challenge-099/aaronreidsmith/raku/ch-1.raku b/challenge-099/aaronreidsmith/raku/ch-1.raku new file mode 100644 index 0000000000..7fd01ed7ac --- /dev/null +++ b/challenge-099/aaronreidsmith/raku/ch-1.raku @@ -0,0 +1,28 @@ +#!/usr/bin/env raku + +sub challenge(Str $S, Str $P) returns Int { + my $regex = '^' ~ $P.trans(['*', '?'] => ['.*', '.']) ~ '$'; + ($S ~~ /<$regex>/).Bool.Int; +} + +multi sub MAIN(Str $S, Str $P) { + say challenge($S, $P); +} + +multi sub MAIN(Bool :$test) { + use Test; + + my @tests = ( + ('abcde', 'a*e' , 1), + ('abcde', 'a*d' , 0), + ('abcde', '?b*d' , 0), + ('abcde', 'a*c?e', 1), + ('acde' , 'a*c?e', 1) # Treat '*' as '0 or more' + ); + + for @tests -> ($S, $P, $expected) { + is(challenge($S, $P), $expected); + } + + done-testing; +} diff --git a/challenge-099/aaronreidsmith/raku/ch-2.raku b/challenge-099/aaronreidsmith/raku/ch-2.raku new file mode 100644 index 0000000000..376d3c46dd --- /dev/null +++ b/challenge-099/aaronreidsmith/raku/ch-2.raku @@ -0,0 +1,26 @@ +#!/usr/bin/env raku + +sub challenge(Str $S, Str $T) returns Int { + my $regex = $T.comb.join('.*'); + ($S ~~ m:exhaustive/<$regex>/).Int; +} + +multi sub MAIN(Str $S, Str $T) { + say challenge($S, $T); +} + +multi sub MAIN(Bool :$test) { + use Test; + + my @tests = ( + ('littleit', 'lit', 5), + ('london' , 'lon', 3) + ); + + for @tests -> ($S, $T, $expected) { + is(challenge($S, $T), $expected); + } + + done-testing; +} + |
