aboutsummaryrefslogtreecommitdiff
path: root/challenge-065
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-06-19 17:45:04 +0100
committerGitHub <noreply@github.com>2020-06-19 17:45:04 +0100
commitb3462034afc18652e17c27e536e9d6c4c5185e11 (patch)
tree1a83f5e14c09fdd1c24865fe1eb5e8307810774f /challenge-065
parentd2824534cadfc66e1767bf420edb071e090d530c (diff)
parentb0d6b0e2bdf76954b99720a4a723251a19506d3c (diff)
downloadperlweeklychallenge-club-b3462034afc18652e17c27e536e9d6c4c5185e11.tar.gz
perlweeklychallenge-club-b3462034afc18652e17c27e536e9d6c4c5185e11.tar.bz2
perlweeklychallenge-club-b3462034afc18652e17c27e536e9d6c4c5185e11.zip
Merge pull request #1837 from Scimon/master
Think this works
Diffstat (limited to 'challenge-065')
-rw-r--r--challenge-065/simon-proctor/raku/ch-2.raku31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-065/simon-proctor/raku/ch-2.raku b/challenge-065/simon-proctor/raku/ch-2.raku
new file mode 100644
index 0000000000..85bc73ae4c
--- /dev/null
+++ b/challenge-065/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,31 @@
+#!/usr/bin/env raku
+
+use v6;
+
+sub MAIN (
+ Str $target #= String to search for palindromes.
+) {
+ my $found = False;
+ for ^$target.codes -> $start {
+ my @palindromes = find-palindromes( $target.substr( $start ) );
+ if @palindromes.grep( so * ) {
+ $found = True;
+ for @palindromes { .join(", ").say };
+ }
+ }
+ say -1 if ! $found;
+}
+
+sub infix:<|,|> (@a,@b) { |@a, |@b }
+
+sub find-palindromes( Str $target ) {
+ my @out;
+ for 2..$target.codes -> $length {
+ my $check = $target.substr( 0, $length );
+ if $check ~~ $check.flip {
+ my @rest = find-palindromes( $target.substr( $length ) );
+ @out = @out |,| ( [ [ $check, ], ] X|,| @rest );
+ }
+ }
+ return @out || [[],];
+}