Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@farhanf
Created April 11, 2019 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farhanf/fedbe6c3ec707a2dfaef54e69f189a92 to your computer and use it in GitHub Desktop.
Save farhanf/fedbe6c3ec707a2dfaef54e69f189a92 to your computer and use it in GitHub Desktop.
// Run in playgrounds
var index = 0
func nextfib(_ num: Int){
let result = fib(index)
if result > num {
print(result)
index = 0
} else {
index += 1
nextfib(num)
}
}
func fib(_ n: Int) -> Int {
guard n != 0, n != 1 else {
return n
}
return fib(n - 1) + fib(n - 2)
}
var testNums = [1,22,9]
for num in testNums {
nextfib(num)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment