From ec8f028287cbc4b32752c85abe16e359d009144a Mon Sep 17 00:00:00 2001 From: "Markus \"Holli\" Holzer" Date: Wed, 3 Jun 2020 01:01:46 +0200 Subject: a bit nicer --- challenge-063/markus-holzer/ch-1.raku | 10 +++++----- challenge-063/markus-holzer/ch-2.raku | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/challenge-063/markus-holzer/ch-1.raku b/challenge-063/markus-holzer/ch-1.raku index d4eedaf53e..7336e63f9c 100644 --- a/challenge-063/markus-holzer/ch-1.raku +++ b/challenge-063/markus-holzer/ch-1.raku @@ -1,8 +1,8 @@ -sub last-word($string, $regexp) +sub last-word( Str $sentence, Regex $matcher ) { - $string.words.grep( $regexp ).tail; + $sentence.words.grep( $matcher ).tail; } -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/ \s re /); # undef +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/ \s re / ); # undef diff --git a/challenge-063/markus-holzer/ch-2.raku b/challenge-063/markus-holzer/ch-2.raku index 2bc8aff3fe..a61e77052f 100644 --- a/challenge-063/markus-holzer/ch-2.raku +++ b/challenge-063/markus-holzer/ch-2.raku @@ -1,19 +1,19 @@ -say r('xyxx'); - -multi sub r( Str $orig ) +multi sub rotmodN( Str $orig ) { - r $orig.comb.List + rotmodN $orig.comb.List } -multi sub r( List $orig ) +multi sub rotmodN ( List $orig, $n = $orig.elems ) { my $work = $orig; - for ( 1 .. Inf ).map( * % 4 ).kv -> $n, $by + for ( 1 .. Inf ).map( * % $n ).kv -> $i, $by { $work = $work.rotate: $by; - return $n + 1 - if $work cmp $orig == Same; + return $i + 1 + if $work cmp $orig == Same; } -} \ No newline at end of file +} + +say rotmodN 'xyxx'; \ No newline at end of file -- cgit