Skip to content

Instantly share code, notes, and snippets.

@cesartl
Created May 9, 2020 08:34
Show Gist options
  • Save cesartl/185ca23928386b56059a69548b1df224 to your computer and use it in GitHub Desktop.
Save cesartl/185ca23928386b56059a69548b1df224 to your computer and use it in GitHub Desktop.
object Fibonacci {
private val companionMatrix = Matrix22(0, 1, 1, 1)
fun fibonacciFast(n: BigInteger): BigInteger {
val m = Matrix22.monoid().run {
combineTimes(companionMatrix, n)
}
return m.x01
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment