Skip to content

Instantly share code, notes, and snippets.

@uraimo
Created January 9, 2018 08:31
Show Gist options
  • Select an option

  • Save uraimo/de50acbe8fbcc696781f4d4f71d925e7 to your computer and use it in GitHub Desktop.

Select an option

Save uraimo/de50acbe8fbcc696781f4d4f71d925e7 to your computer and use it in GitHub Desktop.

Tail recursive version of fibonacci:

func fibTail(_ n: Int, _ a: Int = 0,_ b: Int = 1) -> Int{
    if n == 0 { return a }
    if n == 1 { return b }
    return fibTail(n-1,b,a+b)
}


fibTail(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment