Last active
November 10, 2017 17:22
-
-
Save rickw/846291c707bf02922d60 to your computer and use it in GitHub Desktop.
Fibonacci sequence in Swift
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
func fibber(n:Int) -> Int { | |
switch n { | |
case 0: | |
return 0 | |
case 1: | |
return 1 | |
default: | |
return fibber(n-1) + fibber(n-2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would have rather done it without recursion (recursion is evil), such as:
it is way faster to execute!