Created
July 18, 2019 20:52
-
-
Save sherifflight/5d3f093aac3a2764ae23f0dfdde6dcab to your computer and use it in GitHub Desktop.
Fibonachi
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 fibonachi (n: Int) -> Int { | |
guard n > 1 else { | |
return 1 | |
} | |
var prev = 0 | |
var cur = 1 | |
for _ in 1..<n { | |
(prev, cur) = (cur, prev + cur) | |
} | |
return cur; | |
} | |
fibonachi(n: 6) //return 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment