package processor

import kotlin.system.exitProcess

fun main() {
    doMenuActions()
}

/**
 * Menu and Actions
 * @param data List of data
 * @param index Index of data
 */
private fun doMenuActions() {
    do {
        val menu = readMenuOption()
        when (menu) {
            0 -> exit()
            1 -> addMatrices()
            2 -> multiplyByConstant()
            3 -> multiplyMatrices()
            4 -> transposeMatrix()
            5 -> determinantMatrix()
            6 -> inverseMatrix()
        }
    } while (menu != 0)
}

/**
 * Inverse of a Matrix
 */
fun inverseMatrix() {
    val m = readMatrix("")
    inverseMatrix(m)
}

/**
 * Calculate the inverse of a Matrix
 */
fun inverseMatrix(mat: Array<Array<Double>>) {
    /*
    If det(A) != 0
    A-1 = adj(A)/det(A)
    Else
    "Inverse doesn't exist"
    */
    val det = determinantMatrix(mat, mat.size, mat.size)
    if (det != 0.0) {
        val adj = Array(mat.size) { Array(mat.size) { 0.0 } }
        adjoint(mat, adj, mat.size)
        // Find Inverse using formula "inverse(A) = adj(A)/det(A)"
        // Find Inverse using formula "inverse(A) = adj(A)/det(A)"
        val inverse = Array(mat.size) { Array(mat.size) { 0.0 } }
        for (i in mat.indices)
            for (j in mat.indices)
                inverse[i][j] = adj[i][j] / det

        printMatrix(inverse)

    } else {
        println("This matrix doesn't have an inverse.")
    }

}

/**
 * Determinat of a Matrix
 */
fun determinantMatrix() {
    val m = readMatrix("")
    val determinant = determinantMatrix(m, m.size, m.size)
    println("The result is:")
    println(determinant)
}

/**
 * Function to get cofactor (sub matrix) of mat(p)(q) in temp[][]. n is current dimension of mat[][]
 * @param mat Matrix
 * @param temp Matrix
 * @param p Row
 * @param q Column
 * @param n Size of matrix
 */
fun getCofactor(
    mat: Array<Array<Double>>, temp: Array<Array<Double>>,
    p: Int, q: Int, n: Int
) {
    var i = 0
    var j = 0

    // Looping for each element of
    // the matrix
    for (row in 0 until n) {
        for (col in 0 until n) {
            // Copying into temporary matrix
            // only those element which are
            // not in given row and column
            if (row != p && col != q) {
                temp[i][j++] = mat[row][col]
                // Row is filled, so increase
                // row index and reset col
                // index
                if (j == n - 1) {
                    j = 0
                    i++
                }
            }
        }
    }
}

/**
 * Calculate Determinant of a Matrix Recursive
 * @param mat Matrix
 * @param n Size of actual Matrix
 * @param Size of Matrix Original Matrix
 * @return Determinant of Matrix
 */
fun determinantMatrix(mat: Array<Array<Double>>, n: Int, Size: Int): Double {
    var det = 0.0 // Initialize result

    // Base case : if matrix contains single
    // element
    if (n == 1) return mat[0][0]

    // To store cofactors
    val temp = Array(Size) { Array(Size) { 0.0 } }

    // To store sign multiplier
    var sign = 1

    // Iterate for each element of first row
    for (f in 0 until n) {
        // Getting Cofactor of mat[0][f]
        getCofactor(mat, temp, 0, f, n)
        det += (sign * mat[0][f] * determinantMatrix(temp, n - 1, Size))

        // terms are to be added with
        // alternate sign
        sign = -sign
    }
    return det
}

/**
 * Get adjoint of A(N)(N) in adj(N)(N).
 */
fun adjoint(mat: Array<Array<Double>>, adj: Array<Array<Double>>, Size: Int) {
    if (Size == 1) {
        adj[0][0] = 1.0
        return
    }

    // temp is used to store cofactors of A[][]
    var sign = 1
    val temp = Array(Size) { Array(Size) { 0.0 } }
    for (i in 0 until Size) {
        for (j in 0 until Size) {
            // Get cofactor of A[i][j]
            getCofactor(mat, temp, i, j, Size)

            // sign of adj[j][i] positive if sum of row
            // and column indexes is even.
            sign = if ((i + j) % 2 == 0) 1 else -1

            // Interchanging rows and columns to get the
            // transpose of the cofactor matrix
            adj[j][i] = sign * determinantMatrix(temp, Size - 1, Size)
        }
    }
}

/**
 * Menu Options Transpose Matrix
 */

fun transposeMatrix() {
    var menu = 0
    do {
        menu = readMenuTranposeOption()
        when (menu) {
            1 -> {
                transposeMain()
                menu = 0
            }
            2 -> {
                transposeSide()
                menu = 0
            }
            3 -> {
                transposeVertical()
                menu = 0
            }
            4 -> {
                transposeHorizontal()
                menu = 0
            }
        }
    } while (menu != 0)
    doMenuActions()
}

/**
 * Trasnpose Horizontal Matrix
 */
fun transposeHorizontal() {
    val m = readMatrix("")
    transposeHorizontal(m)
}

/**
 * Trasnpose Horizontal Matrix
 * @param m Matrix
 */
fun transposeHorizontal(mat: Array<Array<Double>>) {
    val mT = Array(mat[0].size) { Array(mat.size) { 0.0 } }
    val n = mat.size
    for (i in 0 until n) {
        for (j in 0 until n) {
            mT[(n - 1) - i][j] = mat[i][j]
        }
    }
    println("Transpose Vertical")
    printMatrix(mT)
}

/**
 * Transpose Vertical Matrix
 */
fun transposeVertical() {
    val m = readMatrix("")
    transposeVertical(m)
}

/**
 * Tranpose Vertical Matrix
 * @param m Matrix
 */
fun transposeVertical(mat: Array<Array<Double>>) {
    val mT = Array(mat[0].size) { Array(mat.size) { 0.0 } }
    val n = mat.size
    for (i in 0 until n) {
        for (j in 0 until n) {
            mT[i][(n - 1) - j] = mat[i][j]
        }
    }
    println("Transpose Vertical")
    printMatrix(mT)
}

/**
 * Tranpose Side Diagonal
 */
fun transposeSide() {
    val m = readMatrix("")
    transposeSide(m)
}

/**
 * Tranpose Side Diagonal
 * @param m Matrix
 */
fun transposeSide(mat: Array<Array<Double>>) {
    val mT = Array(mat[0].size) { Array(mat.size) { 0.0 } }
    val n = mat.size
    for (i in mat.indices) {
        for (j in 0 until mat[0].size) {
            mT[(n - 1) - j][(n - 1) - i] = mat[i][j]
        }
    }

    printMatrix(mT)
}

/**
 * Transpose Matrix Main Diagonal
 */
fun transposeMain() {
    val m = readMatrix("")
    transposeMain(m)

}

/**
 * Transpose Matrix Side Diagonal
 *
 */
fun transposeMain(mat: Array<Array<Double>>) {
    val mT = Array(mat[0].size) { Array(mat.size) { 0.0 } }

    for (i in mat.indices) {
        for (j in 0 until mat[0].size) {
            mT[j][i] = mat[i][j]
        }
    }

    printMatrix(mT)
}

/**
 * Reads Menu Transpose Matrix
 * @return Menu option
 */
fun readMenuTranposeOption(): Int {
    var option: Int
    do {
        println("1. Main diagonal")
        println("2. Side diagonal")
        println("3. Vertical line")
        println("4. Horizontal line")
        print("Your choice: ")
        option = readLine()!!.toIntOrNull() ?: -1
        if (option !in 1..4) {
            println("Incorrect option! Try again.")
        }
    } while (option !in 1..4)
    return option
}

/**
 * Multiply Matrices
 */
fun multiplyMatrices() {
    val m1 = readMatrix("first")
    val m2 = readMatrix("second")
    multiplayMatrices(m1, m2)
}

/**
 * Multiply Matrices
 * @param m1 First Matrix
 * @param m2 Second Matrix
 */
fun multiplayMatrices(m1: Array<Array<Double>>, m2: Array<Array<Double>>) {
    // m1. columns == m2.rows
    if (m1[0].size != m2.size) {
        println("The operation cannot be performed.")
    } else {
        //
        val m3 = Array(m1.size) { Array(m2[0].size) { 0.0 } }
        for (i in m1.indices) {
            for (j in 0 until m2[0].size) {
                for (k in m2.indices) {
                    m3[i][j] += m1[i][k] * m2[k][j]
                }
            }
        }
        // imprimimos la matriz resultado
        printMatrix(m3)
    }
}

/**
 * Multiply matrix by constant
 */
fun multiplyByConstant() {
    val m = readMatrix("")
    val c = readConstant()
    matrixByNumber(m, c)
}

/**
 * Reads the constant
 */
fun readConstant(): Double {
    var c: Double
    do {
        print("Enter constant: ")
        c = readLine()!!.toDoubleOrNull() ?: Double.MAX_VALUE
    } while (c == Double.MAX_VALUE)
    return c
}

/**
 * Add Matrices
 */
fun addMatrices() {
    val m1 = readMatrix("first")
    val m2 = readMatrix("second")
    addMatrices(m1, m2)
}

/**
 * Reads Menu
 * @return Menu option
 */
fun readMenuOption(): Int {
    var option: Int
    do {
        println("1. Add matrices")
        println("2. Multiply matrix by a constant")
        println("3. Multiply matrices")
        println("4. Transpose matrix")
        println("5. Calculate a determinant")
        println("6. Inverse matrix")
        println("0. Exit")
        print("Your choice: ")
        option = readLine()!!.toIntOrNull() ?: -1
        if (option !in 0..6) {
            println("Incorrect option! Try again.")
        }
    } while (option !in 0..6)
    return option
}

/**
 * Exits the program.
 */
fun exit() {
    exitProcess(0)
}

/**
 * Multiply matrix by number
 * @param m Matrix
 * @param c Number
 */
fun matrixByNumber(matrix: Array<Array<Double>>, c: Double) {
    val res = Array(matrix.size) { Array(matrix[0].size) { 0.0 } }
    for (i in matrix.indices) {
        for (j in 0 until matrix[i].size) {
            res[i][j] = c * matrix[i][j]
        }
    }
    printMatrix(res)
}

/**
 * Print a Matrix
 * @param m Matrix
 */
fun printMatrix(m: Array<Array<Double>>) {
    // println()
    println("The result is: ")
    for (i in m.indices) {
        for (j in m[i].indices) {
            print("${m[i][j]} ")
        }
        println()
    }
}

/**
 * Add two matrices
 * @param m1 first matrix
 * @param m2 second matrix
 */
fun addMatrices(m1: Array<Array<Double>>, m2: Array<Array<Double>>) {
    if (m1.size != m2.size || m1[0].size != m2[0].size) {
        println("The operation cannot be performed.")
    } else {
        val m3 = Array(m1.size) { Array(m1[0].size) { 0.0 } }
        for (i in m1.indices) {
            for (j in m1[i].indices) {
                m3[i][j] = m1[i][j] + m2[i][j]
            }
        }
        // imprimimos la matriz resultado
        printMatrix(m3)
    }
}

/**
 * Read a matrix from the console
 * @return a matrix
 */
fun readMatrix(type: String): Array<Array<Double>> {
    print("Enter size of $type matrix: ")
    val (f, c) = readLine()!!.split(" ").map { it.toInt() }
    val matrix = Array(f) { Array(c) { 0.0 } }
    println("Enter $type matrix: ")
    for (i in 0 until f) {
        val line = readLine()!!.split(" ").map { it.toDouble() }
        for (j in 0 until c) {
            matrix[i][j] = line[j]
        }
    }
    return matrix
}

Compiled from "Matrix.kt"
public final class processor.MatrixKt {
  public static final void main();
    Code:
       0: invokestatic  #9                  // Method doMenuActions:()V
       3: return

  private static final void doMenuActions();
    Code:
       0: invokestatic  #13                 // Method readMenuOption:()I
       3: istore_0
       4: iload_0
       5: tableswitch   { // 0 to 6
                     0: 48
                     1: 54
                     2: 60
                     3: 66
                     4: 72
                     5: 78
                     6: 84
               default: 87
          }
      48: invokestatic  #16                 // Method exit:()V
      51: goto          87
      54: invokestatic  #19                 // Method addMatrices:()V
      57: goto          87
      60: invokestatic  #22                 // Method multiplyByConstant:()V
      63: goto          87
      66: invokestatic  #25                 // Method multiplyMatrices:()V
      69: goto          87
      72: invokestatic  #28                 // Method transposeMatrix:()V
      75: goto          87
      78: invokestatic  #31                 // Method determinantMatrix:()V
      81: goto          87
      84: invokestatic  #34                 // Method inverseMatrix:()V
      87: iload_0
      88: ifne          0
      91: return

  public static final void inverseMatrix();
    Code:
       0: ldc           #38                 // String
       2: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
       5: astore_0
       6: aload_0
       7: invokestatic  #45                 // Method inverseMatrix:([[Ljava/lang/Double;)V
      10: return

  public static final void inverseMatrix(java.lang.Double[][]);
    Code:
       0: aload_0
       1: ldc           #50                 // String mat
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_0
       8: checkcast     #58                 // class "[Ljava/lang/Object;"
      11: arraylength
      12: aload_0
      13: checkcast     #58                 // class "[Ljava/lang/Object;"
      16: arraylength
      17: invokestatic  #61                 // Method determinantMatrix:([[Ljava/lang/Double;II)D
      20: dstore_1
      21: dload_1
      22: dconst_0
      23: dcmpg
      24: ifne          31
      27: iconst_1
      28: goto          32
      31: iconst_0
      32: ifne          313
      35: iconst_0
      36: istore        4
      38: aload_0
      39: checkcast     #58                 // class "[Ljava/lang/Object;"
      42: arraylength
      43: istore        5
      45: iload         5
      47: anewarray     #63                 // class "[Ljava/lang/Double;"
      50: astore        6
      52: iload         4
      54: iload         5
      56: if_icmpge     127
      59: iload         4
      61: istore        7
      63: aload         6
      65: iload         7
      67: iconst_0
      68: istore        8
      70: aload_0
      71: checkcast     #58                 // class "[Ljava/lang/Object;"
      74: arraylength
      75: istore        9
      77: iload         9
      79: anewarray     #65                 // class java/lang/Double
      82: astore        10
      84: istore        14
      86: astore        13
      88: iload         8
      90: iload         9
      92: if_icmpge     114
      95: iload         8
      97: istore        11
      99: aload         10
     101: iload         11
     103: dconst_0
     104: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     107: aastore
     108: iinc          8, 1
     111: goto          88
     114: aload         13
     116: iload         14
     118: aload         10
     120: aastore
     121: iinc          4, 1
     124: goto          52
     127: aload         6
     129: astore_3
     130: aload_0
     131: aload_3
     132: aload_0
     133: checkcast     #58                 // class "[Ljava/lang/Object;"
     136: arraylength
     137: invokestatic  #73                 // Method adjoint:([[Ljava/lang/Double;[[Ljava/lang/Double;I)V
     140: iconst_0
     141: istore        5
     143: aload_0
     144: checkcast     #58                 // class "[Ljava/lang/Object;"
     147: arraylength
     148: istore        6
     150: iload         6
     152: anewarray     #63                 // class "[Ljava/lang/Double;"
     155: astore        7
     157: iload         5
     159: iload         6
     161: if_icmpge     232
     164: iload         5
     166: istore        8
     168: aload         7
     170: iload         8
     172: iconst_0
     173: istore        9
     175: aload_0
     176: checkcast     #58                 // class "[Ljava/lang/Object;"
     179: arraylength
     180: istore        10
     182: iload         10
     184: anewarray     #65                 // class java/lang/Double
     187: astore        11
     189: istore        14
     191: astore        13
     193: iload         9
     195: iload         10
     197: if_icmpge     219
     200: iload         9
     202: istore        12
     204: aload         11
     206: iload         12
     208: dconst_0
     209: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     212: aastore
     213: iinc          9, 1
     216: goto          193
     219: aload         13
     221: iload         14
     223: aload         11
     225: aastore
     226: iinc          5, 1
     229: goto          157
     232: aload         7
     234: astore        4
     236: iconst_0
     237: istore        5
     239: aload_0
     240: checkcast     #58                 // class "[Ljava/lang/Object;"
     243: arraylength
     244: istore        6
     246: iload         5
     248: iload         6
     250: if_icmpge     305
     253: iconst_0
     254: istore        7
     256: aload_0
     257: checkcast     #58                 // class "[Ljava/lang/Object;"
     260: arraylength
     261: istore        8
     263: iload         7
     265: iload         8
     267: if_icmpge     299
     270: aload         4
     272: iload         5
     274: aaload
     275: iload         7
     277: aload_3
     278: iload         5
     280: aaload
     281: iload         7
     283: aaload
     284: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
     287: dload_1
     288: ddiv
     289: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     292: aastore
     293: iinc          7, 1
     296: goto          263
     299: iinc          5, 1
     302: goto          246
     305: aload         4
     307: invokestatic  #80                 // Method printMatrix:([[Ljava/lang/Double;)V
     310: goto          322
     313: ldc           #82                 // String This matrix doesn\'t have an inverse.
     315: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
     318: swap
     319: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     322: return

  public static final void determinantMatrix();
    Code:
       0: ldc           #38                 // String
       2: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
       5: astore_0
       6: aload_0
       7: aload_0
       8: checkcast     #58                 // class "[Ljava/lang/Object;"
      11: arraylength
      12: aload_0
      13: checkcast     #58                 // class "[Ljava/lang/Object;"
      16: arraylength
      17: invokestatic  #61                 // Method determinantMatrix:([[Ljava/lang/Double;II)D
      20: dstore_1
      21: ldc           #103                // String The result is:
      23: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: swap
      27: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      33: dload_1
      34: invokevirtual #106                // Method java/io/PrintStream.println:(D)V
      37: return

  public static final void getCofactor(java.lang.Double[][], java.lang.Double[][], int, int, int);
    Code:
       0: aload_0
       1: ldc           #50                 // String mat
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #111                // String temp
       9: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore        5
      15: iconst_0
      16: istore        6
      18: iconst_0
      19: istore        7
      21: iload         7
      23: iload         4
      25: if_icmpge     94
      28: iconst_0
      29: istore        8
      31: iload         8
      33: iload         4
      35: if_icmpge     88
      38: iload         7
      40: iload_2
      41: if_icmpeq     82
      44: iload         8
      46: iload_3
      47: if_icmpeq     82
      50: aload_1
      51: iload         5
      53: aaload
      54: iload         6
      56: iinc          6, 1
      59: aload_0
      60: iload         7
      62: aaload
      63: iload         8
      65: aaload
      66: aastore
      67: iload         6
      69: iload         4
      71: iconst_1
      72: isub
      73: if_icmpne     82
      76: iconst_0
      77: istore        6
      79: iinc          5, 1
      82: iinc          8, 1
      85: goto          31
      88: iinc          7, 1
      91: goto          21
      94: return

  public static final double determinantMatrix(java.lang.Double[][], int, int);
    Code:
       0: aload_0
       1: ldc           #50                 // String mat
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: dconst_0
       7: dstore_3
       8: iload_1
       9: iconst_1
      10: if_icmpne     22
      13: aload_0
      14: iconst_0
      15: aaload
      16: iconst_0
      17: aaload
      18: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
      21: dreturn
      22: iconst_0
      23: istore        6
      25: iload_2
      26: anewarray     #63                 // class "[Ljava/lang/Double;"
      29: astore        7
      31: iload         6
      33: iload_2
      34: if_icmpge     96
      37: iload         6
      39: istore        8
      41: aload         7
      43: iload         8
      45: iconst_0
      46: istore        9
      48: iload_2
      49: anewarray     #65                 // class java/lang/Double
      52: astore        10
      54: istore        13
      56: astore        12
      58: iload         9
      60: iload_2
      61: if_icmpge     83
      64: iload         9
      66: istore        11
      68: aload         10
      70: iload         11
      72: dconst_0
      73: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      76: aastore
      77: iinc          9, 1
      80: goto          58
      83: aload         12
      85: iload         13
      87: aload         10
      89: aastore
      90: iinc          6, 1
      93: goto          31
      96: aload         7
      98: astore        5
     100: iconst_1
     101: istore        6
     103: iconst_0
     104: istore        7
     106: iload         7
     108: iload_1
     109: if_icmpge     159
     112: aload_0
     113: aload         5
     115: iconst_0
     116: iload         7
     118: iload_1
     119: invokestatic  #118                // Method getCofactor:([[Ljava/lang/Double;[[Ljava/lang/Double;III)V
     122: dload_3
     123: iload         6
     125: i2d
     126: aload_0
     127: iconst_0
     128: aaload
     129: iload         7
     131: aaload
     132: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
     135: dmul
     136: aload         5
     138: iload_1
     139: iconst_1
     140: isub
     141: iload_2
     142: invokestatic  #61                 // Method determinantMatrix:([[Ljava/lang/Double;II)D
     145: dmul
     146: dadd
     147: dstore_3
     148: iload         6
     150: ineg
     151: istore        6
     153: iinc          7, 1
     156: goto          106
     159: dload_3
     160: dreturn

  public static final void adjoint(java.lang.Double[][], java.lang.Double[][], int);
    Code:
       0: aload_0
       1: ldc           #50                 // String mat
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #122                // String adj
       9: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_2
      13: iconst_1
      14: if_icmpne     27
      17: aload_1
      18: iconst_0
      19: aaload
      20: iconst_0
      21: dconst_1
      22: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      25: aastore
      26: return
      27: iconst_1
      28: istore_3
      29: iconst_0
      30: istore        5
      32: iload_2
      33: anewarray     #63                 // class "[Ljava/lang/Double;"
      36: astore        6
      38: iload         5
      40: iload_2
      41: if_icmpge     103
      44: iload         5
      46: istore        7
      48: aload         6
      50: iload         7
      52: iconst_0
      53: istore        8
      55: iload_2
      56: anewarray     #65                 // class java/lang/Double
      59: astore        9
      61: istore        12
      63: astore        11
      65: iload         8
      67: iload_2
      68: if_icmpge     90
      71: iload         8
      73: istore        10
      75: aload         9
      77: iload         10
      79: dconst_0
      80: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      83: aastore
      84: iinc          8, 1
      87: goto          65
      90: aload         11
      92: iload         12
      94: aload         9
      96: aastore
      97: iinc          5, 1
     100: goto          38
     103: aload         6
     105: astore        4
     107: iconst_0
     108: istore        5
     110: iload         5
     112: iload_2
     113: if_icmpge     186
     116: iconst_0
     117: istore        6
     119: iload         6
     121: iload_2
     122: if_icmpge     180
     125: aload_0
     126: aload         4
     128: iload         5
     130: iload         6
     132: iload_2
     133: invokestatic  #118                // Method getCofactor:([[Ljava/lang/Double;[[Ljava/lang/Double;III)V
     136: iload         5
     138: iload         6
     140: iadd
     141: iconst_2
     142: irem
     143: ifne          150
     146: iconst_1
     147: goto          151
     150: iconst_m1
     151: istore_3
     152: aload_1
     153: iload         6
     155: aaload
     156: iload         5
     158: iload_3
     159: i2d
     160: aload         4
     162: iload_2
     163: iconst_1
     164: isub
     165: iload_2
     166: invokestatic  #61                 // Method determinantMatrix:([[Ljava/lang/Double;II)D
     169: dmul
     170: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     173: aastore
     174: iinc          6, 1
     177: goto          119
     180: iinc          5, 1
     183: goto          110
     186: return

  public static final void transposeMatrix();
    Code:
       0: iconst_0
       1: istore_0
       2: invokestatic  #125                // Method readMenuTranposeOption:()I
       5: istore_0
       6: iload_0
       7: tableswitch   { // 1 to 4
                     1: 36
                     2: 44
                     3: 52
                     4: 60
               default: 65
          }
      36: invokestatic  #128                // Method transposeMain:()V
      39: iconst_0
      40: istore_0
      41: goto          65
      44: invokestatic  #131                // Method transposeSide:()V
      47: iconst_0
      48: istore_0
      49: goto          65
      52: invokestatic  #134                // Method transposeVertical:()V
      55: iconst_0
      56: istore_0
      57: goto          65
      60: invokestatic  #137                // Method transposeHorizontal:()V
      63: iconst_0
      64: istore_0
      65: iload_0
      66: ifne          2
      69: invokestatic  #9                  // Method doMenuActions:()V
      72: return

  public static final void transposeHorizontal();
    Code:
       0: ldc           #38                 // String
       2: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
       5: astore_0
       6: aload_0
       7: invokestatic  #139                // Method transposeHorizontal:([[Ljava/lang/Double;)V
      10: return

  public static final void transposeHorizontal(java.lang.Double[][]);
    Code:
       0: aload_0
       1: ldc           #50                 // String mat
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_0
       9: iconst_0
      10: aaload
      11: arraylength
      12: istore_3
      13: iload_3
      14: anewarray     #63                 // class "[Ljava/lang/Double;"
      17: astore        4
      19: iload_2
      20: iload_3
      21: if_icmpge     91
      24: iload_2
      25: istore        5
      27: aload         4
      29: iload         5
      31: iconst_0
      32: istore        6
      34: aload_0
      35: checkcast     #58                 // class "[Ljava/lang/Object;"
      38: arraylength
      39: istore        7
      41: iload         7
      43: anewarray     #65                 // class java/lang/Double
      46: astore        8
      48: istore        11
      50: astore        10
      52: iload         6
      54: iload         7
      56: if_icmpge     78
      59: iload         6
      61: istore        9
      63: aload         8
      65: iload         9
      67: dconst_0
      68: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      71: aastore
      72: iinc          6, 1
      75: goto          52
      78: aload         10
      80: iload         11
      82: aload         8
      84: aastore
      85: iinc          2, 1
      88: goto          19
      91: aload         4
      93: astore_1
      94: aload_0
      95: checkcast     #58                 // class "[Ljava/lang/Object;"
      98: arraylength
      99: istore_2
     100: iconst_0
     101: istore_3
     102: iload_3
     103: iload_2
     104: if_icmpge     144
     107: iconst_0
     108: istore        4
     110: iload         4
     112: iload_2
     113: if_icmpge     138
     116: aload_1
     117: iload_2
     118: iconst_1
     119: isub
     120: iload_3
     121: isub
     122: aaload
     123: iload         4
     125: aload_0
     126: iload_3
     127: aaload
     128: iload         4
     130: aaload
     131: aastore
     132: iinc          4, 1
     135: goto          110
     138: iinc          3, 1
     141: goto          102
     144: ldc           #141                // String Transpose Vertical
     146: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
     149: swap
     150: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     153: aload_1
     154: invokestatic  #80                 // Method printMatrix:([[Ljava/lang/Double;)V
     157: return

  public static final void transposeVertical();
    Code:
       0: ldc           #38                 // String
       2: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
       5: astore_0
       6: aload_0
       7: invokestatic  #144                // Method transposeVertical:([[Ljava/lang/Double;)V
      10: return

  public static final void transposeVertical(java.lang.Double[][]);
    Code:
       0: aload_0
       1: ldc           #50                 // String mat
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_0
       9: iconst_0
      10: aaload
      11: arraylength
      12: istore_3
      13: iload_3
      14: anewarray     #63                 // class "[Ljava/lang/Double;"
      17: astore        4
      19: iload_2
      20: iload_3
      21: if_icmpge     91
      24: iload_2
      25: istore        5
      27: aload         4
      29: iload         5
      31: iconst_0
      32: istore        6
      34: aload_0
      35: checkcast     #58                 // class "[Ljava/lang/Object;"
      38: arraylength
      39: istore        7
      41: iload         7
      43: anewarray     #65                 // class java/lang/Double
      46: astore        8
      48: istore        11
      50: astore        10
      52: iload         6
      54: iload         7
      56: if_icmpge     78
      59: iload         6
      61: istore        9
      63: aload         8
      65: iload         9
      67: dconst_0
      68: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      71: aastore
      72: iinc          6, 1
      75: goto          52
      78: aload         10
      80: iload         11
      82: aload         8
      84: aastore
      85: iinc          2, 1
      88: goto          19
      91: aload         4
      93: astore_1
      94: aload_0
      95: checkcast     #58                 // class "[Ljava/lang/Object;"
      98: arraylength
      99: istore_2
     100: iconst_0
     101: istore_3
     102: iload_3
     103: iload_2
     104: if_icmpge     144
     107: iconst_0
     108: istore        4
     110: iload         4
     112: iload_2
     113: if_icmpge     138
     116: aload_1
     117: iload_3
     118: aaload
     119: iload_2
     120: iconst_1
     121: isub
     122: iload         4
     124: isub
     125: aload_0
     126: iload_3
     127: aaload
     128: iload         4
     130: aaload
     131: aastore
     132: iinc          4, 1
     135: goto          110
     138: iinc          3, 1
     141: goto          102
     144: ldc           #141                // String Transpose Vertical
     146: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
     149: swap
     150: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     153: aload_1
     154: invokestatic  #80                 // Method printMatrix:([[Ljava/lang/Double;)V
     157: return

  public static final void transposeSide();
    Code:
       0: ldc           #38                 // String
       2: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
       5: astore_0
       6: aload_0
       7: invokestatic  #146                // Method transposeSide:([[Ljava/lang/Double;)V
      10: return

  public static final void transposeSide(java.lang.Double[][]);
    Code:
       0: aload_0
       1: ldc           #50                 // String mat
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_0
       9: iconst_0
      10: aaload
      11: arraylength
      12: istore_3
      13: iload_3
      14: anewarray     #63                 // class "[Ljava/lang/Double;"
      17: astore        4
      19: iload_2
      20: iload_3
      21: if_icmpge     91
      24: iload_2
      25: istore        5
      27: aload         4
      29: iload         5
      31: iconst_0
      32: istore        6
      34: aload_0
      35: checkcast     #58                 // class "[Ljava/lang/Object;"
      38: arraylength
      39: istore        7
      41: iload         7
      43: anewarray     #65                 // class java/lang/Double
      46: astore        8
      48: istore        11
      50: astore        10
      52: iload         6
      54: iload         7
      56: if_icmpge     78
      59: iload         6
      61: istore        9
      63: aload         8
      65: iload         9
      67: dconst_0
      68: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      71: aastore
      72: iinc          6, 1
      75: goto          52
      78: aload         10
      80: iload         11
      82: aload         8
      84: aastore
      85: iinc          2, 1
      88: goto          19
      91: aload         4
      93: astore_1
      94: aload_0
      95: checkcast     #58                 // class "[Ljava/lang/Object;"
      98: arraylength
      99: istore_2
     100: iconst_0
     101: istore_3
     102: aload_0
     103: checkcast     #58                 // class "[Ljava/lang/Object;"
     106: arraylength
     107: istore        4
     109: iload_3
     110: iload         4
     112: if_icmpge     163
     115: iconst_0
     116: istore        5
     118: aload_0
     119: iconst_0
     120: aaload
     121: arraylength
     122: istore        6
     124: iload         5
     126: iload         6
     128: if_icmpge     157
     131: aload_1
     132: iload_2
     133: iconst_1
     134: isub
     135: iload         5
     137: isub
     138: aaload
     139: iload_2
     140: iconst_1
     141: isub
     142: iload_3
     143: isub
     144: aload_0
     145: iload_3
     146: aaload
     147: iload         5
     149: aaload
     150: aastore
     151: iinc          5, 1
     154: goto          124
     157: iinc          3, 1
     160: goto          109
     163: aload_1
     164: invokestatic  #80                 // Method printMatrix:([[Ljava/lang/Double;)V
     167: return

  public static final void transposeMain();
    Code:
       0: ldc           #38                 // String
       2: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
       5: astore_0
       6: aload_0
       7: invokestatic  #148                // Method transposeMain:([[Ljava/lang/Double;)V
      10: return

  public static final void transposeMain(java.lang.Double[][]);
    Code:
       0: aload_0
       1: ldc           #50                 // String mat
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_0
       9: iconst_0
      10: aaload
      11: arraylength
      12: istore_3
      13: iload_3
      14: anewarray     #63                 // class "[Ljava/lang/Double;"
      17: astore        4
      19: iload_2
      20: iload_3
      21: if_icmpge     91
      24: iload_2
      25: istore        5
      27: aload         4
      29: iload         5
      31: iconst_0
      32: istore        6
      34: aload_0
      35: checkcast     #58                 // class "[Ljava/lang/Object;"
      38: arraylength
      39: istore        7
      41: iload         7
      43: anewarray     #65                 // class java/lang/Double
      46: astore        8
      48: istore        11
      50: astore        10
      52: iload         6
      54: iload         7
      56: if_icmpge     78
      59: iload         6
      61: istore        9
      63: aload         8
      65: iload         9
      67: dconst_0
      68: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      71: aastore
      72: iinc          6, 1
      75: goto          52
      78: aload         10
      80: iload         11
      82: aload         8
      84: aastore
      85: iinc          2, 1
      88: goto          19
      91: aload         4
      93: astore_1
      94: iconst_0
      95: istore_2
      96: aload_0
      97: checkcast     #58                 // class "[Ljava/lang/Object;"
     100: arraylength
     101: istore_3
     102: iload_2
     103: iload_3
     104: if_icmpge     147
     107: iconst_0
     108: istore        4
     110: aload_0
     111: iconst_0
     112: aaload
     113: arraylength
     114: istore        5
     116: iload         4
     118: iload         5
     120: if_icmpge     141
     123: aload_1
     124: iload         4
     126: aaload
     127: iload_2
     128: aload_0
     129: iload_2
     130: aaload
     131: iload         4
     133: aaload
     134: aastore
     135: iinc          4, 1
     138: goto          116
     141: iinc          2, 1
     144: goto          102
     147: aload_1
     148: invokestatic  #80                 // Method printMatrix:([[Ljava/lang/Double;)V
     151: return

  public static final int readMenuTranposeOption();
    Code:
       0: iconst_0
       1: istore_0
       2: ldc           #150                // String 1. Main diagonal
       4: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
       7: swap
       8: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      11: ldc           #152                // String 2. Side diagonal
      13: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      16: swap
      17: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      20: ldc           #154                // String 3. Vertical line
      22: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      25: swap
      26: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      29: ldc           #156                // String 4. Horizontal line
      31: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      34: swap
      35: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      38: ldc           #158                // String Your choice:
      40: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      43: swap
      44: invokevirtual #161                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      47: invokestatic  #167                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      50: dup
      51: invokestatic  #170                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      54: invokestatic  #176                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
      57: dup
      58: ifnull        67
      61: invokevirtual #181                // Method java/lang/Integer.intValue:()I
      64: goto          69
      67: pop
      68: iconst_m1
      69: istore_0
      70: iconst_1
      71: iload_0
      72: if_icmpgt     88
      75: iload_0
      76: iconst_5
      77: if_icmpge     84
      80: iconst_1
      81: goto          89
      84: iconst_0
      85: goto          89
      88: iconst_0
      89: ifne          101
      92: ldc           #183                // String Incorrect option! Try again.
      94: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      97: swap
      98: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     101: iconst_1
     102: iload_0
     103: if_icmpgt     119
     106: iload_0
     107: iconst_5
     108: if_icmpge     115
     111: iconst_1
     112: goto          120
     115: iconst_0
     116: goto          120
     119: iconst_0
     120: ifeq          2
     123: iload_0
     124: ireturn

  public static final void multiplyMatrices();
    Code:
       0: ldc           #186                // String first
       2: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
       5: astore_0
       6: ldc           #188                // String second
       8: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
      11: astore_1
      12: aload_0
      13: aload_1
      14: invokestatic  #192                // Method multiplayMatrices:([[Ljava/lang/Double;[[Ljava/lang/Double;)V
      17: return

  public static final void multiplayMatrices(java.lang.Double[][], java.lang.Double[][]);
    Code:
       0: aload_0
       1: ldc           #195                // String m1
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #196                // String m2
       9: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iconst_0
      14: aaload
      15: arraylength
      16: aload_1
      17: checkcast     #58                 // class "[Ljava/lang/Object;"
      20: arraylength
      21: if_icmpeq     36
      24: ldc           #198                // String The operation cannot be performed.
      26: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      29: swap
      30: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      33: goto          243
      36: iconst_0
      37: istore_3
      38: aload_0
      39: checkcast     #58                 // class "[Ljava/lang/Object;"
      42: arraylength
      43: istore        4
      45: iload         4
      47: anewarray     #63                 // class "[Ljava/lang/Double;"
      50: astore        5
      52: iload_3
      53: iload         4
      55: if_icmpge     124
      58: iload_3
      59: istore        6
      61: aload         5
      63: iload         6
      65: iconst_0
      66: istore        7
      68: aload_1
      69: iconst_0
      70: aaload
      71: arraylength
      72: istore        8
      74: iload         8
      76: anewarray     #65                 // class java/lang/Double
      79: astore        9
      81: istore        12
      83: astore        11
      85: iload         7
      87: iload         8
      89: if_icmpge     111
      92: iload         7
      94: istore        10
      96: aload         9
      98: iload         10
     100: dconst_0
     101: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     104: aastore
     105: iinc          7, 1
     108: goto          85
     111: aload         11
     113: iload         12
     115: aload         9
     117: aastore
     118: iinc          3, 1
     121: goto          52
     124: aload         5
     126: astore_2
     127: iconst_0
     128: istore_3
     129: aload_0
     130: checkcast     #58                 // class "[Ljava/lang/Object;"
     133: arraylength
     134: istore        4
     136: iload_3
     137: iload         4
     139: if_icmpge     239
     142: iconst_0
     143: istore        5
     145: aload_1
     146: iconst_0
     147: aaload
     148: arraylength
     149: istore        6
     151: iload         5
     153: iload         6
     155: if_icmpge     233
     158: iconst_0
     159: istore        7
     161: aload_1
     162: checkcast     #58                 // class "[Ljava/lang/Object;"
     165: arraylength
     166: istore        8
     168: iload         7
     170: iload         8
     172: if_icmpge     227
     175: aload_2
     176: iload_3
     177: aaload
     178: astore        9
     180: iload         5
     182: istore        10
     184: aload         9
     186: iload         10
     188: aload         9
     190: iload         10
     192: aaload
     193: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
     196: aload_0
     197: iload_3
     198: aaload
     199: iload         7
     201: aaload
     202: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
     205: aload_1
     206: iload         7
     208: aaload
     209: iload         5
     211: aaload
     212: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
     215: dmul
     216: dadd
     217: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     220: aastore
     221: iinc          7, 1
     224: goto          168
     227: iinc          5, 1
     230: goto          151
     233: iinc          3, 1
     236: goto          136
     239: aload_2
     240: invokestatic  #80                 // Method printMatrix:([[Ljava/lang/Double;)V
     243: return

  public static final void multiplyByConstant();
    Code:
       0: ldc           #38                 // String
       2: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
       5: astore_0
       6: invokestatic  #203                // Method readConstant:()D
       9: dstore_1
      10: aload_0
      11: dload_1
      12: invokestatic  #207                // Method matrixByNumber:([[Ljava/lang/Double;D)V
      15: return

  public static final double readConstant();
    Code:
       0: dconst_0
       1: dstore_0
       2: ldc           #210                // String Enter constant:
       4: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
       7: swap
       8: invokevirtual #161                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      11: invokestatic  #167                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      14: dup
      15: invokestatic  #170                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      18: invokestatic  #214                // Method kotlin/text/StringsKt.toDoubleOrNull:(Ljava/lang/String;)Ljava/lang/Double;
      21: dup
      22: ifnull        31
      25: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
      28: goto          35
      31: pop
      32: ldc2_w        #215                // double 1.7976931348623157E308d
      35: dstore_0
      36: dload_0
      37: ldc2_w        #215                // double 1.7976931348623157E308d
      40: dcmpg
      41: ifne          48
      44: iconst_1
      45: goto          49
      48: iconst_0
      49: ifne          2
      52: dload_0
      53: dreturn

  public static final void addMatrices();
    Code:
       0: ldc           #186                // String first
       2: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
       5: astore_0
       6: ldc           #188                // String second
       8: invokestatic  #42                 // Method readMatrix:(Ljava/lang/String;)[[Ljava/lang/Double;
      11: astore_1
      12: aload_0
      13: aload_1
      14: invokestatic  #218                // Method addMatrices:([[Ljava/lang/Double;[[Ljava/lang/Double;)V
      17: return

  public static final int readMenuOption();
    Code:
       0: iconst_0
       1: istore_0
       2: ldc           #220                // String 1. Add matrices
       4: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
       7: swap
       8: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      11: ldc           #222                // String 2. Multiply matrix by a constant
      13: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      16: swap
      17: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      20: ldc           #224                // String 3. Multiply matrices
      22: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      25: swap
      26: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      29: ldc           #226                // String 4. Transpose matrix
      31: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      34: swap
      35: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      38: ldc           #228                // String 5. Calculate a determinant
      40: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      43: swap
      44: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      47: ldc           #230                // String 6. Inverse matrix
      49: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      52: swap
      53: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      56: ldc           #232                // String 0. Exit
      58: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: swap
      62: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      65: ldc           #158                // String Your choice:
      67: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      70: swap
      71: invokevirtual #161                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      74: invokestatic  #167                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      77: dup
      78: invokestatic  #170                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      81: invokestatic  #176                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
      84: dup
      85: ifnull        94
      88: invokevirtual #181                // Method java/lang/Integer.intValue:()I
      91: goto          96
      94: pop
      95: iconst_m1
      96: istore_0
      97: iconst_0
      98: iload_0
      99: if_icmpgt     116
     102: iload_0
     103: bipush        7
     105: if_icmpge     112
     108: iconst_1
     109: goto          117
     112: iconst_0
     113: goto          117
     116: iconst_0
     117: ifne          129
     120: ldc           #183                // String Incorrect option! Try again.
     122: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
     125: swap
     126: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     129: iconst_0
     130: iload_0
     131: if_icmpgt     148
     134: iload_0
     135: bipush        7
     137: if_icmpge     144
     140: iconst_1
     141: goto          149
     144: iconst_0
     145: goto          149
     148: iconst_0
     149: ifeq          2
     152: iload_0
     153: ireturn

  public static final void exit();
    Code:
       0: iconst_0
       1: invokestatic  #235                // Method java/lang/System.exit:(I)V
       4: new           #237                // class java/lang/RuntimeException
       7: dup
       8: ldc           #239                // String System.exit returned normally, while it was supposed to halt JVM.
      10: invokespecial #243                // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
      13: athrow

  public static final void matrixByNumber(java.lang.Double[][], double);
    Code:
       0: aload_0
       1: ldc           #245                // String matrix
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore        4
       9: aload_0
      10: checkcast     #58                 // class "[Ljava/lang/Object;"
      13: arraylength
      14: istore        5
      16: iload         5
      18: anewarray     #63                 // class "[Ljava/lang/Double;"
      21: astore        6
      23: iload         4
      25: iload         5
      27: if_icmpge     97
      30: iload         4
      32: istore        7
      34: aload         6
      36: iload         7
      38: iconst_0
      39: istore        8
      41: aload_0
      42: iconst_0
      43: aaload
      44: arraylength
      45: istore        9
      47: iload         9
      49: anewarray     #65                 // class java/lang/Double
      52: astore        10
      54: istore        13
      56: astore        12
      58: iload         8
      60: iload         9
      62: if_icmpge     84
      65: iload         8
      67: istore        11
      69: aload         10
      71: iload         11
      73: dconst_0
      74: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      77: aastore
      78: iinc          8, 1
      81: goto          58
      84: aload         12
      86: iload         13
      88: aload         10
      90: aastore
      91: iinc          4, 1
      94: goto          23
      97: aload         6
      99: astore_3
     100: iconst_0
     101: istore        4
     103: aload_0
     104: checkcast     #58                 // class "[Ljava/lang/Object;"
     107: arraylength
     108: istore        5
     110: iload         4
     112: iload         5
     114: if_icmpge     168
     117: iconst_0
     118: istore        6
     120: aload_0
     121: iload         4
     123: aaload
     124: arraylength
     125: istore        7
     127: iload         6
     129: iload         7
     131: if_icmpge     162
     134: aload_3
     135: iload         4
     137: aaload
     138: iload         6
     140: dload_1
     141: aload_0
     142: iload         4
     144: aaload
     145: iload         6
     147: aaload
     148: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
     151: dmul
     152: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     155: aastore
     156: iinc          6, 1
     159: goto          127
     162: iinc          4, 1
     165: goto          110
     168: aload_3
     169: invokestatic  #80                 // Method printMatrix:([[Ljava/lang/Double;)V
     172: return

  public static final void printMatrix(java.lang.Double[][]);
    Code:
       0: aload_0
       1: ldc           #247                // String m
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #249                // String The result is:
       8: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      11: swap
      12: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      15: iconst_0
      16: istore_1
      17: aload_0
      18: checkcast     #58                 // class "[Ljava/lang/Object;"
      21: arraylength
      22: istore_2
      23: iload_1
      24: iload_2
      25: if_icmpge     93
      28: iconst_0
      29: istore_3
      30: aload_0
      31: iload_1
      32: aaload
      33: arraylength
      34: istore        4
      36: iload_3
      37: iload         4
      39: if_icmpge     81
      42: new           #251                // class java/lang/StringBuilder
      45: dup
      46: invokespecial #253                // Method java/lang/StringBuilder."<init>":()V
      49: aload_0
      50: iload_1
      51: aaload
      52: iload_3
      53: aaload
      54: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
      57: invokevirtual #257                // Method java/lang/StringBuilder.append:(D)Ljava/lang/StringBuilder;
      60: bipush        32
      62: invokevirtual #260                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      65: invokevirtual #263                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      68: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      71: swap
      72: invokevirtual #161                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      75: iinc          3, 1
      78: goto          36
      81: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      84: invokevirtual #265                // Method java/io/PrintStream.println:()V
      87: iinc          1, 1
      90: goto          23
      93: return

  public static final void addMatrices(java.lang.Double[][], java.lang.Double[][]);
    Code:
       0: aload_0
       1: ldc           #195                // String m1
       3: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #196                // String m2
       9: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #58                 // class "[Ljava/lang/Object;"
      16: arraylength
      17: aload_1
      18: checkcast     #58                 // class "[Ljava/lang/Object;"
      21: arraylength
      22: if_icmpne     36
      25: aload_0
      26: iconst_0
      27: aaload
      28: arraylength
      29: aload_1
      30: iconst_0
      31: aaload
      32: arraylength
      33: if_icmpeq     48
      36: ldc           #198                // String The operation cannot be performed.
      38: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      41: swap
      42: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      45: goto          214
      48: iconst_0
      49: istore_3
      50: aload_0
      51: checkcast     #58                 // class "[Ljava/lang/Object;"
      54: arraylength
      55: istore        4
      57: iload         4
      59: anewarray     #63                 // class "[Ljava/lang/Double;"
      62: astore        5
      64: iload_3
      65: iload         4
      67: if_icmpge     136
      70: iload_3
      71: istore        6
      73: aload         5
      75: iload         6
      77: iconst_0
      78: istore        7
      80: aload_0
      81: iconst_0
      82: aaload
      83: arraylength
      84: istore        8
      86: iload         8
      88: anewarray     #65                 // class java/lang/Double
      91: astore        9
      93: istore        12
      95: astore        11
      97: iload         7
      99: iload         8
     101: if_icmpge     123
     104: iload         7
     106: istore        10
     108: aload         9
     110: iload         10
     112: dconst_0
     113: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     116: aastore
     117: iinc          7, 1
     120: goto          97
     123: aload         11
     125: iload         12
     127: aload         9
     129: aastore
     130: iinc          3, 1
     133: goto          64
     136: aload         5
     138: astore_2
     139: iconst_0
     140: istore_3
     141: aload_0
     142: checkcast     #58                 // class "[Ljava/lang/Object;"
     145: arraylength
     146: istore        4
     148: iload_3
     149: iload         4
     151: if_icmpge     210
     154: iconst_0
     155: istore        5
     157: aload_0
     158: iload_3
     159: aaload
     160: arraylength
     161: istore        6
     163: iload         5
     165: iload         6
     167: if_icmpge     204
     170: aload_2
     171: iload_3
     172: aaload
     173: iload         5
     175: aload_0
     176: iload_3
     177: aaload
     178: iload         5
     180: aaload
     181: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
     184: aload_1
     185: iload_3
     186: aaload
     187: iload         5
     189: aaload
     190: invokevirtual #77                 // Method java/lang/Double.doubleValue:()D
     193: dadd
     194: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     197: aastore
     198: iinc          5, 1
     201: goto          163
     204: iinc          3, 1
     207: goto          148
     210: aload_2
     211: invokestatic  #80                 // Method printMatrix:([[Ljava/lang/Double;)V
     214: return

  public static final java.lang.Double[][] readMatrix(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #267                // String type
       4: invokestatic  #56                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #251                // class java/lang/StringBuilder
      10: dup
      11: invokespecial #253                // Method java/lang/StringBuilder."<init>":()V
      14: ldc_w         #269                // String Enter size of
      17: invokevirtual #272                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      20: aload_0
      21: invokevirtual #272                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: ldc_w         #274                // String  matrix:
      27: invokevirtual #272                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      30: invokevirtual #263                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      33: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #161                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      40: invokestatic  #167                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      43: dup
      44: invokestatic  #170                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      47: checkcast     #276                // class java/lang/CharSequence
      50: iconst_1
      51: anewarray     #278                // class java/lang/String
      54: astore_2
      55: aload_2
      56: iconst_0
      57: ldc_w         #280                // String
      60: aastore
      61: aload_2
      62: iconst_0
      63: iconst_0
      64: bipush        6
      66: aconst_null
      67: invokestatic  #284                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      70: checkcast     #286                // class java/lang/Iterable
      73: astore_2
      74: iconst_0
      75: istore_3
      76: aload_2
      77: astore        4
      79: new           #288                // class java/util/ArrayList
      82: dup
      83: aload_2
      84: bipush        10
      86: invokestatic  #294                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      89: invokespecial #296                // Method java/util/ArrayList."<init>":(I)V
      92: checkcast     #298                // class java/util/Collection
      95: astore        5
      97: iconst_0
      98: istore        6
     100: aload         4
     102: invokeinterface #302,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     107: astore        7
     109: aload         7
     111: invokeinterface #308,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     116: ifeq          163
     119: aload         7
     121: invokeinterface #312,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     126: astore        8
     128: aload         5
     130: aload         8
     132: checkcast     #278                // class java/lang/String
     135: astore        9
     137: astore        16
     139: iconst_0
     140: istore        10
     142: aload         9
     144: invokestatic  #316                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     147: nop
     148: invokestatic  #319                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     151: aload         16
     153: swap
     154: invokeinterface #323,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     159: pop
     160: goto          109
     163: aload         5
     165: checkcast     #325                // class java/util/List
     168: nop
     169: astore_1
     170: aload_1
     171: iconst_0
     172: invokeinterface #329,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     177: checkcast     #331                // class java/lang/Number
     180: invokevirtual #332                // Method java/lang/Number.intValue:()I
     183: istore_2
     184: aload_1
     185: iconst_1
     186: invokeinterface #329,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     191: checkcast     #331                // class java/lang/Number
     194: invokevirtual #332                // Method java/lang/Number.intValue:()I
     197: istore_3
     198: iconst_0
     199: istore        5
     201: iload_2
     202: anewarray     #63                 // class "[Ljava/lang/Double;"
     205: astore        6
     207: iload         5
     209: iload_2
     210: if_icmpge     272
     213: iload         5
     215: istore        7
     217: aload         6
     219: iload         7
     221: iconst_0
     222: istore        8
     224: iload_3
     225: anewarray     #65                 // class java/lang/Double
     228: astore        9
     230: istore        17
     232: astore        16
     234: iload         8
     236: iload_3
     237: if_icmpge     259
     240: iload         8
     242: istore        10
     244: aload         9
     246: iload         10
     248: dconst_0
     249: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     252: aastore
     253: iinc          8, 1
     256: goto          234
     259: aload         16
     261: iload         17
     263: aload         9
     265: aastore
     266: iinc          5, 1
     269: goto          207
     272: aload         6
     274: astore        4
     276: new           #251                // class java/lang/StringBuilder
     279: dup
     280: invokespecial #253                // Method java/lang/StringBuilder."<init>":()V
     283: ldc_w         #334                // String Enter
     286: invokevirtual #272                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     289: aload_0
     290: invokevirtual #272                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     293: ldc_w         #274                // String  matrix:
     296: invokevirtual #272                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     299: invokevirtual #263                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     302: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
     305: swap
     306: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     309: iconst_0
     310: istore        5
     312: iload         5
     314: iload_2
     315: if_icmpge     494
     318: invokestatic  #167                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
     321: dup
     322: invokestatic  #170                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     325: checkcast     #276                // class java/lang/CharSequence
     328: iconst_1
     329: anewarray     #278                // class java/lang/String
     332: astore        7
     334: aload         7
     336: iconst_0
     337: ldc_w         #280                // String
     340: aastore
     341: aload         7
     343: iconst_0
     344: iconst_0
     345: bipush        6
     347: aconst_null
     348: invokestatic  #284                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     351: checkcast     #286                // class java/lang/Iterable
     354: astore        7
     356: iconst_0
     357: istore        8
     359: aload         7
     361: astore        9
     363: new           #288                // class java/util/ArrayList
     366: dup
     367: aload         7
     369: bipush        10
     371: invokestatic  #294                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     374: invokespecial #296                // Method java/util/ArrayList."<init>":(I)V
     377: checkcast     #298                // class java/util/Collection
     380: astore        10
     382: iconst_0
     383: istore        11
     385: aload         9
     387: invokeinterface #302,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     392: astore        12
     394: aload         12
     396: invokeinterface #308,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     401: ifeq          448
     404: aload         12
     406: invokeinterface #312,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     411: astore        13
     413: aload         10
     415: aload         13
     417: checkcast     #278                // class java/lang/String
     420: astore        14
     422: astore        16
     424: iconst_0
     425: istore        15
     427: aload         14
     429: invokestatic  #338                // Method java/lang/Double.parseDouble:(Ljava/lang/String;)D
     432: nop
     433: invokestatic  #69                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     436: aload         16
     438: swap
     439: invokeinterface #323,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     444: pop
     445: goto          394
     448: aload         10
     450: checkcast     #325                // class java/util/List
     453: nop
     454: astore        6
     456: iconst_0
     457: istore        7
     459: iload         7
     461: iload_3
     462: if_icmpge     488
     465: aload         4
     467: iload         5
     469: aaload
     470: iload         7
     472: aload         6
     474: iload         7
     476: invokeinterface #329,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     481: aastore
     482: iinc          7, 1
     485: goto          459
     488: iinc          5, 1
     491: goto          312
     494: aload         4
     496: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #356                // Method main:()V
       3: return
}


package daily

fun main() {
    val solution = Solution154()
    //1
    val array = solution.minArray(intArrayOf(3, 4, 5, 1, 2))
    //1
    val array1 = solution.minArray(intArrayOf(1, 2, 3, 4, 5))
    //5
    val array2 = solution.minArray(intArrayOf(5, 15, 5, 5, 5))
    //4
    val array4 = solution.minArray(intArrayOf(5, 15, 4, 5, 5))
    //1
    val array3 = solution.minArray(intArrayOf(5, 5, 5, 1, 2))
}

class Solution154 {
    fun minArray(numbers: IntArray): Int {
        //未旋转
        if (numbers[0] < numbers[numbers.size-1]) return numbers[0]
        return lbs(numbers,0,numbers.size-1)
    }

    /**
     * 向左二分查找 (left,right]
     */
    fun lbs(numbers: IntArray,left:Int,right:Int):Int {
        if(left>=right-1) return numbers[right]
        val mid = (left+right)/2
        return if(numbers[right] > numbers[mid]) lbs(numbers,left,mid)
        else if(numbers[right] < numbers[mid]) lbs(numbers,mid,right)
        else Math.min(lbs(numbers, left, mid),lbs(numbers, mid, right))
    }
}

Compiled from "LeetCode154.kt"
public final class daily.LeetCode154Kt {
  public static final void main();
    Code:
       0: new           #8                  // class daily/Solution154
       3: dup
       4: invokespecial #11                 // Method daily/Solution154."<init>":()V
       7: astore_0
       8: aload_0
       9: iconst_5
      10: newarray       int
      12: astore_2
      13: aload_2
      14: iconst_0
      15: iconst_3
      16: iastore
      17: aload_2
      18: iconst_1
      19: iconst_4
      20: iastore
      21: aload_2
      22: iconst_2
      23: iconst_5
      24: iastore
      25: aload_2
      26: iconst_3
      27: iconst_1
      28: iastore
      29: aload_2
      30: iconst_4
      31: iconst_2
      32: iastore
      33: aload_2
      34: invokevirtual #15                 // Method daily/Solution154.minArray:([I)I
      37: istore_1
      38: aload_0
      39: iconst_5
      40: newarray       int
      42: astore_3
      43: aload_3
      44: iconst_0
      45: iconst_1
      46: iastore
      47: aload_3
      48: iconst_1
      49: iconst_2
      50: iastore
      51: aload_3
      52: iconst_2
      53: iconst_3
      54: iastore
      55: aload_3
      56: iconst_3
      57: iconst_4
      58: iastore
      59: aload_3
      60: iconst_4
      61: iconst_5
      62: iastore
      63: aload_3
      64: invokevirtual #15                 // Method daily/Solution154.minArray:([I)I
      67: istore_2
      68: aload_0
      69: iconst_5
      70: newarray       int
      72: astore        4
      74: aload         4
      76: iconst_0
      77: iconst_5
      78: iastore
      79: aload         4
      81: iconst_1
      82: bipush        15
      84: iastore
      85: aload         4
      87: iconst_2
      88: iconst_5
      89: iastore
      90: aload         4
      92: iconst_3
      93: iconst_5
      94: iastore
      95: aload         4
      97: iconst_4
      98: iconst_5
      99: iastore
     100: aload         4
     102: invokevirtual #15                 // Method daily/Solution154.minArray:([I)I
     105: istore_3
     106: aload_0
     107: iconst_5
     108: newarray       int
     110: astore        5
     112: aload         5
     114: iconst_0
     115: iconst_5
     116: iastore
     117: aload         5
     119: iconst_1
     120: bipush        15
     122: iastore
     123: aload         5
     125: iconst_2
     126: iconst_4
     127: iastore
     128: aload         5
     130: iconst_3
     131: iconst_5
     132: iastore
     133: aload         5
     135: iconst_4
     136: iconst_5
     137: iastore
     138: aload         5
     140: invokevirtual #15                 // Method daily/Solution154.minArray:([I)I
     143: istore        4
     145: aload_0
     146: iconst_5
     147: newarray       int
     149: astore        6
     151: aload         6
     153: iconst_0
     154: iconst_5
     155: iastore
     156: aload         6
     158: iconst_1
     159: iconst_5
     160: iastore
     161: aload         6
     163: iconst_2
     164: iconst_5
     165: iastore
     166: aload         6
     168: iconst_3
     169: iconst_1
     170: iastore
     171: aload         6
     173: iconst_4
     174: iconst_2
     175: iastore
     176: aload         6
     178: invokevirtual #15                 // Method daily/Solution154.minArray:([I)I
     181: istore        5
     183: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #26                 // Method main:()V
       3: return
}


package daily

import java.util.*

fun main() {
    //16
    val i = SolutionLCP13().minimalSteps(arrayOf("S#O", "M..", "M.T"));
    //-1
    val i1 = SolutionLCP13().minimalSteps(arrayOf("S#O", "M.#", "M.T"));
    //17
    val i2 = SolutionLCP13().minimalSteps(arrayOf("S#O", "M.T", "M.."));
}

class SolutionLCP13 {

    data class Point(val x:Int,val y:Int)
    fun minimalSteps(maze: Array<String>): Int {
        var xS = 0
        var yS = 0
        var xT = 0
        var yT = 0
        var numofO = 0
        var numofM = 0
        val hashMapO = HashMap<Point, Int>()
        val hashMapM = HashMap<Point, Int>()
        for (i in maze.indices) {
            for (j in maze[i].indices) {
                when(maze[i][j]) {
                    'O'-> hashMapO.put(Point(i,j),numofO++)
                    'M'-> hashMapM.put(Point(i,j),numofM++)
                    'S'-> {
                        xS = i
                        yS = j
                    }
                    'T'-> {
                        xT = i
                        yT = j
                    }
                }
            }
        }
        //result = 所有最小(M->O)之和  +  最小(S->O->M0 + M1->T - M1->O)
        //需要统计的只有：
        //   1. S->所有O的最短距离；————>BFS
        val minS2Os = IntArray(numofO){Int.MAX_VALUE}
        //   2. 所有O->最近M的最短距离；————>BFS
        val minO2Ms = IntArray(numofO){Int.MAX_VALUE}
        val minPointO2Ms = Array<Point>(numofO) { Point(0,0) }
        //   2. 所有M->最近O的最短距离；————>BFS
        val minM2Os = IntArray(numofM){Int.MAX_VALUE}
        //   3. 所有M->T的最短距离；————BFS (2.和3.可以在同一轮BFS解决)
        val minM2Ts = IntArray(numofM){Int.MAX_VALUE}

        //BFS(S) S->所有O的最短距离
        val queue = LinkedList<Point>()
        var deep = 0
        queue.offer(Point(xS,yS))
        var colors = Array(maze.size) {BooleanArray(maze[0].length) {false} }
        while (!queue.isEmpty()) {
            val size = queue.size
            for (i in 0 until size) {
                val pop = queue.poll()
                if(colors[pop.x][pop.y]) continue
                colors[pop.x][pop.y] = true
                if(maze[pop.x][pop.y] == '#') continue
                if(maze[pop.x][pop.y] == 'O') {
                    minS2Os[hashMapO[pop]!!] = Math.min(deep, minS2Os[hashMapO[pop]!!])
                }
                if(pop.x > 0) queue.offer(Point(pop.x - 1,pop.y))
                if(pop.x < maze.size - 1) queue.offer(Point(pop.x + 1,pop.y))
                if(pop.y > 0) queue.offer(Point(pop.x,pop.y - 1))
                if(pop.y < maze[pop.x].length - 1) queue.offer(Point(pop.x,pop.y + 1))
                deep++
            }
        }

        //   2. 所有O->最近M的最短距离；————>BFS
        loop@ for (O in hashMapO.keys) {
            queue.clear()
            deep = 0
            queue.offer(O)
            colors = Array(maze.size) {BooleanArray(maze[0].length) {false} }
            while (!queue.isEmpty()) {
                val size = queue.size
                for (i in 0 until size) {
                    val pop = queue.pop()
                    if(colors[pop.x][pop.y]) continue
                    colors[pop.x][pop.y] = true
                    if(maze[pop.x][pop.y] == '#') continue
                    if(maze[pop.x][pop.y] == 'M') {
                        minO2Ms[hashMapO[O]!!] = deep
                        minPointO2Ms[hashMapO[O]!!] = pop
                        continue@loop
                    }
                    if(pop.x > 0) queue.offer(Point(pop.x - 1,pop.y))
                    if(pop.x < maze.size - 1) queue.offer(Point(pop.x + 1,pop.y))
                    if(pop.y > 0) queue.offer(Point(pop.x,pop.y - 1))
                    if(pop.y < maze[pop.x].length - 1) queue.offer(Point(pop.x,pop.y + 1))
                    deep++
                }
            }
        }

        loop2@for (M in hashMapM.keys) {
            queue.clear()
            deep = 0
            queue.offer(M)
            colors = Array(maze.size) {BooleanArray(maze[0].length) {false} }
            var findO = false
            var findT = false
            while (!queue.isEmpty()) {
                val size = queue.size
                for (i in 0 until size) {
                    val pop = queue.pop()
                    if(colors[pop.x][pop.y]) continue
                    colors[pop.x][pop.y] = true
                    if(maze[pop.x][pop.y] == '#') continue
                    if(!findO && maze[pop.x][pop.y] == 'O') {
                        minM2Os[hashMapM[M]!!] = deep
                        findO = true
                    }
                    if(!findT && maze[pop.x][pop.y] == 'T') {
                        minM2Ts[hashMapM[M]!!] = deep
                        findT = true
                    }
                    if(findO && findT) continue@loop2
                    if(pop.x > 0) queue.offer(Point(pop.x - 1,pop.y))
                    if(pop.x < maze.size - 1) queue.offer(Point(pop.x + 1,pop.y))
                    if(pop.y > 0) queue.offer(Point(pop.x,pop.y - 1))
                    if(pop.y < maze[pop.x].length - 1) queue.offer(Point(pop.x,pop.y + 1))
                    deep++
                }
            }
        }

        //最小(S->O->M0 + M1->T - M1->O)
        var minS2O2MAndM2TSubM2O = Int.MAX_VALUE
        for (i in minS2Os.indices) for (j in minO2Ms.indices) for (x in minM2Os.indices) for (y in minM2Ts.indices) minS2O2MAndM2TSubM2O = if(minPointO2Ms[j] == getKey(hashMapM,x)) minS2O2MAndM2TSubM2O else Math.min(minS2O2MAndM2TSubM2O, minS2Os[i] + minM2Os[j] - minM2Os[x] + minM2Ts[y])

        return minM2Os.sum() + minS2O2MAndM2TSubM2O
    }

