From 4629e3f70fdf73637dc6d6d14b797ba92d9ef0b0 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 25 Oct 2021 10:41:25 +0200 Subject: Task 1 done --- challenge-136/luca-ferrari/raku/ch-1.p6 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 challenge-136/luca-ferrari/raku/ch-1.p6 diff --git a/challenge-136/luca-ferrari/raku/ch-1.p6 b/challenge-136/luca-ferrari/raku/ch-1.p6 new file mode 100755 index 0000000000..aa3bf36984 --- /dev/null +++ b/challenge-136/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,5 @@ +#!raku + +sub MAIN( Int $m where { $m > 0 }, Int $n where { $n > 0 } ) { + ( [gcd] $m, $n ) %% 2 ?? '1'.say !! '0'.say; +} -- cgit From a3a4eab6b572853c0b3c1a27f2d5b1e129173977 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 25 Oct 2021 11:04:49 +0200 Subject: Task 2 done --- challenge-136/luca-ferrari/raku/ch-2.p6 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 challenge-136/luca-ferrari/raku/ch-2.p6 diff --git a/challenge-136/luca-ferrari/raku/ch-2.p6 b/challenge-136/luca-ferrari/raku/ch-2.p6 new file mode 100755 index 0000000000..83a5227a9d --- /dev/null +++ b/challenge-136/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,22 @@ +#!raku + +sub MAIN( Int $n where { $n > 1 } ) { + my @fibonacci; + @fibonacci.push: 1, 1; + my %solutions; + + # compute a reduced fibonacci sequence up to the sum of the number given + @fibonacci.push: @fibonacci[ * - 1 ] + @fibonacci[ * - 2 ] while $n > ( @fibonacci[ * - 1] + @fibonacci[ * - 2 ]); + + + # iterate over all the available numbers, and compute the sum + # and if the sum does match, add the array to the hash of solutions + # with a stringified key representation + %solutions{ $_.join( ' + ') } = $_ if ( ( [+] $_ ) == $n ) for @fibonacci.combinations.unique; + + # print the number of keys + say %solutions.keys.elems; + # and print all the sums + .join( " + " ).say for %solutions.values; + +} -- cgit From 3fb94d5d2b20c84f2c7ae2299a78dcb1da442131 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 25 Oct 2021 12:30:25 +0200 Subject: Blog reerences. --- challenge-136/luca-ferrari/blog-1.txt | 1 + challenge-136/luca-ferrari/blog-2.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 challenge-136/luca-ferrari/blog-1.txt create mode 100644 challenge-136/luca-ferrari/blog-2.txt diff --git a/challenge-136/luca-ferrari/blog-1.txt b/challenge-136/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..0e141f1428 --- /dev/null +++ b/challenge-136/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/10/25/PerlWeeklyChallenge136.html#task1 diff --git a/challenge-136/luca-ferrari/blog-2.txt b/challenge-136/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..99f4aed91f --- /dev/null +++ b/challenge-136/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/10/25/PerlWeeklyChallenge136.html#task2 -- cgit From 2d5b702c9a348f2226fca9c981f0054c485aa1dd Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 25 Oct 2021 14:28:41 +0200 Subject: Another implementation of the second task. --- challenge-136/luca-ferrari/raku/ch-2.p6 | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/challenge-136/luca-ferrari/raku/ch-2.p6 b/challenge-136/luca-ferrari/raku/ch-2.p6 index 83a5227a9d..6a606785ee 100755 --- a/challenge-136/luca-ferrari/raku/ch-2.p6 +++ b/challenge-136/luca-ferrari/raku/ch-2.p6 @@ -1,22 +1,28 @@ #!raku sub MAIN( Int $n where { $n > 1 } ) { - my @fibonacci; - @fibonacci.push: 1, 1; - my %solutions; + # my @fibonacci; + # @fibonacci.push: 1, 1; + # my %solutions; - # compute a reduced fibonacci sequence up to the sum of the number given - @fibonacci.push: @fibonacci[ * - 1 ] + @fibonacci[ * - 2 ] while $n > ( @fibonacci[ * - 1] + @fibonacci[ * - 2 ]); + # # compute a reduced fibonacci sequence up to the sum of the number given + # @fibonacci.push: @fibonacci[ * - 1 ] + @fibonacci[ * - 2 ] while $n > ( @fibonacci[ * - 1] + @fibonacci[ * - 2 ]); - # iterate over all the available numbers, and compute the sum - # and if the sum does match, add the array to the hash of solutions - # with a stringified key representation - %solutions{ $_.join( ' + ') } = $_ if ( ( [+] $_ ) == $n ) for @fibonacci.combinations.unique; + # # iterate over all the available numbers, and compute the sum + # # and if the sum does match, add the array to the hash of solutions + # # with a stringified key representation + # %solutions{ $_.join( ' + ') } = $_ if ( ( [+] $_ ) == $n ) for @fibonacci.combinations.unique; - # print the number of keys - say %solutions.keys.elems; - # and print all the sums - .join( " + " ).say for %solutions.values; + # # print the number of keys + # say %solutions.keys.elems; + # # and print all the sums + # .join( " + " ).say for %solutions.values; + + + my @fibonacci = 1, 1, * + * ... * > $n; + my @solutions = @fibonacci.unique.combinations.grep( *.sum == $n ); + @solutions.elems.say; + .join( ' + ' ).say for @solutions; } -- cgit