diff options
| -rwxr-xr-x | challenge-340/simon-proctor/raku/ch-1.raku | 25 | ||||
| -rwxr-xr-x | challenge-340/simon-proctor/raku/ch-2.raku | 20 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-340/simon-proctor/raku/ch-1.raku b/challenge-340/simon-proctor/raku/ch-1.raku new file mode 100755 index 0000000000..af190284e9 --- /dev/null +++ b/challenge-340/simon-proctor/raku/ch-1.raku @@ -0,0 +1,25 @@ +#!/usr/bin/env raku + +subset IsTrue of Bool where so *; + +multi sub MAIN( IsTrue :t(:$test) ) is hidden-from-USAGE { + use Test; + is strip-dupes('abbaca'), 'ca'; + is strip-dupes('azxxzy'), 'ay'; + is strip-dupes('aaaaaaaa'), ''; + is strip-dupes('aabccba'), 'a'; + is strip-dupes('abcddcba'), ''; + done-testing; +} + +multi sub MAIN( Str() $s ) { strip-dupes($s).say; } + +sub strip-dupes( Str $s is copy ) { + my $old = $s; + repeat { + $old = $s; + $s ~~ s:g/(.)$0//; + } until ( $old ~~ $s ); + $s; +} + diff --git a/challenge-340/simon-proctor/raku/ch-2.raku b/challenge-340/simon-proctor/raku/ch-2.raku new file mode 100755 index 0000000000..84dbca259a --- /dev/null +++ b/challenge-340/simon-proctor/raku/ch-2.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +subset IsTrue of Bool where so *; + +multi sub MAIN( IsTrue :t(:$test) ) is hidden-from-USAGE { + use Test; + ok ascending("The cat has 3 kittens 7 toys 10 beds"); + nok ascending('Alice bought 5 apples 2 oranges 9 bananas'); + ok ascending('I ran 1 mile 2 days 3 weeks 4 months'); + nok ascending('Bob has 10 cars 10 bikes'); + ok ascending('Zero is 0 one is 1 two is 2'); + done-testing; +} + +multi sub MAIN( Str $s ) { ascending($s).say; } +multi sub MAIN( *@s ) { ascending( @s.join(" ") ).say; } + +sub ascending( Str $s ) { + [<] $s.comb(/\d+/); +} |
