aboutsummaryrefslogtreecommitdiff
path: root/challenge-145
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2021-12-29 09:23:15 +0100
committerLuca Ferrari <fluca1978@gmail.com>2021-12-29 09:23:15 +0100
commit4d9d354f7e8fb47afbd3ed6c5805dc837a9e8d29 (patch)
treede11251f28849de77ba81bd9665852ce46a6d557 /challenge-145
parent12828ab4269a983570736b0bd17299c32eae1b27 (diff)
downloadperlweeklychallenge-club-4d9d354f7e8fb47afbd3ed6c5805dc837a9e8d29.tar.gz
perlweeklychallenge-club-4d9d354f7e8fb47afbd3ed6c5805dc837a9e8d29.tar.bz2
perlweeklychallenge-club-4d9d354f7e8fb47afbd3ed6c5805dc837a9e8d29.zip
Task 2 done
Diffstat (limited to 'challenge-145')
-rwxr-xr-xchallenge-145/luca-ferrari/raku/ch-2.p626
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;
+}