Last active
January 25, 2017 10:48
-
-
Save mzaks/6e248558f30e480503fc 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
var i = 0 | |
func fib(_ number : Int)->Int { | |
i += 1 | |
return number <= 2 ? number : fib(number-1)+fib(number-2) | |
} | |
var j = 0 | |
var fibRow = [0, 1, 2] | |
func fibC(_ number:Int)->Int{ | |
if number >= fibRow.count { | |
fibRow.append(fibC(number-2)+fibC(number-1)) | |
} | |
j += 1 | |
return fibRow[number] | |
} | |
fib(10) | |
fib(11) | |
print(i) // 286 | |
fibC(10) | |
fibC(11) | |
print(j) // 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment