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

Version Path
trackler-2.2.1.62 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.61 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.60 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.59 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.58 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.57 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.56 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.55 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.54 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.53 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.52 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.51 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.50 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.49 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.48 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.47 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.46 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.45 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.44 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt
trackler-2.2.1.43 tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt