Created
March 19, 2024 00:57
-
-
Save kishikawakatsumi/5d9bd152c9316062217a73fa275ce545 to your computer and use it in GitHub Desktop.
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
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