aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-02-14 18:42:16 +0000
committerGitHub <noreply@github.com>2021-02-14 18:42:16 +0000
commit376078ff5e9756583c9a30379941a42dbf2d88b5 (patch)
tree611522c1cea84447f0670d082dccab41f01b7c38
parent9b3200fe6ced2d6175feeba7ed832cd2477a1e45 (diff)
parente8430b12f5eb20e6551e17a8863fc83c26d4bd4b (diff)
downloadperlweeklychallenge-club-376078ff5e9756583c9a30379941a42dbf2d88b5.tar.gz
perlweeklychallenge-club-376078ff5e9756583c9a30379941a42dbf2d88b5.tar.bz2
perlweeklychallenge-club-376078ff5e9756583c9a30379941a42dbf2d88b5.zip
Merge pull request #3519 from mimosinnet/branch-for-challenge-099
Solution for challenge 099
-rw-r--r--challenge-099/mimosinnet/raku/ch-1.raku41
-rw-r--r--challenge-099/mimosinnet/raku/ch-2.raku41
2 files changed, 82 insertions, 0 deletions
diff --git a/challenge-099/mimosinnet/raku/ch-1.raku b/challenge-099/mimosinnet/raku/ch-1.raku
new file mode 100644
index 0000000000..abfc71ad41
--- /dev/null
+++ b/challenge-099/mimosinnet/raku/ch-1.raku
@@ -0,0 +1,41 @@
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-099/
+
+#|
+sub challenge( $string, $pattern is copy ) {
+ $pattern = '^' ~ $pattern.trans( [ '*', '?' ] => [ '.*' , '.' ]) ~ '$' ;
+ $string ~~ /<$pattern>/ ?? 1 !! 0;
+}
+
+multi sub MAIN( $string, $pattern ) {
+ say 'Input: $S = "',$string,'" $P = "', $pattern, '"';
+ say 'Output: ',challenge($string, $pattern),"\n";
+}
+
+multi sub MAIN( 'challenge' ) {
+ my @challenge = (
+ ( 'abcde', 'a*e'),
+ ( 'abcde', 'a*d'),
+ ( 'abcde', '?b*d'),
+ ( 'abcde', 'a*c?e'),
+ );
+
+ for @challenge -> ($a, $b) {
+ MAIN($a,$b);
+ }
+}
+
+multi sub MAIN( 'test' ) {
+ use Test;
+
+ my @tests = (
+ ( 'abcde', 'a*e', 1),
+ ( 'abcde', 'a*d', 0),
+ ( 'abcde', '?b*d', 0),
+ ( 'abcde', 'a*c?ei', 0),
+ );
+
+ for @tests -> ($a, $b, $c) {
+ is challenge($a, $b), $c;
+ }
+
+}
diff --git a/challenge-099/mimosinnet/raku/ch-2.raku b/challenge-099/mimosinnet/raku/ch-2.raku
new file mode 100644
index 0000000000..be2abd0fee
--- /dev/null
+++ b/challenge-099/mimosinnet/raku/ch-2.raku
@@ -0,0 +1,41 @@
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-099/
+
+# I have been stuck for a while in this challenge,
+# and I have looked at aaronreidsmith solution.
+# This is based on aaronreidsmith.
+
+#|
+sub challenge( $string, $pattern is copy ) {
+ $pattern = $pattern.comb.join('.*') ;
+ $string.match( /<$pattern>/, :exhaustive).elems;
+}
+
+multi sub MAIN( $string, $pattern ) {
+ say 'Input: $S = "',$string,'", $T = "',$pattern,'"';
+ say 'Output: ',challenge($string,$pattern),"\n";
+}
+
+multi sub MAIN( 'challenge' ) {
+ my @challenge = (
+ ( 'littleit', 'lit' ),
+ ( 'london' , 'lon' )
+ );
+
+ for @challenge -> ($a, $b) {
+ MAIN( $a, $b);
+ }
+}
+
+multi sub MAIN( 'test' ) {
+ use Test;
+
+ my @test = (
+ ( 'littleit', 'lit', 5 ),
+ ( 'london' , 'lon', 3 )
+ );
+
+ for @test -> ($a, $b, $c) {
+ is challenge( $a, $b), $c;
+ }
+
+}