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 0aba6d4 commit 6df59cdCopy full SHA for 6df59cd
Project-Euler/Problem2.js
@@ -0,0 +1,15 @@
1
+const SQ5 = 5 ** .5; // Square root of 5
2
+const PHI = (1 + SQ5) / 2; // definition of PHI
3
+
4
+//theoretically it should take O(1) constant amount of time as long
5
+// arithmetic calculations are considered to be in constant amount of time.
6
7
+function EvenFibonacci(limit) {
8
+ const highestIndex = Math.floor(Math.log(limit * SQ5) / Math.log(PHI));
9
+ const n = Math.floor(highestIndex / 3);
10
+ return ((PHI ** (3 * n + 3) - 1) / (PHI ** 3 - 1)
11
+ - ((1 - PHI) ** (3 * n + 3) - 1) / ((1 - PHI) ** 3 - 1)) / SQ5;
12
+}
13
14
+console.log(EvenFibonacci(4e6));
15
+// Sum of Even Fibonnaci upto 4 Million
0 commit comments