Skip to content

Instantly share code, notes, and snippets.

@downloadpizza
Created April 3, 2020 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save downloadpizza/5acb391a5bafb176407343f321211a96 to your computer and use it in GitHub Desktop.
Save downloadpizza/5acb391a5bafb176407343f321211a96 to your computer and use it in GitHub Desktop.
DownloadPizza's Catalyst stuff
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