Catalan numbers: Difference between revisions

Content added Content deleted
(Kotlin: init removed)
(Kotlin version enhanced)
Line 1,900:
fun catI(n: Int): Double {
if (n !in catsI)
catsI[n] = Math.round(fact(2 * n) / (fact(n + 1) * fact(n))).toDouble()
 
return Math.round(catsI[n]).toDouble()
}
 
Line 1,912:
for (i in 0..n - 1)
sum += catR1(i) * catR1(n - 1 - i)
sum = Math.round(sum).toDouble()
 
catsR1[n] = sum
return Math.round(sum).toDouble()
}
 
fun catR2(n: Int): Double {
if (n !in catsR2)
catsR2[n] = Math.round(2.0 * (2 * (n - 1) + 1) / (n + 1) * catR2(n - 1)).toDouble()
 
return Math.round(catsR2[n]).toDouble()
}