Sha256: eedbcab072c07b193f1e123710d73f1c81e8ebe63f2205eb0f97ace32406b95f

Contents?: true

Size: 451 Bytes

Versions: 116

Compression:

Stored size: 451 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 until row).map { col ->
            m = m * (row - col) / col
            return@map m
        }
    }
}

Version data entries

116 entries across 116 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.179 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.178 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.177 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.176 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.175 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.174 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.173 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.172 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.171 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.170 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.169 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.167 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.166 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.165 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.164 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.163 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.162 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.161 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.160 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt