Project Euler problems (numbering) : follow naming convention.

This commit is contained in:
Eric Lavault
2021-10-11 16:17:25 +02:00
parent df4a783b06
commit cb6201f03f
11 changed files with 2 additions and 2 deletions

View File

@ -0,0 +1,12 @@
// https://projecteuler.net/problem=2
const SQ5 = 5 ** 0.5 // Square root of 5
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
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
}