aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2020-09-15 19:50:36 +0200
committerAbigail <abigail@abigail.be>2020-09-15 19:50:36 +0200
commitd36cbe639e0dffeb2fd168576ea19570c9fb687d (patch)
tree4849101159885ed68cc392d64ec64357b06e2d24
parenta5470d3acea87f11ed71eaf4b61e822664d44008 (diff)
downloadperlweeklychallenge-club-d36cbe639e0dffeb2fd168576ea19570c9fb687d.tar.gz
perlweeklychallenge-club-d36cbe639e0dffeb2fd168576ea19570c9fb687d.tar.bz2
perlweeklychallenge-club-d36cbe639e0dffeb2fd168576ea19570c9fb687d.zip
Fix off-by-one error.
We need all the Fibonacci numbers up to and including $N, else we will miss out on a solution if $N is a Fibonacci number.
-rw-r--r--challenge-077/abigail/Part1/input41
-rw-r--r--challenge-077/abigail/Part1/output4.exp7
-rw-r--r--challenge-077/abigail/Part1/solution.js2
-rw-r--r--challenge-077/abigail/Part1/solution.pl2
4 files changed, 10 insertions, 2 deletions
diff --git a/challenge-077/abigail/Part1/input4 b/challenge-077/abigail/Part1/input4
new file mode 100644
index 0000000000..66a899ac41
--- /dev/null
+++ b/challenge-077/abigail/Part1/input4
@@ -0,0 +1 @@
+377
diff --git a/challenge-077/abigail/Part1/output4.exp b/challenge-077/abigail/Part1/output4.exp
new file mode 100644
index 0000000000..4fc109d510
--- /dev/null
+++ b/challenge-077/abigail/Part1/output4.exp
@@ -0,0 +1,7 @@
+1 + 2 + 5 + 13 + 34 + 89 + 233 = 377
+3 + 5 + 13 + 34 + 89 + 233 = 377
+8 + 13 + 34 + 89 + 233 = 377
+21 + 34 + 89 + 233 = 377
+55 + 89 + 233 = 377
+144 + 233 = 377
+377 = 377
diff --git a/challenge-077/abigail/Part1/solution.js b/challenge-077/abigail/Part1/solution.js
index 6a3d839342..f2d7173403 100644
--- a/challenge-077/abigail/Part1/solution.js
+++ b/challenge-077/abigail/Part1/solution.js
@@ -28,7 +28,7 @@ let N = +fs . readFileSync (0) . toString () . trim ();
// up to the target number. Store this in FIB.
//
let FIB = [1, 2];
-while (FIB [FIB . length - 1] + FIB [FIB . length - 2] < N) {
+while (FIB [FIB . length - 1] + FIB [FIB . length - 2] <= N) {
FIB . push (FIB [FIB . length - 1] + FIB [FIB . length - 2]);
}
diff --git a/challenge-077/abigail/Part1/solution.pl b/challenge-077/abigail/Part1/solution.pl
index 5e6856b6d8..b39028c5b9 100644
--- a/challenge-077/abigail/Part1/solution.pl
+++ b/challenge-077/abigail/Part1/solution.pl
@@ -36,7 +36,7 @@ chomp (my $N = <>);
# we cannot duplicate numbers, so we just need one 1.
#
my @FIB = (1, 2);
-while ($FIB [-1] + $FIB [-2] < $N) {
+while ($FIB [-1] + $FIB [-2] <= $N) {
push @FIB => $FIB [-1] + $FIB [-2];
}