diff options
| -rw-r--r-- | challenge-063/simon-proctor/raku/ch-1.raku | 13 | ||||
| -rw-r--r-- | challenge-063/simon-proctor/raku/ch-2.raku | 21 |
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-063/simon-proctor/raku/ch-1.raku b/challenge-063/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..ed1092c70c --- /dev/null +++ b/challenge-063/simon-proctor/raku/ch-1.raku @@ -0,0 +1,13 @@ +#!/usr/bin/env raku + +use v6.d; + +sub last_word( Str $sentence, Regex $test ) { + $sentence.words.reverse.first( $test ); +} + +# Test Last_word +say last_word(' hello world', rx/<[ea]>l/); # 'hello' +say last_word("Don't match too much, Chet!", rx:i/ch.t/); # 'Chet!' +say last_word("spaces in regexp won't match", rx/"in re"/); # undef +say last_word( join(' ', 1..1e6), rx/^(3.*?) ** 3/); # '399933' diff --git a/challenge-063/simon-proctor/raku/ch-2.raku b/challenge-063/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..2696b581f6 --- /dev/null +++ b/challenge-063/simon-proctor/raku/ch-2.raku @@ -0,0 +1,21 @@ +#!/usr/bin/env raku + +use v6.d; + +#| Given a string home many rotations are needed (see the challenge for the rules on rotations). +sub MAIN ( Str $input where m!^<[xy]>+$! ) { + my Int $i = 1; + my Str $rotated = rotate_string( $input, $i ); + + while ( $rotated !~~ $input ) { + $i++; + $rotated = rotate_string( $rotated, $i ); + } + + say $i; +} + +sub rotate_string( Str $rotated, Int $i ) { + my $midpoint = $i % $rotated.codes; + "{$rotated.substr($midpoint,$rotated.codes-$midpoint)}{$rotated.substr(0,$midpoint)}"; +} |
