Skip to content

Instantly share code, notes, and snippets.

@haydenk
Created April 28, 2026 14:37
Show Gist options
  • Select an option

  • Save haydenk/c29518aa2215fd059363229505f5db47 to your computer and use it in GitHub Desktop.

Select an option

Save haydenk/c29518aa2215fd059363229505f5db47 to your computer and use it in GitHub Desktop.
[Python] Recursive Fibonacci with type hints; handles negative inputs by taking the absolute value.
def fibonacci(n: int) -> int:
abs_n: int = abs(n)
if abs_n < 2:
return 0
if abs_n < 3:
return 1
return fibonacci(abs_n - 1) + fibonacci(abs_n - 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment