Skip to content

Instantly share code, notes, and snippets.

@kishikawakatsumi
Created March 19, 2024 00:57
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 kishikawakatsumi/5d9bd152c9316062217a73fa275ce545 to your computer and use it in GitHub Desktop.
Save kishikawakatsumi/5d9bd152c9316062217a73fa275ce545 to your computer and use it in GitHub Desktop.
import Foundation
/// Calculates the `n`th Fibonacci number
///
/// This function returns `0` for all negative numbers.
func fib(_ n: Int) -> Int {
guard n > 0 else {
return 0
}
if n == 1 {
return 1
} else {
return fib(n - 1) + fib(n - 2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment