๐ฆ๐บ
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 SubFib(startNumber, endNumber): | |
| for cur in F(): | |
| if cur > endNumber: return | |
| if cur >= startNumber: | |
| yield cur | |
| for i in SubFib(10, 200): | |
| print i |
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 |