diff options
| -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; +} + |
