aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-04-22 16:18:33 +0100
committerGitHub <noreply@github.com>2021-04-22 16:18:33 +0100
commit2761252ba87bfe7a3fce5177b451bbb25fae7886 (patch)
treef8ed8c3b5b43542e28586b53c230d8fa18416e13
parent7aceed58d0b3a13b7baa554fb14fa1c6b606bc10 (diff)
parent08b7e089cd6637a5ca674b022f680808d2e763f8 (diff)
downloadperlweeklychallenge-club-2761252ba87bfe7a3fce5177b451bbb25fae7886.tar.gz
perlweeklychallenge-club-2761252ba87bfe7a3fce5177b451bbb25fae7886.tar.bz2
perlweeklychallenge-club-2761252ba87bfe7a3fce5177b451bbb25fae7886.zip
Merge pull request #3941 from fluca1978/pwc109
Pwc109
-rw-r--r--challenge-109/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-109/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-109/luca-ferrari/raku/ch-1.p620
-rw-r--r--challenge-109/luca-ferrari/raku/ch-2.p635
4 files changed, 57 insertions, 0 deletions
diff --git a/challenge-109/luca-ferrari/blog-1.txt b/challenge-109/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..c983cf6c1b
--- /dev/null
+++ b/challenge-109/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/04/22/PerlWeeklyChallenge109.html#task1
diff --git a/challenge-109/luca-ferrari/blog-2.txt b/challenge-109/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..c079f7971f
--- /dev/null
+++ b/challenge-109/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/04/22/PerlWeeklyChallenge109.html#task2
diff --git a/challenge-109/luca-ferrari/raku/ch-1.p6 b/challenge-109/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..58168f713c
--- /dev/null
+++ b/challenge-109/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,20 @@
+#!perl6
+
+#
+# C(n) = sum of divisors of n except 1 and n
+#
+sub choowla( Int $n where { $n > 0 } ) {
+ # special case
+ return 0 if $n < 2;
+
+ # get all divisors
+ # my @divisors.push: $_ if $n %% $_ for 2 .. $n / 2;
+ # return [+] @divisors;
+ return [+] ( $_ if $n %% $_ for 2 .. $n / 2 );
+}
+
+sub MAIN( Int $limit = 20 ) {
+ # my @choowla-numbers.push: choowla( $_ ) for 1 .. $limit;
+ # @choowla-numbers.join( ',' ).say;
+ @( choowla( $_ ) for 1 .. $limit ).join( ',' ).say;
+}
diff --git a/challenge-109/luca-ferrari/raku/ch-2.p6 b/challenge-109/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..4a9117f636
--- /dev/null
+++ b/challenge-109/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,35 @@
+#!raku
+
+
+multi sub MAIN( *@nums where { @nums.grep( * ~~ Int ).elems == @nums.elems && @nums.elems == 7 } ) {
+ my @letters = 'a' .. 'g';
+ my @solutions;
+
+ # permutate all numbers to find out the correct sum
+ for @nums.permutations -> @current {
+ # build an hash to help visualize the answer
+ my %squares;
+ %squares{ @letters[ $_ ] } = @current[ $_ ] for 0 ..^ @letters.elems;
+
+ # compute the sums
+ my @sums;
+ @sums.push: [+] %squares{ 'a' .. 'b' };
+ @sums.push: [+] %squares{ 'b' .. 'd' };
+ @sums.push: [+] %squares{ 'd' .. 'f' };
+ @sums.push: [+] %squares{ 'f' .. 'g' };
+
+
+ # if the first sum is equal to all the others, push this solution
+ @solutions.push: %squares if @sums[ 0 ] == all @sums[ 1 .. * ];
+ }
+
+
+
+ say $_ for @solutions;
+
+}
+
+
+multi sub MAIN() {
+ MAIN( <1 2 3 4 5 6 7> );
+}