Matrix In Kotlin

I have this 2D List next below.

fun main(){ val down = mutableListOf<MutableList<Any>>() val rs = listOf( listOf(1,2,3), listOf(4,5,6), listOf(7,8,9) ) rs.forEachIndexed { index1, mutableList -> down.add(mutableListOf()) mutableList.forEachIndexed { index2, any -> try { down[index2].add(rs[index1][index1]) } catch (e: Exception) { e.message } } println(down.toTypedArray().contentDeepToString()) 

To be honest it’s work fine and output in the console something like this:

[[1, 5, 9], [5, 9], [9]] 

The code output the numbers of the list as one line, But i wanna output for each time the next line, Mean if the first line has 1,5,9 indexes the second line mast be 2,6 the third only 3 and so on whatever the list has, Like the output below:

[[1, 5, 9], [2, 6], [3]] 

submitted by /u/N0Matter1995
[link] [comments]