Skip to content

Instantly share code, notes, and snippets.

@freemansion
Created September 21, 2018 07:17
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 freemansion/b4e8028912d8b64e2308039f2dea6bcb to your computer and use it in GitHub Desktop.
Save freemansion/b4e8028912d8b64e2308039f2dea6bcb to your computer and use it in GitHub Desktop.
Fibonacci sequence in swift
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