From 7aabb5c6c9021adb0510e653d7deffb72f6e13af Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 15 Jun 2020 10:12:18 +0200 Subject: Task 1 done. --- challenge-065/luca-ferrari/raku/ch-1.p6 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 challenge-065/luca-ferrari/raku/ch-1.p6 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..c1337e9fbd --- /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 > 0 } ) { + + + 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; + +} -- cgit From 19e6acc3823b40bf860a3cdf05f47613ea7ed311 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 15 Jun 2020 11:15:05 +0200 Subject: Task 2 done. --- challenge-065/luca-ferrari/raku/ch-1.p6 | 2 +- challenge-065/luca-ferrari/raku/ch-2.p6 | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 challenge-065/luca-ferrari/raku/ch-2.p6 diff --git a/challenge-065/luca-ferrari/raku/ch-1.p6 b/challenge-065/luca-ferrari/raku/ch-1.p6 index c1337e9fbd..15d37d9766 100644 --- a/challenge-065/luca-ferrari/raku/ch-1.p6 +++ b/challenge-065/luca-ferrari/raku/ch-1.p6 @@ -16,7 +16,7 @@ sub MAIN( Int $N where { $N > 0 }, - Int $S where { $S > 0 } ) { + Int $S where { $S >= 1 && $S <= 9 } ) { my @found; 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"; +} -- cgit From 731e2715bf3a5fee96d708e19bbb8497db98de0c Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 15 Jun 2020 11:36:28 +0200 Subject: Blog references. --- challenge-065/luca-ferrari/blog-1.txt | 1 + challenge-065/luca-ferrari/blog-2.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 challenge-065/luca-ferrari/blog-1.txt create mode 100644 challenge-065/luca-ferrari/blog-2.txt 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 -- cgit