I have very limited experience in Java and slightly more in C# (just doing Advent of Code problems last month), so I'm not familiar with how to write idiomatic Kotlin.
This class implements an infinite generator for the Fibonacci sequence.
import java.math.BigInteger
class FibonacciGenerator {
private var fibs = arrayListOf<BigInteger>(BigInteger.ZERO, BigInteger.ONE)
fun get(idx: Int): BigInteger {
while (fibs.size <= idx) {
val nextNum: BigInteger = fibs[fibs.size - 1] + fibs[fibs.size - 2]
fibs.add(nextNum)
}
return fibs[idx]
}
}