func fibn(n: UInt) -> UInt {
if n == 0 {
return n
}
var last: UInt = 0,
next: UInt = 1
for _ in 1..<n {
(last, next) = (next, last+next)
}
return next
}
Created
June 10, 2018 17:17
-
-
Save islandjoe/42aa5c293c0340865af0c56a8d8c9421 to your computer and use it in GitHub Desktop.
A performant Fibonacci function. Much preferable than the recursive version.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment