aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2021-10-25 11:04:49 +0200
committerLuca Ferrari <fluca1978@gmail.com>2021-10-25 11:04:49 +0200
commita3a4eab6b572853c0b3c1a27f2d5b1e129173977 (patch)
treeafc719be8fe530ee4a3944b66880ad51119dfce7
parent4629e3f70fdf73637dc6d6d14b797ba92d9ef0b0 (diff)
downloadperlweeklychallenge-club-a3a4eab6b572853c0b3c1a27f2d5b1e129173977.tar.gz
perlweeklychallenge-club-a3a4eab6b572853c0b3c1a27f2d5b1e129173977.tar.bz2
perlweeklychallenge-club-a3a4eab6b572853c0b3c1a27f2d5b1e129173977.zip
Task 2 done
-rwxr-xr-xchallenge-136/luca-ferrari/raku/ch-2.p622
1 files changed, 22 insertions, 0 deletions
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;
+
+}