class Matrix(genList: List<List<Int>>) {
    val entryList: MutableList<MatrixEntry> = mutableListOf<MatrixEntry>()
    val saddlePoints: MutableSet<MatrixCoordinate> by lazy {
        val returnSet: MutableSet<MatrixCoordinate> = mutableSetOf<MatrixCoordinate>()
        for (i in entryList){
            if ((getRow(i.row).maxBy { it.value }?.value == i.value ) and (getColumn(i.col).minBy { it.value }?.value == i.value)){
                returnSet.add(i.coord)
            }
        }
        returnSet
    }
    
    init {
        for (i in 0..genList.size-1){
            for (j in 0..genList[i].size-1){
                entryList.add(MatrixEntry(genList[i][j], MatrixCoordinate(i,j)))
            }
        }
    }

    fun getRow(row: Int): List<MatrixEntry> = entryList.filter { it.row == row }

    fun getColumn(column: Int): List<MatrixEntry> = entryList.filter { it.col == column }


}

data class MatrixEntry(val value: Int, val coord: MatrixCoordinate){
    val col = coord.col
    val row = coord.row
}