    private fun getKey(hashMapM: HashMap<Point, Int>, x: Int): Point {
         for ((k,v) in hashMapM) {
             if (v == x) return k
         }
        return Point(1,1)
    }
}

Compiled from "LeetCodeLCP13.kt"
public final class daily.LeetCodeLCP13Kt {
  public static final void main();
    Code:
       0: new           #8                  // class daily/SolutionLCP13
       3: dup
       4: invokespecial #11                 // Method daily/SolutionLCP13."<init>":()V
       7: iconst_3
       8: anewarray     #13                 // class java/lang/String
      11: astore_1
      12: aload_1
      13: iconst_0
      14: ldc           #15                 // String S#O
      16: aastore
      17: aload_1
      18: iconst_1
      19: ldc           #17                 // String M..
      21: aastore
      22: aload_1
      23: iconst_2
      24: ldc           #19                 // String M.T
      26: aastore
      27: aload_1
      28: invokevirtual #23                 // Method daily/SolutionLCP13.minimalSteps:([Ljava/lang/String;)I
      31: istore_0
      32: new           #8                  // class daily/SolutionLCP13
      35: dup
      36: invokespecial #11                 // Method daily/SolutionLCP13."<init>":()V
      39: iconst_3
      40: anewarray     #13                 // class java/lang/String
      43: astore_2
      44: aload_2
      45: iconst_0
      46: ldc           #15                 // String S#O
      48: aastore
      49: aload_2
      50: iconst_1
      51: ldc           #25                 // String M.#
      53: aastore
      54: aload_2
      55: iconst_2
      56: ldc           #19                 // String M.T
      58: aastore
      59: aload_2
      60: invokevirtual #23                 // Method daily/SolutionLCP13.minimalSteps:([Ljava/lang/String;)I
      63: istore_1
      64: new           #8                  // class daily/SolutionLCP13
      67: dup
      68: invokespecial #11                 // Method daily/SolutionLCP13."<init>":()V
      71: iconst_3
      72: anewarray     #13                 // class java/lang/String
      75: astore_3
      76: aload_3
      77: iconst_0
      78: ldc           #15                 // String S#O
      80: aastore
      81: aload_3
      82: iconst_1
      83: ldc           #19                 // String M.T
      85: aastore
      86: aload_3
      87: iconst_2
      88: ldc           #17                 // String M..
      90: aastore
      91: aload_3
      92: invokevirtual #23                 // Method daily/SolutionLCP13.minimalSteps:([Ljava/lang/String;)I
      95: istore_2
      96: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #32                 // Method main:()V
       3: return
}


package daily

fun main() {
    val solution = Solution167()
    //4,5
    val twoSum4 = solution.twoSum(intArrayOf(1,2,3,4,4,8,9,75), 8)
    //2,3
    val twoSum3 = solution.twoSum(intArrayOf(5,25,75), 100)
    //1，2
    val twoSum = solution.twoSum(intArrayOf(2, 7, 11, 15), 9)
    //1,5
    val twoSum2 = solution.twoSum(intArrayOf(-995, -856, 456, 7856, 65454), 64459)
}

/**
 * 两数之和——找到数组中两数之和等于目标的索引（索引以1开始）,输出一个答案
 */
class Solution167 {
    fun twoSum(numbers: IntArray, target: Int): IntArray {
        var a = 0
        var b = 0
        for (i in numbers.indices) {
            b = numbers.binarySearch(target - numbers[i])
            if(b == i) b = numbers.binarySearch(target - numbers[i], b + 1)
            if(b > 0) {
                b++
                a = i + 1
                break
            }
        }
        return intArrayOf(a,b)
    }
}

Compiled from "LeetCode167.kt"
public final class daily.LeetCode167Kt {
  public static final void main();
    Code:
       0: new           #8                  // class daily/Solution167
       3: dup
       4: invokespecial #11                 // Method daily/Solution167."<init>":()V
       7: astore_0
       8: aload_0
       9: bipush        8
      11: newarray       int
      13: astore_2
      14: aload_2
      15: iconst_0
      16: iconst_1
      17: iastore
      18: aload_2
      19: iconst_1
      20: iconst_2
      21: iastore
      22: aload_2
      23: iconst_2
      24: iconst_3
      25: iastore
      26: aload_2
      27: iconst_3
      28: iconst_4
      29: iastore
      30: aload_2
      31: iconst_4
      32: iconst_4
      33: iastore
      34: aload_2
      35: iconst_5
      36: bipush        8
      38: iastore
      39: aload_2
      40: bipush        6
      42: bipush        9
      44: iastore
      45: aload_2
      46: bipush        7
      48: bipush        75
      50: iastore
      51: aload_2
      52: bipush        8
      54: invokevirtual #15                 // Method daily/Solution167.twoSum:([II)[I
      57: astore_1
      58: aload_0
      59: iconst_3
      60: newarray       int
      62: astore_3
      63: aload_3
      64: iconst_0
      65: iconst_5
      66: iastore
      67: aload_3
      68: iconst_1
      69: bipush        25
      71: iastore
      72: aload_3
      73: iconst_2
      74: bipush        75
      76: iastore
      77: aload_3
      78: bipush        100
      80: invokevirtual #15                 // Method daily/Solution167.twoSum:([II)[I
      83: astore_2
      84: aload_0
      85: iconst_4
      86: newarray       int
      88: astore        4
      90: aload         4
      92: iconst_0
      93: iconst_2
      94: iastore
      95: aload         4
      97: iconst_1
      98: bipush        7
     100: iastore
     101: aload         4
     103: iconst_2
     104: bipush        11
     106: iastore
     107: aload         4
     109: iconst_3
     110: bipush        15
     112: iastore
     113: aload         4
     115: bipush        9
     117: invokevirtual #15                 // Method daily/Solution167.twoSum:([II)[I
     120: astore_3
     121: aload_0
     122: iconst_5
     123: newarray       int
     125: astore        5
     127: aload         5
     129: iconst_0
     130: sipush        -995
     133: iastore
     134: aload         5
     136: iconst_1
     137: sipush        -856
     140: iastore
     141: aload         5
     143: iconst_2
     144: sipush        456
     147: iastore
     148: aload         5
     150: iconst_3
     151: sipush        7856
     154: iastore
     155: aload         5
     157: iconst_4
     158: ldc           #16                 // int 65454
     160: iastore
     161: aload         5
     163: ldc           #17                 // int 64459
     165: invokevirtual #15                 // Method daily/Solution167.twoSum:([II)[I
     168: astore        4
     170: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #26                 // Method main:()V
       3: return
}