We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 10f664d commit 9e6fe4bCopy full SHA for 9e6fe4b
1 file changed
Project-Euler/Problem2.js
@@ -1,17 +1,16 @@
1
const SQ5 = 5 ** 0.5
2
-//Square root of 5
+// Square root of 5
3
4
const PHI = (1 + SQ5) / 2
5
// definition of PHI
6
7
-//theoretically it should take O(1) constant amount of time as long
+// theoretically it should take O(1) constant amount of time as long
8
// arithmetic calculations are considered to be in constant amount of time
9
-function EvenFibonacci(limit) {
+function EvenFibonacci (limit) {
10
const highestIndex = Math.floor(Math.log(limit * SQ5) / Math.log(PHI))
11
const n = Math.floor(highestIndex / 3)
12
return ((PHI ** (3 * n + 3) - 1) / (PHI ** 3 - 1) -
13
((1 - PHI) ** (3 * n + 3) - 1) / ((1 - PHI) ** 3 - 1)) / SQ5
14
}
15
-
16
-console.log(EvenFibonacci(4e6));
+console.log(EvenFibonacci(4e6))
17
// Sum of Even Fibonnaci upto 4 Million
0 commit comments