aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-11-30 01:48:16 +0000
committerGitHub <noreply@github.com>2020-11-30 01:48:16 +0000
commit93f26f4321a1e8d721b271fe569f094e25b2941b (patch)
tree6956a94633aba9315ef1564d69a7ccb1b8793538
parent2377df6c00f13b29f8c1443e15128a1db7ff9c5c (diff)
parented6b726acc50043116387d0d61168da847e9b512 (diff)
downloadperlweeklychallenge-club-93f26f4321a1e8d721b271fe569f094e25b2941b.tar.gz
perlweeklychallenge-club-93f26f4321a1e8d721b271fe569f094e25b2941b.tar.bz2
perlweeklychallenge-club-93f26f4321a1e8d721b271fe569f094e25b2941b.zip
Merge pull request #2880 from stuart-little/stuart-little_065
1st commit on 065
-rw-r--r--challenge-065/stuart-little/README1
-rwxr-xr-xchallenge-065/stuart-little/raku/ch-1.p611
-rwxr-xr-xchallenge-065/stuart-little/raku/ch-2.p627
3 files changed, 39 insertions, 0 deletions
diff --git a/challenge-065/stuart-little/README b/challenge-065/stuart-little/README
new file mode 100644
index 0000000000..78439907de
--- /dev/null
+++ b/challenge-065/stuart-little/README
@@ -0,0 +1 @@
+Solutions by Stuart Little
diff --git a/challenge-065/stuart-little/raku/ch-1.p6 b/challenge-065/stuart-little/raku/ch-1.p6
new file mode 100755
index 0000000000..b05bb2776d
--- /dev/null
+++ b/challenge-065/stuart-little/raku/ch-1.p6
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl6
+use v6;
+
+sub digsum($n,$s) {
+ ((10 ** ($n-1))..^(10 ** $n)).grep({ $_.comb.sum == $s })
+}
+
+say digsum(@*ARGS[0], @*ARGS[1])
+
+# run as <script> <nr of digits> <digit sum>
+
diff --git a/challenge-065/stuart-little/raku/ch-2.p6 b/challenge-065/stuart-little/raku/ch-2.p6
new file mode 100755
index 0000000000..754010d2af
--- /dev/null
+++ b/challenge-065/stuart-little/raku/ch-2.p6
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl6
+use v6;
+
+sub is_pal($s) {
+ $s.chars >=1 && ($s eq $s.flip)
+}
+
+sub start_pal_indices($s) {
+ (1..$s.chars).grep({ $s.substr(0..^$_).&is_pal })
+}
+
+sub part_pal($s) {
+ $s eq '' && return ((),);
+ $s.chars==1 && return (($s,),);
+ return $s.&start_pal_indices.map({ $s.substr($_).&part_pal.map( -> @p {($s.substr(0..^$_),|@p)}) }).map(|*)
+}
+
+for @*ARGS[0].&part_pal.classify(*.elems).min(*.key) {.say}
+
+=finish
+run as <script> <string>
+
+Due to the ambiguity in the original problem I elected to implement
+
+https://leetcode.com/problems/palindrome-partitioning-ii/description/
+
+instead.