Skip to content

Instantly share code, notes, and snippets.

@mzaks
Last active January 25, 2017 10:48
Show Gist options
  • Save mzaks/6e248558f30e480503fc to your computer and use it in GitHub Desktop.
Save mzaks/6e248558f30e480503fc to your computer and use it in GitHub Desktop.
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