Created
September 21, 2018 07:17
-
-
Save freemansion/b4e8028912d8b64e2308039f2dea6bcb to your computer and use it in GitHub Desktop.
Fibonacci sequence in swift
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 { | |
switch num { | |
case Int.min...1: return max(0, num) | |
default: return fib(num-2) + fib(num-1) | |
} | |
} | |
Array(0...10).forEach { print(fib($0)) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment