aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-099/simon-proctor/raku/ch-1.raku28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-099/simon-proctor/raku/ch-1.raku b/challenge-099/simon-proctor/raku/ch-1.raku
new file mode 100644
index 0000000000..5c5b47b161
--- /dev/null
+++ b/challenge-099/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,28 @@
+#!/usr/bin/env raku
+
+use v6;
+
+#| Given a string and a simple pattern see if the string matches the pattern
+multi sub MAIN(
+ Str $S, #= String to check
+ Str $P, #={ Pattern to match :
+? - Matches a single character :
+* - Matches any number of characters
+}
+) {
+ my $regex = generate-regex( $P );
+ say $S.match($regex) ?? 1 !! 0;
+}
+
+sub generate-regex( $P ) {
+ my @chars = [ '^', |$P.comb.map(
+ -> $c {
+ given $c {
+ when "*" { ".*" };
+ when "?" { "." };
+ default { "'$c'" };
+ }
+ }
+ ), '$' ];
+ return rx/<{@chars.join(" ")}>/;
+}