aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Smith <asmith@sumologic.com>2021-02-13 12:58:26 -0600
committerAaron Smith <asmith@sumologic.com>2021-02-13 12:58:26 -0600
commit4b6337b51c4f4715fd6abb380fed9307a6ad504a (patch)
tree2d6e82acf821d032798ac3981ccf43168b6dd696
parent323110b0d053e2067a3cae6db62bc209f869bc57 (diff)
downloadperlweeklychallenge-club-4b6337b51c4f4715fd6abb380fed9307a6ad504a.tar.gz
perlweeklychallenge-club-4b6337b51c4f4715fd6abb380fed9307a6ad504a.tar.bz2
perlweeklychallenge-club-4b6337b51c4f4715fd6abb380fed9307a6ad504a.zip
Challenge 99 - Raku
-rw-r--r--challenge-099/aaronreidsmith/blog.txt1
-rw-r--r--challenge-099/aaronreidsmith/raku/ch-1.raku28
-rw-r--r--challenge-099/aaronreidsmith/raku/ch-2.raku26
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;
+}
+