// using map
fun transpose(matrix: List<List<Int>>): List<List<Int>> =
matrix[0].indices.map { col ->
matrix.map { row -> row[col] }
}
fun main() {
val matrix = listOf(
listOf(1, 2, 3),
listOf(4, 5, 6),
listOf(7, 8, 9)
)
val t = transpose(matrix)
t.forEach { println(it.joinToString(" ")) }
}
/*
run:
1 4 7
2 5 8
3 6 9
*/