Last active
March 29, 2024 15:00
-
-
Save tompng/c21034aab89234d83523af33049e80f2 to your computer and use it in GitHub Desktop.
recursive fibonacci with complex
This file contains 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 fibo_c(n) | |
return 1 if n == 0 | |
a=fibo_c(n/2)*b=1i**n[0] | |
b.*a.abs2+(a.*2+1i).real*a.imag.i | |
end | |
10.times.map{fibo_c(_1).real} | |
# => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment