File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change 1
- const SQ5 = 5 ** .5 ; // Square root of 5
2
- const PHI = ( 1 + SQ5 ) / 2 ; // definition of PHI
1
+ const SQ5 = 5 ** 0.5
2
+ //Square root of 5
3
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.
4
+ const PHI = ( 1 + SQ5 ) / 2
5
+ // definition of PHI
6
6
7
+ //theoretically it should take O(1) constant amount of time as long
8
+ // arithmetic calculations are considered to be in constant amount of time
7
9
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 ;
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
12
14
}
13
15
14
16
console . log ( EvenFibonacci ( 4e6 ) ) ;
15
- // Sum of Even Fibonnaci upto 4 Million
17
+ // Sum of Even Fibonnaci upto 4 Million
You can’t perform that action at this time.
0 commit comments