mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-20 10:37:07 +08:00
Remove live code & console.log, leave examples as comments (ProjectEuler, Recursive).
This commit is contained in:
@ -4,10 +4,9 @@ const PHI = (1 + SQ5) / 2 // definition of PHI
|
||||
|
||||
// theoretically it should take O(1) constant amount of time as long
|
||||
// arithmetic calculations are considered to be in constant amount of time
|
||||
const EvenFibonacci = (limit) => {
|
||||
export const EvenFibonacci = (limit) => {
|
||||
const highestIndex = Math.floor(Math.log(limit * SQ5) / Math.log(PHI))
|
||||
const n = Math.floor(highestIndex / 3)
|
||||
return ((PHI ** (3 * n + 3) - 1) / (PHI ** 3 - 1) -
|
||||
((1 - PHI) ** (3 * n + 3) - 1) / ((1 - PHI) ** 3 - 1)) / SQ5
|
||||
}
|
||||
console.log(EvenFibonacci(4e6)) // Sum of even Fibonacci upto 4 Million
|
||||
|
Reference in New Issue
Block a user