Skip to content

Instantly share code, notes, and snippets.

@cesartl
Created May 10, 2020 10:17
Show Gist options
  • Save cesartl/37c27a6e09964e16cfb178cf8877b7be to your computer and use it in GitHub Desktop.
Save cesartl/37c27a6e09964e16cfb178cf8877b7be to your computer and use it in GitHub Desktop.
fun fibobacciMemo(n: BigInteger): BigInteger {
var nMinus2 = BigInteger.ZERO
var nMinus1 = BigInteger.ONE
if (n <= BigInteger.ONE) {
return n
}
var i = BigInteger.ZERO
while (i < n) {
i += BigInteger.ONE
nMinus1 += nMinus2
nMinus2 = nMinus1 - nMinus2
}
return nMinus2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment