Skip to content

Instantly share code, notes, and snippets.

@goldsworthy
Created January 28, 2016 23:02
Show Gist options
  • Save goldsworthy/13f3f62abd302eae0e1f to your computer and use it in GitHub Desktop.
Save goldsworthy/13f3f62abd302eae0e1f to your computer and use it in GitHub Desktop.
object FibonacciBinet {
def fib(n: Int) = {
def A = Math.pow(1 + Math.sqrt(5), n)
def B = Math.pow(1 - Math.sqrt(5), n)
def C = Math.pow(2, n) * Math.sqrt(5)
Math.floor((A - B) / C)
}
fib(0)
fib(1)
fib(2)
fib(3)
fib(4)
fib(12)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment