Created
January 12, 2022 22:31
-
-
Save gonaumov/3e2243085f3cd05f95ebd4b20f4e34bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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