Skip to content

Instantly share code, notes, and snippets.

@tompng
Last active March 29, 2024 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tompng/c21034aab89234d83523af33049e80f2 to your computer and use it in GitHub Desktop.
Save tompng/c21034aab89234d83523af33049e80f2 to your computer and use it in GitHub Desktop.
recursive fibonacci with complex
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