diff options
Diffstat (limited to 'challenge-063/arne-sommer/raku')
| -rwxr-xr-x | challenge-063/arne-sommer/raku/ch-1.p6 | 21 | ||||
| -rwxr-xr-x | challenge-063/arne-sommer/raku/ch-2.p6 | 36 | ||||
| -rwxr-xr-x | challenge-063/arne-sommer/raku/lawo | 21 | ||||
| -rwxr-xr-x | challenge-063/arne-sommer/raku/rostr | 36 |
4 files changed, 114 insertions, 0 deletions
diff --git a/challenge-063/arne-sommer/raku/ch-1.p6 b/challenge-063/arne-sommer/raku/ch-1.p6 new file mode 100755 index 0000000000..064388d9ef --- /dev/null +++ b/challenge-063/arne-sommer/raku/ch-1.p6 @@ -0,0 +1,21 @@ +#! /usr/bin/env raku + +unit sub MAIN (:$verbose); + +sub last_word ($string, Regex $regex) +{ + say ": String: $string" if $verbose; + + for $string.split(/\s/).reverse -> $word + { + say ": Word: $word (regex: { $regex.gist })" if $verbose; + + return $word if $word ~~ $regex; + } + return; +} + +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/in re/); # undef +say last_word( join(' ', 1..1e6), rx/^(3.*?) ** 3 /); # '399933' diff --git a/challenge-063/arne-sommer/raku/ch-2.p6 b/challenge-063/arne-sommer/raku/ch-2.p6 new file mode 100755 index 0000000000..1e81450e5e --- /dev/null +++ b/challenge-063/arne-sommer/raku/ch-2.p6 @@ -0,0 +1,36 @@ +#! /usr/bin/env raku + +subset XY where /^<[xy]>+$/; + +sub MAIN (XY $string = 'xyxx', :$verbose) +{ + my $length = $string.chars; + my $current = $string; + + my $count = 0; + + loop + { + $count++; + + my $rotate = $count % $length; + + if $rotate + { + my $a = $current.substr($rotate); + my $b = $current.substr(0, $rotate); + + $current = $a ~ $b; + + say ": Rotation $count: $current (moved '$b' to the end)" if $verbose; + } + elsif $verbose + { + say ": Rotation $count: $current (moved nothing)"; + } + + last if $current eq $string; + } + + say "$count Rotations"; +} diff --git a/challenge-063/arne-sommer/raku/lawo b/challenge-063/arne-sommer/raku/lawo new file mode 100755 index 0000000000..064388d9ef --- /dev/null +++ b/challenge-063/arne-sommer/raku/lawo @@ -0,0 +1,21 @@ +#! /usr/bin/env raku + +unit sub MAIN (:$verbose); + +sub last_word ($string, Regex $regex) +{ + say ": String: $string" if $verbose; + + for $string.split(/\s/).reverse -> $word + { + say ": Word: $word (regex: { $regex.gist })" if $verbose; + + return $word if $word ~~ $regex; + } + return; +} + +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/in re/); # undef +say last_word( join(' ', 1..1e6), rx/^(3.*?) ** 3 /); # '399933' diff --git a/challenge-063/arne-sommer/raku/rostr b/challenge-063/arne-sommer/raku/rostr new file mode 100755 index 0000000000..1e81450e5e --- /dev/null +++ b/challenge-063/arne-sommer/raku/rostr @@ -0,0 +1,36 @@ +#! /usr/bin/env raku + +subset XY where /^<[xy]>+$/; + +sub MAIN (XY $string = 'xyxx', :$verbose) +{ + my $length = $string.chars; + my $current = $string; + + my $count = 0; + + loop + { + $count++; + + my $rotate = $count % $length; + + if $rotate + { + my $a = $current.substr($rotate); + my $b = $current.substr(0, $rotate); + + $current = $a ~ $b; + + say ": Rotation $count: $current (moved '$b' to the end)" if $verbose; + } + elsif $verbose + { + say ": Rotation $count: $current (moved nothing)"; + } + + last if $current eq $string; + } + + say "$count Rotations"; +} |
