Created
April 3, 2020 07:34
-
-
Save downloadpizza/5acb391a5bafb176407343f321211a96 to your computer and use it in GitHub Desktop.
DownloadPizza's Catalyst stuff
This file contains 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
package net.downloadpizza.cautil.matrix | |
typealias Matrix<T> = List<List<T>> | |
inline fun <T> readMatrix(height: Int, delimeter: String = " ", convert: (String) -> T): Matrix<T> = | |
List(height) { readLine()!!.split(delimeter).map(convert) } | |
fun readIntMatrix(height: Int, delimeter: String = " "): Matrix<Int> = | |
readMatrix(height, delimeter, String::toInt) | |
fun readDoubleMatrix(height: Int, delimeter: String = " "): Matrix<Double> = | |
readMatrix(height, delimeter, String::toDouble) | |
inline fun <T, R> List<List<T>>.mapMatrix(transform: (T) -> R): Matrix<R> = this.map { it.map(transform) } | |
fun <T : Comparable<T>> List<List<T>>.matrixMax() = this.mapNotNull { it.max() }.max() | |
fun <T : Comparable<T>> List<List<T>>.matrixMin() = this.mapNotNull { it.min() }.min() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment