Skip to content

Instantly share code, notes, and snippets.

@apphands
Last active June 12, 2016 05:07
Show Gist options
  • Save apphands/64ee53aadf04af68ed4d15a20bca48c9 to your computer and use it in GitHub Desktop.
Save apphands/64ee53aadf04af68ed4d15a20bca48c9 to your computer and use it in GitHub Desktop.
Calculate Fibonacci numbers in Swift
// https://en.wikipedia.org/wiki/Fibonacci_number
// 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...
func fib(n:Int)->Int {
if n > 2 {
return fib(n-1) + fib(n-2)
} else {
return n
}
}
//usage
fib(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment