Created
June 4, 2014 17:52
-
-
Save luchuan/6d0f95ddf793c156896b to your computer and use it in GitHub Desktop.
This file contains 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
// Playground - noun: a place where people can play | |
import Cocoa | |
func main() { | |
func _fib(x: Int, y: Int, i: Int) -> Int { | |
if i == 1 || i == 0 { | |
return x + y | |
} else { | |
return _fib(y, x + y, i - 1) | |
} | |
} | |
func fib(n: Int) -> Int { | |
if n == 0 { | |
return 0 | |
} | |
return _fib(0, 1, n) | |
} | |
fib(10) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment