๐ฆ๐บ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ฯ = (1+sqrt(5))/2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fib_iterative(n): | |
| a, b = 0, 1 | |
| while n > 0: | |
| a, b = b, a + b | |
| n -= 1 | |
| return a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // |<--- p: F(n-1) - 1 --->| | |
| // |<----- q ----->| |<-- r -->| | |
| // +----+---+------+---+---------+ | |
| // | | k | | m | | | |
| // +----+---+------+---+---------+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fib(n) { | |
| if (n <= 0) | |
| return 0; | |
| if (n <= 2) | |
| return 1; | |
| return fib(n-1) + fib(n-2); | |
| } | |
| function smallest_greater_eq_fib(n) { | |
| let f = fib(0), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def fib(self, N: int) -> int: | |
| if (N <= 1): | |
| return N | |
| A = [[1, 1], [1, 0]] | |
| self.matrix_power(A, N-1) | |
| return A[0][0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fib(n){ | |
| if (n === 1) return 0; | |
| if (n === 2) return 1; | |
| return fib(n โ 1) + fib(n โ 2); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fib_formula(n): | |
| golden_ratio = (1 + math.sqrt(5)) / 2 | |
| val = (golden_ratio**n - (1 - golden_ratio)**n) / math.sqrt(5) | |
| return int(round(val)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function * iterableObj() { | |
| yield 'This'; | |
| yield 'is'; | |
| yield 'iterable.' | |
| } | |
| for (const val of iterableObj()) { | |
| console.log(val); | |
| } | |
| // This | |
| // is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Fibonacci_Search | |
| { | |
| static int kk = -1, nn = -1; | |
| static int fib[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, | |
| 377, 610, 98, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, | |
| 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, | |
| 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, | |
| 102334155, 165580141 }; | |
| static int fibsearch(int a[], int n, long x) |