diff options
| -rwxr-xr-x | challenge-145/luca-ferrari/raku/ch-2.p6 | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-145/luca-ferrari/raku/ch-2.p6 b/challenge-145/luca-ferrari/raku/ch-2.p6 new file mode 100755 index 0000000000..97202d578c --- /dev/null +++ b/challenge-145/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,26 @@ +#!raku +sub MAIN( Str $s = 'redivider' ) { + + my @roots; + my @chars = $s.comb; + + for 0 ..^ @chars.elems -> $current { + my $current-root = @chars[ $current ]; + + + for $current + 1 ..^ @chars.elems -> $other { + next if @chars[ $other ] !~~ $current-root; + + my $string = @chars[ $current .. $other ].join; + + if ( $string ~~ $string.flip ) { + @roots.push: [ $current-root, $string ]; + last; + } + } + + @roots.push: [ $current-root, '' ] if ! @roots.grep({ $_[ 0 ] ~~ $current-root } ); + } + + "$_[0] = $_[1]".say for @roots; +} |
