Ad

Generate Sequence

fun tribonacci(signature: DoubleArray, n: Int) = generateSequence(Triple(signature[0], signature[1], signature[2])) {
        Triple(it.second, it.third, it.first + it.second + it.third) }
        .map { it.first }
        .take(n)
        .toList()
        .toDoubleArray()
        
        
        
fun main() {
    val array = doubleArrayOf(1.0,1.0,1.0)
    tribonacci(array, 10)
}