Created
February 5, 2019 07:59
-
-
Save stevencurtis/705b582ddb9793113862d359c91d7cef to your computer and use it in GitHub Desktop.
Fibonacci bottom-up optimised
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 fib (_ num: Int) -> Int { | |
guard num > 1 else { return num } | |
var a = 0 | |
var b = 1 | |
var c = 0 | |
for _ in 2..<num { | |
c = a + b | |
a = b | |
b = c | |
} | |
return a + b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment