diff options
| author | mimosinnet <mimosinnet@gmail.com> | 2021-02-14 19:27:23 +0100 |
|---|---|---|
| committer | mimosinnet <mimosinnet@gmail.com> | 2021-02-14 19:27:23 +0100 |
| commit | e8430b12f5eb20e6551e17a8863fc83c26d4bd4b (patch) | |
| tree | 6d88a2713565674256aa6839d155d0b8251a1a10 | |
| parent | 4e54fca523d11ae55bfe4cef8a59965278762642 (diff) | |
| download | perlweeklychallenge-club-e8430b12f5eb20e6551e17a8863fc83c26d4bd4b.tar.gz perlweeklychallenge-club-e8430b12f5eb20e6551e17a8863fc83c26d4bd4b.tar.bz2 perlweeklychallenge-club-e8430b12f5eb20e6551e17a8863fc83c26d4bd4b.zip | |
Solution for challenge 099
| -rw-r--r-- | challenge-099/mimosinnet/raku/ch-1.raku | 41 | ||||
| -rw-r--r-- | challenge-099/mimosinnet/raku/ch-2.raku | 41 |
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; + } + +} |
