Created
June 21, 2016 08:55
-
-
Save greymd/16c63541711e2176ab64faef214c5c12 to your computer and use it in GitHub Desktop.
Calculate fibonacci numbers with O( log n)
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
(define $binet | |
(lambda [$n] | |
(* (/ 1 (sqrt 5)) | |
(- (/ (+ 1 (sqrt 5)) 2)^n | |
(/ (- 1 (sqrt 5)) 2)^n)))) | |
; > (binet 3) | |
; 2 | |
; > (binet 1) | |
; 1 | |
; > (binet 2) | |
; 1 | |
; > (binet 3) | |
; 2 | |
; > (binet 4) | |
; 3 | |
; > (binet 5) | |
; 5 | |
; > (binet 6) | |
; 8 | |
; > (binet 7) | |
; 13 | |
; > (binet 8) | |
; 21 | |
; > (binet 9) | |
; 34 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment