Created
April 11, 2019 02:57
-
-
Save farhanf/fedbe6c3ec707a2dfaef54e69f189a92 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
// 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