Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Created January 12, 2022 22:31
Show Gist options
  • Save gonaumov/3e2243085f3cd05f95ebd4b20f4e34bb to your computer and use it in GitHub Desktop.
Save gonaumov/3e2243085f3cd05f95ebd4b20f4e34bb to your computer and use it in GitHub Desktop.
/**
* Let's make a program that accepts a matrix and if
* the elements below the main diagonal are less than
* zero replace them with zero ...
*/
fun main() {
"""
1 2 -1
-1 -1 6
-1 -1 9
""".trimIndent().split("\\n+".toRegex()).map { s ->
s.trim().split("\\s+".toRegex()).map {
it.toInt()
}
}.mapIndexed { i, ints ->
ints.mapIndexed { j, joints ->
if (j < i && joints < 0) {
0
} else {
joints
}
}
}.forEach { ints ->
ints.forEach {
print(it.toString().padStart(3, " ".first()))
}
println()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment