Created
May 10, 2020 10:17
-
-
Save cesartl/37c27a6e09964e16cfb178cf8877b7be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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