Sha256: a176c766f92bc4429dca48eca7204588bc28cb611c1457bf5b103aa2e58a8ba3

Contents?: true

Size: 839 Bytes

Versions: 188

Compression:

Stored size: 839 Bytes

Contents

data class Matrix(val entries: List<List<Int>>) {

    val saddlePoints: Set<MatrixCoordinate> by lazy {
        val result = mutableSetOf<MatrixCoordinate>()

        if (entries.isNotEmpty()) {
            for (row in 0 until entries.size) {
                for (col in 0 until entries[0].size) {
                    val coordinateValue = entries[row][col]

                    if (coordinateValue == getRowMax(row) && coordinateValue == getColumnMin(col)) {
                        result.add(MatrixCoordinate(row, col))
                    }
                }
            }
        }

        result
    }

    private fun getRowMax(row: Int): Int {
        return entries[row].max() ?: 0
    }

    private fun getColumnMin(col: Int): Int {
        return entries
            .map { row -> row[col] }
            .min() ?: 0
    }

}

Version data entries

188 entries across 188 versions & 1 rubygems

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