aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-065/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-065/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-065/luca-ferrari/raku/ch-1.p630
-rw-r--r--challenge-065/luca-ferrari/raku/ch-2.p632
4 files changed, 64 insertions, 0 deletions
diff --git a/challenge-065/luca-ferrari/blog-1.txt b/challenge-065/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..9599f014c5
--- /dev/null
+++ b/challenge-065/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/06/15/PerlWeeklyChallenge65.html#task1
diff --git a/challenge-065/luca-ferrari/blog-2.txt b/challenge-065/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..f5d845885d
--- /dev/null
+++ b/challenge-065/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/06/15/PerlWeeklyChallenge65.html#task2
diff --git a/challenge-065/luca-ferrari/raku/ch-1.p6 b/challenge-065/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..15d37d9766
--- /dev/null
+++ b/challenge-065/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,30 @@
+#!raku
+
+# You are given two positive numbers $N and $S.
+#
+# Write a script to list all positive numbers having
+# exactly $N digits where sum of all digits equals to $S.
+# Example
+#
+# Input:
+# $N = 2
+# $S = 4
+#
+# Output:
+# 13, 22, 31, 40
+
+
+
+sub MAIN( Int $N where { $N > 0 },
+ Int $S where { $S >= 1 && $S <= 9 } ) {
+
+
+ my @found;
+ "Searching numbers with $N digits that sum to $S between { 1 ~ ( 0 x $N - 1 ) } and { $S ~ ( 0 x $N - 1 ) }".say;
+ for ( 1 ~ ( 0 x $N - 1 ) ).Int .. ( $S ~ ( 0 x $N - 1 ) ).Int {
+ @found.push: $_ if ( [+] $_.split( '', :skip-empty ) ) == $S ;
+ }
+
+ @found.say;
+
+}
diff --git a/challenge-065/luca-ferrari/raku/ch-2.p6 b/challenge-065/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..a30cca8246
--- /dev/null
+++ b/challenge-065/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,32 @@
+#!raku
+
+# You are given a string $S. Write a script print all possible partitions that gives Palindrome.
+# Return -1 if none found.
+# Please make sure, partition should not overlap.
+# For example, for given string “abaab”,
+# the partition “aba” and “baab” would not be valid, since they overlap.
+
+
+sub MAIN( Str $S where { $S.chars > 0 } = "abaab" ){
+ "Searching non overlapping palindrome partitions on $S".say;
+ my @palindromes;
+
+ my $last = -1;
+ for 0 ..^ $S.chars -> $start {
+ # avoid overlapping
+ next if $start <= $last;
+
+ for $start + 1 ..^ $S.chars -> $end {
+ my $string = $S.split( '', :skip-empty )[ $start .. $end ];
+ if $string ~~ $string.reverse {
+ @palindromes.push: $string;
+ # avoid overlapping
+ $last = $end;
+ last;
+ }
+
+ }
+ }
+
+ @palindromes ?? @palindromes.join( ',' ).say !! "-1";
+}