Sha256: 8f4b1230548b508f72310286e97636727d8546537efc513ae687302bebfa8d53
Contents?: true
Size: 450 Bytes
Versions: 280
Compression:
Stored size: 450 Bytes
Contents
object PascalsTriangle { fun computeTriangle(rows: Int): List<List<Int>> { require(rows >= 0, { "Rows can't be negative!" }) if (rows == 0) return emptyList() return (1..rows).map { buildTriangleRow(it) } } private fun buildTriangleRow(row: Int): List<Int> { var m = 1 return listOf(1) + (1..row - 1).map { col -> m = m * (row - col) / col return@map m } } }
Version data entries
280 entries across 280 versions & 1 rubygems