package processor

import java.text.DecimalFormat

private val regexp = "\\s+".toRegex()
var decimalFormat = DecimalFormat("#0.##")

fun main() {
    while (true) {
        printMenu()
        print("Your choice: ")
        when (readln().toInt()) {
            0 -> break
            1 -> {
                val m1 = readMatrix("first")
                val m2 = readMatrix("second")
                if (isAdditionAllowed(m1, m2)) {
                    printMatrix(addMatrices(m1, m2))
                } else {
                    println("The operation cannot be performed.")
                }
            }
            2 -> {
                val m1 = readMatrix()
                print("Enter constant: ")
                val constant = readln().toDouble()
                printMatrix(multiplyMatrixByConstant(m1, constant))
            }
            3 -> {
                val m1 = readMatrix("first")
                val m2 = readMatrix("second")
                if (isMultiplicationAllowed(m1, m2)) {
                    printMatrix(multiplyMatrices(m1, m2))
                } else {
                    println("The operation cannot be performed.")
                }
            }
            4 -> {
                printTransposeMatrixMenu()
                print("Your choice: ")
                val strategy = TransposeStrategy.byNumber(readln().toInt())
                val m = readMatrix()
                strategy.transpose(m)
                printMatrix(m)
            }
            5 -> {
                val m = readMatrix()
                if (m.isSquare()) {
                    println("The result is:")
                    println(m.determinant())
                } else {
                    println("The operation cannot be performed.")
                }
            }
            6 -> {
                val m = readMatrix()
                if (m.isSquare()) {
                    val inverse = findMatrixInverse(m)
                    if (inverse == null) {
                        println("This matrix doesn't have an inverse.")
                    } else {
                        printMatrix(inverse)
                    }
                } else {
                    println("The operation cannot be performed.")
                }
            }
            else -> println("Wrong choice!")
        }
    }
}

private fun printMenu() {
    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")
}

private fun readMatrix(matrixName: String = ""): Matrix {
    val matrixNamePlaceholder = if (matrixName.isNotBlank()) " " else "" + matrixName.trim()
    print("Enter size of$matrixNamePlaceholder matrix: ")
    val (n, m) = readln().split(regexp).map { it.toInt() }
    val result = Matrix.empty(n, m)
    println("Enter$matrixNamePlaceholder matrix:")
    repeat(n) { x ->
        val row = readln().split(regexp).map { it.toDouble() }
        check(row.size == m)
        row.forEachIndexed { y, e -> result[x, y] = e }
    }
    return result
}

private fun isAdditionAllowed(m1: Matrix, m2: Matrix) =
    m1.sizesOfDimensions.contentEquals(m2.sizesOfDimensions)

private fun addMatrices(m1: Matrix, m2: Matrix): Matrix {
    val (n, m) = m1.sizesOfDimensions
    val result = Matrix.empty(n, m)
    repeat(n) { x ->
        repeat(m) { y ->
            result[x, y] = m1[x, y] + m2[x, y]
        }
    }
    return result
}

private fun multiplyMatrixByConstant(matrix: Matrix, c: Double): Matrix {
    val (n, m) = matrix.sizesOfDimensions
    val result = Matrix.empty(n, m)
    repeat(n) { x ->
        repeat(m) { y ->
            result[x, y] = matrix[x, y] * c
        }
    }
    return result
}

private fun isMultiplicationAllowed(m1: Matrix, m2: Matrix): Boolean {
    val (_, m1d2) = m1.sizesOfDimensions
    val (m2d1, _) = m2.sizesOfDimensions
    return m1d2 == m2d1
}

private fun multiplyMatrices(m1: Matrix, m2: Matrix): Matrix {
    val (n, m) = m1.sizesOfDimensions
    val (_, k) = m2.sizesOfDimensions
    val result = Matrix.empty(n, k)
    repeat(n) { x ->
        repeat(k) { y ->
            val dotProduct = (0 until m).sumOf { idx -> m1[x, idx] * m2[idx, y] }
            result[x, y] = dotProduct
        }
    }
    return result
}

private fun printMatrix(matrix: Matrix) {
    val (n, m) = matrix.sizesOfDimensions
    println("The result is:")
    repeat(n) { x ->
        repeat(m) { y ->
            print("${decimalFormat.format(matrix[x, y])} ")
        }
        println()
    }
}

private fun printTransposeMatrixMenu() {
    println("1. Main diagonal")
    println("2. Side diagonal")
    println("3. Vertical line")
    println("4. Horizontal line")
}

fun findMatrixInverse(matrix: Matrix): Matrix? {
    val determinant = matrix.determinant()
    if (determinant == 0.0) {
        return null
    }
    val cofactorMatrix = matrix.toCofactorMatrix()
    MainDiagonalTransposeStrategy.transpose(cofactorMatrix)
    return multiplyMatrixByConstant(cofactorMatrix, 1.0 / determinant)
}

Compiled from "Main.kt"
public final class processor.MainKt {
  private static final kotlin.text.Regex regexp;

  private static java.text.DecimalFormat decimalFormat;

  public static final java.text.DecimalFormat getDecimalFormat();
    Code:
       0: getstatic     #11                 // Field decimalFormat:Ljava/text/DecimalFormat;
       3: areturn

  public static final void setDecimalFormat(java.text.DecimalFormat);
    Code:
       0: aload_0
       1: ldc           #15                 // String <set-?>
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: putstatic     #11                 // Field decimalFormat:Ljava/text/DecimalFormat;
      10: return

  public static final void main();
    Code:
       0: nop
       1: invokestatic  #26                 // Method printMenu:()V
       4: ldc           #28                 // String Your choice:
       6: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
       9: swap
      10: invokevirtual #40                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      13: invokestatic  #46                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
      16: invokestatic  #52                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      19: tableswitch   { // 0 to 6
                     0: 60
                     1: 63
                     2: 106
                     3: 140
                     4: 183
                     5: 229
                     6: 279
               default: 333
          }
      60: goto          345
      63: ldc           #54                 // String first
      65: invokestatic  #58                 // Method readMatrix:(Ljava/lang/String;)Lprocessor/Matrix;
      68: astore_0
      69: ldc           #60                 // String second
      71: invokestatic  #58                 // Method readMatrix:(Ljava/lang/String;)Lprocessor/Matrix;
      74: astore_1
      75: aload_0
      76: aload_1
      77: invokestatic  #64                 // Method isAdditionAllowed:(Lprocessor/Matrix;Lprocessor/Matrix;)Z
      80: ifeq          94
      83: aload_0
      84: aload_1
      85: invokestatic  #68                 // Method addMatrices:(Lprocessor/Matrix;Lprocessor/Matrix;)Lprocessor/Matrix;
      88: invokestatic  #72                 // Method printMatrix:(Lprocessor/Matrix;)V
      91: goto          0
      94: ldc           #74                 // String The operation cannot be performed.
      96: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      99: swap
     100: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: goto          0
     106: aconst_null
     107: iconst_1
     108: aconst_null
     109: invokestatic  #81                 // Method readMatrix$default:(Ljava/lang/String;ILjava/lang/Object;)Lprocessor/Matrix;
     112: astore_0
     113: ldc           #83                 // String Enter constant:
     115: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     118: swap
     119: invokevirtual #40                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     122: invokestatic  #46                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
     125: invokestatic  #89                 // Method java/lang/Double.parseDouble:(Ljava/lang/String;)D
     128: dstore_1
     129: aload_0
     130: dload_1
     131: invokestatic  #93                 // Method multiplyMatrixByConstant:(Lprocessor/Matrix;D)Lprocessor/Matrix;
     134: invokestatic  #72                 // Method printMatrix:(Lprocessor/Matrix;)V
     137: goto          0
     140: ldc           #54                 // String first
     142: invokestatic  #58                 // Method readMatrix:(Ljava/lang/String;)Lprocessor/Matrix;
     145: astore_0
     146: ldc           #60                 // String second
     148: invokestatic  #58                 // Method readMatrix:(Ljava/lang/String;)Lprocessor/Matrix;
     151: astore_1
     152: aload_0
     153: aload_1
     154: invokestatic  #96                 // Method isMultiplicationAllowed:(Lprocessor/Matrix;Lprocessor/Matrix;)Z
     157: ifeq          171
     160: aload_0
     161: aload_1
     162: invokestatic  #99                 // Method multiplyMatrices:(Lprocessor/Matrix;Lprocessor/Matrix;)Lprocessor/Matrix;
     165: invokestatic  #72                 // Method printMatrix:(Lprocessor/Matrix;)V
     168: goto          0
     171: ldc           #74                 // String The operation cannot be performed.
     173: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     176: swap
     177: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     180: goto          0
     183: invokestatic  #102                // Method printTransposeMatrixMenu:()V
     186: ldc           #28                 // String Your choice:
     188: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     191: swap
     192: invokevirtual #40                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     195: getstatic     #108                // Field processor/TransposeStrategy.Companion:Lprocessor/TransposeStrategy$Companion;
     198: invokestatic  #46                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
     201: invokestatic  #52                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     204: invokevirtual #114                // Method processor/TransposeStrategy$Companion.byNumber:(I)Lprocessor/TransposeStrategy;
     207: astore_0
     208: aconst_null
     209: iconst_1
     210: aconst_null
     211: invokestatic  #81                 // Method readMatrix$default:(Ljava/lang/String;ILjava/lang/Object;)Lprocessor/Matrix;
     214: astore_1
     215: aload_0
     216: aload_1
     217: invokeinterface #117,  2          // InterfaceMethod processor/TransposeStrategy.transpose:(Lprocessor/Matrix;)V
     222: aload_1
     223: invokestatic  #72                 // Method printMatrix:(Lprocessor/Matrix;)V
     226: goto          0
     229: aconst_null
     230: iconst_1
     231: aconst_null
     232: invokestatic  #81                 // Method readMatrix$default:(Ljava/lang/String;ILjava/lang/Object;)Lprocessor/Matrix;
     235: astore_0
     236: aload_0
     237: invokevirtual #123                // Method processor/Matrix.isSquare:()Z
     240: ifeq          267
     243: ldc           #125                // String The result is:
     245: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     248: swap
     249: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     252: aload_0
     253: invokevirtual #129                // Method processor/Matrix.determinant:()D
     256: dstore_1
     257: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     260: dload_1
     261: invokevirtual #132                // Method java/io/PrintStream.println:(D)V
     264: goto          0
     267: ldc           #74                 // String The operation cannot be performed.
     269: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     272: swap
     273: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     276: goto          0
     279: aconst_null
     280: iconst_1
     281: aconst_null
     282: invokestatic  #81                 // Method readMatrix$default:(Ljava/lang/String;ILjava/lang/Object;)Lprocessor/Matrix;
     285: astore_0
     286: aload_0
     287: invokevirtual #123                // Method processor/Matrix.isSquare:()Z
     290: ifeq          321
     293: aload_0
     294: invokestatic  #136                // Method findMatrixInverse:(Lprocessor/Matrix;)Lprocessor/Matrix;
     297: astore_1
     298: aload_1
     299: ifnonnull     314
     302: ldc           #138                // String This matrix doesn\'t have an inverse.
     304: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     307: swap
     308: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     311: goto          0
     314: aload_1
     315: invokestatic  #72                 // Method printMatrix:(Lprocessor/Matrix;)V
     318: goto          0
     321: ldc           #74                 // String The operation cannot be performed.
     323: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     326: swap
     327: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     330: goto          0
     333: ldc           #140                // String Wrong choice!
     335: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     338: swap
     339: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     342: goto          0
     345: return

  private static final void printMenu();
    Code:
       0: ldc           #151                // String 1. Add matrices
       2: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: ldc           #153                // String 2. Multiply matrix by a constant
      11: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: swap
      15: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      18: ldc           #155                // String 3. Multiply matrices
      20: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      23: swap
      24: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      27: ldc           #157                // String 4. Transpose matrix
      29: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      32: swap
      33: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      36: ldc           #159                // String 5. Calculate a determinant
      38: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      41: swap
      42: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      45: ldc           #161                // String 6. Inverse matrix
      47: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      54: ldc           #163                // String 0. Exit
      56: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      59: swap
      60: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      63: return

  private static final processor.Matrix readMatrix(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #165                // class java/lang/CharSequence
       4: invokestatic  #171                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
       7: ifne          14
      10: iconst_1
      11: goto          15
      14: iconst_0
      15: ifeq          23
      18: ldc           #173                // String
      20: goto          51
      23: new           #175                // class java/lang/StringBuilder
      26: dup
      27: invokespecial #178                // Method java/lang/StringBuilder."<init>":()V
      30: ldc           #180                // String
      32: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      35: aload_0
      36: checkcast     #165                // class java/lang/CharSequence
      39: invokestatic  #188                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      42: invokevirtual #191                // Method java/lang/Object.toString:()Ljava/lang/String;
      45: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      48: invokevirtual #192                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: astore_1
      52: new           #175                // class java/lang/StringBuilder
      55: dup
      56: invokespecial #178                // Method java/lang/StringBuilder."<init>":()V
      59: ldc           #194                // String Enter size of
      61: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      64: aload_1
      65: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      68: ldc           #196                // String  matrix:
      70: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      73: invokevirtual #192                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      76: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      79: swap
      80: invokevirtual #40                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      83: invokestatic  #46                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
      86: checkcast     #165                // class java/lang/CharSequence
      89: astore_3
      90: getstatic     #200                // Field regexp:Lkotlin/text/Regex;
      93: astore        4
      95: iconst_0
      96: istore        5
      98: aload         4
     100: aload_3
     101: iload         5
     103: invokevirtual #206                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
     106: checkcast     #208                // class java/lang/Iterable
     109: astore_3
     110: nop
     111: iconst_0
     112: istore        4
     114: aload_3
     115: astore        5
     117: new           #210                // class java/util/ArrayList
     120: dup
     121: aload_3
     122: bipush        10
     124: invokestatic  #216                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     127: invokespecial #219                // Method java/util/ArrayList."<init>":(I)V
     130: checkcast     #221                // class java/util/Collection
     133: astore        6
     135: iconst_0
     136: istore        7
     138: aload         5
     140: invokeinterface #225,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     145: astore        8
     147: aload         8
     149: invokeinterface #230,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     154: ifeq          201
     157: aload         8
     159: invokeinterface #234,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     164: astore        9
     166: aload         6
     168: aload         9
     170: checkcast     #236                // class java/lang/String
     173: astore        10
     175: astore        23
     177: iconst_0
     178: istore        11
     180: aload         10
     182: invokestatic  #52                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     185: nop
     186: invokestatic  #240                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     189: aload         23
     191: swap
     192: invokeinterface #244,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     197: pop
     198: goto          147
     201: aload         6
     203: checkcast     #246                // class java/util/List
     206: nop
     207: astore_2
     208: aload_2
     209: iconst_0
     210: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     215: checkcast     #252                // class java/lang/Number
     218: invokevirtual #256                // Method java/lang/Number.intValue:()I
     221: istore_3
     222: aload_2
     223: iconst_1
     224: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     229: checkcast     #252                // class java/lang/Number
     232: invokevirtual #256                // Method java/lang/Number.intValue:()I
     235: istore        4
     237: getstatic     #259                // Field processor/Matrix.Companion:Lprocessor/Matrix$Companion;
     240: iload_3
     241: iload         4
     243: invokevirtual #265                // Method processor/Matrix$Companion.empty:(II)Lprocessor/Matrix;
     246: astore        5
     248: new           #175                // class java/lang/StringBuilder
     251: dup
     252: invokespecial #178                // Method java/lang/StringBuilder."<init>":()V
     255: ldc_w         #267                // String Enter
     258: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     261: aload_1
     262: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     265: ldc_w         #269                // String  matrix:
     268: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     271: invokevirtual #192                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     274: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     277: swap
     278: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     281: iconst_0
     282: istore        6
     284: iload         6
     286: iload_3
     287: if_icmpge     555
     290: iload         6
     292: istore        7
     294: iconst_0
     295: istore        8
     297: invokestatic  #46                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
     300: checkcast     #165                // class java/lang/CharSequence
     303: astore        9
     305: getstatic     #200                // Field regexp:Lkotlin/text/Regex;
     308: astore        10
     310: iconst_0
     311: istore        11
     313: aload         10
     315: aload         9
     317: iload         11
     319: invokevirtual #206                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
     322: checkcast     #208                // class java/lang/Iterable
     325: astore        9
     327: nop
     328: iconst_0
     329: istore        10
     331: aload         9
     333: astore        11
     335: new           #210                // class java/util/ArrayList
     338: dup
     339: aload         9
     341: bipush        10
     343: invokestatic  #216                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     346: invokespecial #219                // Method java/util/ArrayList."<init>":(I)V
     349: checkcast     #221                // class java/util/Collection
     352: astore        12
     354: iconst_0
     355: istore        13
     357: aload         11
     359: invokeinterface #225,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     364: astore        14
     366: aload         14
     368: invokeinterface #230,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     373: ifeq          420
     376: aload         14
     378: invokeinterface #234,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     383: astore        15
     385: aload         12
     387: aload         15
     389: checkcast     #236                // class java/lang/String
     392: astore        16
     394: astore        17
     396: iconst_0
     397: istore        18
     399: aload         16
     401: invokestatic  #89                 // Method java/lang/Double.parseDouble:(Ljava/lang/String;)D
     404: nop
     405: invokestatic  #272                // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     408: aload         17
     410: swap
     411: invokeinterface #244,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     416: pop
     417: goto          366
     420: aload         12
     422: checkcast     #246                // class java/util/List
     425: nop
     426: astore        19
     428: aload         19
     430: invokeinterface #275,  1          // InterfaceMethod java/util/List.size:()I
     435: iload         4
     437: if_icmpne     444
     440: iconst_1
     441: goto          445
     444: iconst_0
     445: ifne          459
     448: new           #277                // class java/lang/IllegalStateException
     451: dup
     452: ldc_w         #279                // String Check failed.
     455: invokespecial #282                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     458: athrow
     459: aload         19
     461: checkcast     #208                // class java/lang/Iterable
     464: astore        9
     466: iconst_0
     467: istore        10
     469: iconst_0
     470: istore        11
     472: aload         9
     474: invokeinterface #225,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     479: astore        12
     481: aload         12
     483: invokeinterface #230,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     488: ifeq          547
     491: aload         12
     493: invokeinterface #234,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     498: astore        13
     500: iload         11
     502: iinc          11, 1
     505: istore        14
     507: iload         14
     509: ifge          515
     512: invokestatic  #285                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     515: iload         14
     517: aload         13
     519: checkcast     #252                // class java/lang/Number
     522: invokevirtual #288                // Method java/lang/Number.doubleValue:()D
     525: dstore        20
     527: istore        18
     529: iconst_0
     530: istore        22
     532: aload         5
     534: iload         7
     536: iload         18
     538: dload         20
     540: invokevirtual #292                // Method processor/Matrix.set:(IID)V
     543: nop
     544: goto          481
     547: nop
     548: nop
     549: iinc          6, 1
     552: goto          284
     555: aload         5
     557: areturn

  static processor.Matrix readMatrix$default(java.lang.String, int, java.lang.Object);
    Code:
       0: iload_1
       1: iconst_1
       2: iand
       3: ifeq          9
       6: ldc           #180                // String
       8: astore_0
       9: aload_0
      10: invokestatic  #58                 // Method readMatrix:(Ljava/lang/String;)Lprocessor/Matrix;
      13: areturn

  private static final boolean isAdditionAllowed(processor.Matrix, processor.Matrix);
    Code:
       0: aload_0
       1: invokevirtual #325                // Method processor/Matrix.getSizesOfDimensions:()[I
       4: aload_1
       5: invokevirtual #325                // Method processor/Matrix.getSizesOfDimensions:()[I
       8: invokestatic  #331                // Method java/util/Arrays.equals:([I[I)Z
      11: ireturn

  private static final processor.Matrix addMatrices(processor.Matrix, processor.Matrix);
    Code:
       0: aload_0
       1: invokevirtual #325                // Method processor/Matrix.getSizesOfDimensions:()[I
       4: astore_2
       5: aload_2
       6: iconst_0
       7: iaload
       8: istore_3
       9: aload_2
      10: iconst_1
      11: iaload
      12: istore        4
      14: getstatic     #259                // Field processor/Matrix.Companion:Lprocessor/Matrix$Companion;
      17: iload_3
      18: iload         4
      20: invokevirtual #265                // Method processor/Matrix$Companion.empty:(II)Lprocessor/Matrix;
      23: astore        5
      25: iconst_0
      26: istore        6
      28: iload         6
      30: iload_3
      31: if_icmpge     98
      34: iload         6
      36: istore        7
      38: iconst_0
      39: istore        8
      41: iconst_0
      42: istore        9
      44: iload         9
      46: iload         4
      48: if_icmpge     91
      51: iload         9
      53: istore        10
      55: iconst_0
      56: istore        11
      58: aload         5
      60: iload         7
      62: iload         10
      64: aload_0
      65: iload         7
      67: iload         10
      69: invokevirtual #334                // Method processor/Matrix.get:(II)D
      72: aload_1
      73: iload         7
      75: iload         10
      77: invokevirtual #334                // Method processor/Matrix.get:(II)D
      80: dadd
      81: invokevirtual #292                // Method processor/Matrix.set:(IID)V
      84: nop
      85: iinc          9, 1
      88: goto          44
      91: nop
      92: iinc          6, 1
      95: goto          28
      98: aload         5
     100: areturn

  private static final processor.Matrix multiplyMatrixByConstant(processor.Matrix, double);
    Code:
       0: aload_0
       1: invokevirtual #325                // Method processor/Matrix.getSizesOfDimensions:()[I
       4: astore_3
       5: aload_3
       6: iconst_0
       7: iaload
       8: istore        4
      10: aload_3
      11: iconst_1
      12: iaload
      13: istore        5
      15: getstatic     #259                // Field processor/Matrix.Companion:Lprocessor/Matrix$Companion;
      18: iload         4
      20: iload         5
      22: invokevirtual #265                // Method processor/Matrix$Companion.empty:(II)Lprocessor/Matrix;
      25: astore        6
      27: iconst_0
      28: istore        7
      30: iload         7
      32: iload         4
      34: if_icmpge     94
      37: iload         7
      39: istore        8
      41: iconst_0
      42: istore        9
      44: iconst_0
      45: istore        10
      47: iload         10
      49: iload         5
      51: if_icmpge     87
      54: iload         10
      56: istore        11
      58: iconst_0
      59: istore        12
      61: aload         6
      63: iload         8
      65: iload         11
      67: aload_0
      68: iload         8
      70: iload         11
      72: invokevirtual #334                // Method processor/Matrix.get:(II)D
      75: dload_1
      76: dmul
      77: invokevirtual #292                // Method processor/Matrix.set:(IID)V
      80: nop
      81: iinc          10, 1
      84: goto          47
      87: nop
      88: iinc          7, 1
      91: goto          30
      94: aload         6
      96: areturn

  private static final boolean isMultiplicationAllowed(processor.Matrix, processor.Matrix);
    Code:
       0: aload_0
       1: invokevirtual #325                // Method processor/Matrix.getSizesOfDimensions:()[I
       4: iconst_1
       5: iaload
       6: istore_2
       7: aload_1
       8: invokevirtual #325                // Method processor/Matrix.getSizesOfDimensions:()[I
      11: iconst_0
      12: iaload
      13: istore_3
      14: iload_2
      15: iload_3
      16: if_icmpne     23
      19: iconst_1
      20: goto          24
      23: iconst_0
      24: ireturn

  private static final processor.Matrix multiplyMatrices(processor.Matrix, processor.Matrix);
    Code:
       0: aload_0
       1: invokevirtual #325                // Method processor/Matrix.getSizesOfDimensions:()[I
       4: astore_2
       5: aload_2
       6: iconst_0
       7: iaload
       8: istore_3
       9: aload_2
      10: iconst_1
      11: iaload
      12: istore        4
      14: aload_1
      15: invokevirtual #325                // Method processor/Matrix.getSizesOfDimensions:()[I
      18: iconst_1
      19: iaload
      20: istore        5
      22: getstatic     #259                // Field processor/Matrix.Companion:Lprocessor/Matrix$Companion;
      25: iload_3
      26: iload         5
      28: invokevirtual #265                // Method processor/Matrix$Companion.empty:(II)Lprocessor/Matrix;
      31: astore        6
      33: iconst_0
      34: istore        7
      36: iload         7
      38: iload_3
      39: if_icmpge     178
      42: iload         7
      44: istore        8
      46: iconst_0
      47: istore        9
      49: iconst_0
      50: istore        10
      52: iload         10
      54: iload         5
      56: if_icmpge     171
      59: iload         10
      61: istore        11
      63: iconst_0
      64: istore        12
      66: iconst_0
      67: iload         4
      69: invokestatic  #350                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      72: checkcast     #208                // class java/lang/Iterable
      75: astore        13
      77: dconst_0
      78: dstore        14
      80: aload         13
      82: invokeinterface #225,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      87: astore        16
      89: aload         16
      91: invokeinterface #230,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      96: ifeq          149
      99: aload         16
     101: checkcast     #352                // class kotlin/collections/IntIterator
     104: invokevirtual #355                // Method kotlin/collections/IntIterator.nextInt:()I
     107: istore        17
     109: dload         14
     111: iload         17
     113: istore        18
     115: dstore        19
     117: iconst_0
     118: istore        21
     120: aload_0
     121: iload         8
     123: iload         18
     125: invokevirtual #334                // Method processor/Matrix.get:(II)D
     128: aload_1
     129: iload         18
     131: iload         11
     133: invokevirtual #334                // Method processor/Matrix.get:(II)D
     136: dmul
     137: dstore        22
     139: dload         19
     141: dload         22
     143: dadd
     144: dstore        14
     146: goto          89
     149: dload         14
     151: dstore        24
     153: aload         6
     155: iload         8
     157: iload         11
     159: dload         24
     161: invokevirtual #292                // Method processor/Matrix.set:(IID)V
     164: nop
     165: iinc          10, 1
     168: goto          52
     171: nop
     172: iinc          7, 1
     175: goto          36
     178: aload         6
     180: areturn

  private static final void printMatrix(processor.Matrix);
    Code:
       0: aload_0
       1: invokevirtual #325                // Method processor/Matrix.getSizesOfDimensions:()[I
       4: astore_1
       5: aload_1
       6: iconst_0
       7: iaload
       8: istore_2
       9: aload_1
      10: iconst_1
      11: iaload
      12: istore_3
      13: ldc           #125                // String The result is:
      15: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      18: swap
      19: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      22: iconst_0
      23: istore        4
      25: iload         4
      27: iload_2
      28: if_icmpge     113
      31: iload         4
      33: istore        5
      35: iconst_0
      36: istore        6
      38: iconst_0
      39: istore        7
      41: iload         7
      43: iload_3
      44: if_icmpge     100
      47: iload         7
      49: istore        8
      51: iconst_0
      52: istore        9
      54: new           #175                // class java/lang/StringBuilder
      57: dup
      58: invokespecial #178                // Method java/lang/StringBuilder."<init>":()V
      61: getstatic     #11                 // Field decimalFormat:Ljava/text/DecimalFormat;
      64: aload_0
      65: iload         5
      67: iload         8
      69: invokevirtual #334                // Method processor/Matrix.get:(II)D
      72: invokevirtual #367                // Method java/text/DecimalFormat.format:(D)Ljava/lang/String;
      75: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      78: bipush        32
      80: invokevirtual #370                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      83: invokevirtual #192                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      86: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      89: swap
      90: invokevirtual #40                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      93: nop
      94: iinc          7, 1
      97: goto          41
     100: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: invokevirtual #372                // Method java/io/PrintStream.println:()V
     106: nop
     107: iinc          4, 1
     110: goto          25
     113: return

  private static final void printTransposeMatrixMenu();
    Code:
       0: ldc_w         #376                // String 1. Main diagonal
       3: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
       6: swap
       7: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      10: ldc_w         #378                // String 2. Side diagonal
      13: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      16: swap
      17: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      20: ldc_w         #380                // String 3. Vertical line
      23: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: swap
      27: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: ldc_w         #382                // String 4. Horizontal line
      33: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #77                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: return

  public static final processor.Matrix findMatrixInverse(processor.Matrix);
    Code:
       0: aload_0
       1: ldc_w         #384                // String matrix
       4: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #129                // Method processor/Matrix.determinant:()D
      11: dstore_1
      12: dload_1
      13: dconst_0
      14: dcmpg
      15: ifne          22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ifeq          28
      26: aconst_null
      27: areturn
      28: aload_0
      29: invokevirtual #388                // Method processor/Matrix.toCofactorMatrix:()Lprocessor/Matrix;
      32: astore_3
      33: getstatic     #394                // Field processor/MainDiagonalTransposeStrategy.INSTANCE:Lprocessor/MainDiagonalTransposeStrategy;
      36: aload_3
      37: invokevirtual #395                // Method processor/MainDiagonalTransposeStrategy.transpose:(Lprocessor/Matrix;)V
      40: aload_3
      41: dconst_1
      42: dload_1
      43: ddiv
      44: invokestatic  #93                 // Method multiplyMatrixByConstant:(Lprocessor/Matrix;D)Lprocessor/Matrix;
      47: areturn

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

  static {};
    Code:
       0: new           #202                // class kotlin/text/Regex
       3: dup
       4: ldc_w         #404                // String \\s+
       7: invokespecial #405                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      10: putstatic     #200                // Field regexp:Lkotlin/text/Regex;
      13: new           #363                // class java/text/DecimalFormat
      16: dup
      17: ldc_w         #407                // String #0.##
      20: invokespecial #408                // Method java/text/DecimalFormat."<init>":(Ljava/lang/String;)V
      23: putstatic     #11                 // Field decimalFormat:Ljava/text/DecimalFormat;
      26: return
}


package com.emirhanaydin.analytichierarchyprocess

fun getRandomIndex(n: Int): Float {
    return when (n) {
        1, 2 -> 0f
        3 -> 0.58f
        4 -> 0.90f
        5 -> 1.12f
        6 -> 1.24f
        7 -> 1.32f
        8 -> 1.41f
        9 -> 1.45f
        10 -> 1.49f
        11 -> 1.51f
        12 -> 1.48f
        13 -> 1.56f
        else -> -1f
    }
}

fun multiplyVectors(v1: FloatArray, v2: FloatArray): Float {
    val size = v1.size
    var sum = 0f

    for (i in 0 until size) {
        sum += v1[i] * v2[i]
    }

    return sum
}

private fun getWeights(ratings: Array<FloatArray>): Pair<Array<FloatArray>, FloatArray> {
    val size = ratings.size
    val weights = Array(size) { FloatArray(size) }
    val subtotals = FloatArray(size)

    // Calculate the weights
    for (i in 0 until size) {
        val child = ratings[i]

        for (j in 0 until child.size) {
            val index = j + i + 1 // Plus i to make the calculations triangular, plus 1 to skip diagonal

            weights[i][index] = child[j]
            weights[index][i] = 1 / weights[i][index] // Reciprocal

            // Add the values to subtotals by their column indexes
            subtotals[index] += weights[i][index]
            subtotals[i] += weights[index][i]
        }
        // The diagonal indicates the alternative itself, so its weight is 1
        weights[i][i] = 1f
        subtotals[i] += weights[i][i]
    }

    return Pair(weights, subtotals)
}

private fun getNormalizedWeights(weights: Array<FloatArray>, subtotals: FloatArray): Array<FloatArray> {
    val size = weights.size
    val normalizedWeights = Array(size) { FloatArray(size) }

    // Normalize the weights
    for (i in 0 until size) {
        for (j in 0 until size) {
            normalizedWeights[i][j] = weights[i][j] / subtotals[j]
        }
    }

    return normalizedWeights
}

private fun getPriorities(normalizedWeights: Array<FloatArray>): FloatArray {
    val size = normalizedWeights.size
    val priorities = FloatArray(size)

    // Calculate priorities with the normalized weights
    for (i in 0 until size) {
        var sum = 0f
        for (j in 0 until size) {
            sum += normalizedWeights[i][j]
        }
        priorities[i] = sum / size // Average of the row
    }

    return priorities
}

private fun getConsistencyRatio(priorities: FloatArray, subtotals: FloatArray): Pair<Float, Float> {
    val size = priorities.size

    // Calculate the consistency ratio
    val eMax = multiplyVectors(priorities, subtotals)
    val consistencyIndex = (eMax - size) / (size - 1)

    return Pair(consistencyIndex, getRandomIndex(size))
}

fun performAhp(ratings: Array<FloatArray>): AhpResult {
    val weights: Array<FloatArray>
    val subtotals: FloatArray
    getWeights(ratings).apply {
        weights = first
        subtotals = second
    }
    val normalizedWeights = getNormalizedWeights(weights, subtotals)

    val priorities = getPriorities(normalizedWeights)
    val randomIndex: Float
    val consistencyIndex: Float
    getConsistencyRatio(priorities, subtotals).apply {
        consistencyIndex = first
        randomIndex = second
    }
    return AhpResult(priorities, consistencyIndex, randomIndex, consistencyIndex / randomIndex)
}

class AhpResult(
    val priorities: FloatArray,
    val consistencyIndex: Float,
    val randomIndex: Float,
    val consistencyRatio: Float
)

Compiled from "math.kt"
public final class com.emirhanaydin.analytichierarchyprocess.MathKt {
  public static final float getRandomIndex(int);
    Code:
       0: iload_0
       1: tableswitch   { // 1 to 13
                     1: 68
                     2: 68
                     3: 72
                     4: 77
                     5: 82
                     6: 87
                     7: 92
                     8: 97
                     9: 102
                    10: 107
                    11: 112
                    12: 117
                    13: 122
               default: 127
          }
      68: fconst_0
      69: goto          129
      72: ldc           #7                  // float 0.58f
      74: goto          129
      77: ldc           #8                  // float 0.9f
      79: goto          129
      82: ldc           #9                  // float 1.12f
      84: goto          129
      87: ldc           #10                 // float 1.24f
      89: goto          129
      92: ldc           #11                 // float 1.32f
      94: goto          129
      97: ldc           #12                 // float 1.41f
      99: goto          129
     102: ldc           #13                 // float 1.45f
     104: goto          129
     107: ldc           #14                 // float 1.49f
     109: goto          129
     112: ldc           #15                 // float 1.51f
     114: goto          129
     117: ldc           #16                 // float 1.48f
     119: goto          129
     122: ldc           #17                 // float 1.56f
     124: goto          129
     127: ldc           #18                 // float -1.0f
     129: freturn

  public static final float multiplyVectors(float[], float[]);
    Code:
       0: aload_0
       1: ldc           #25                 // String v1
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #33                 // String v2
       9: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: arraylength
      14: istore_2
      15: fconst_0
      16: fstore_3
      17: iconst_0
      18: istore        4
      20: iload         4
      22: iload_2
      23: if_icmpge     44
      26: fload_3
      27: aload_0
      28: iload         4
      30: faload
      31: aload_1
      32: iload         4
      34: faload
      35: fmul
      36: fadd
      37: fstore_3
      38: iinc          4, 1
      41: goto          20
      44: fload_3
      45: freturn

  private static final kotlin.Pair<float[][], float[]> getWeights(float[][]);
    Code:
       0: aload_0
       1: checkcast     #43                 // class "[Ljava/lang/Object;"
       4: arraylength
       5: istore_1
       6: iconst_0
       7: istore_3
       8: iload_1
       9: anewarray     #44                 // class "[F"
      12: astore        4
      14: iload_3
      15: iload_1
      16: if_icmpge     36
      19: iload_3
      20: istore        5
      22: aload         4
      24: iload         5
      26: iload_1
      27: newarray       float
      29: aastore
      30: iinc          3, 1
      33: goto          14
      36: aload         4
      38: astore_2
      39: iload_1
      40: newarray       float
      42: astore_3
      43: iconst_0
      44: istore        4
      46: iload         4
      48: iload_1
      49: if_icmpge     187
      52: aload_0
      53: iload         4
      55: aaload
      56: astore        5
      58: iconst_0
      59: istore        6
      61: aload         5
      63: arraylength
      64: istore        7
      66: iload         6
      68: iload         7
      70: if_icmpge     153
      73: iload         6
      75: iload         4
      77: iadd
      78: iconst_1
      79: iadd
      80: istore        8
      82: aload_2
      83: iload         4
      85: aaload
      86: iload         8
      88: aload         5
      90: iload         6
      92: faload
      93: fastore
      94: aload_2
      95: iload         8
      97: aaload
      98: iload         4
     100: iconst_1
     101: i2f
     102: aload_2
     103: iload         4
     105: aaload
     106: iload         8
     108: faload
     109: fdiv
     110: fastore
     111: aload_3
     112: iload         8
     114: aload_3
     115: iload         8
     117: faload
     118: aload_2
     119: iload         4
     121: aaload
     122: iload         8
     124: faload
     125: fadd
     126: fastore
     127: iload         4
     129: istore        9
     131: aload_3
     132: iload         9
     134: aload_3
     135: iload         9
     137: faload
     138: aload_2
     139: iload         8
     141: aaload
     142: iload         4
     144: faload
     145: fadd
     146: fastore
     147: iinc          6, 1
     150: goto          66
     153: aload_2
     154: iload         4
     156: aaload
     157: iload         4
     159: fconst_1
     160: fastore
     161: iload         4
     163: istore        6
     165: aload_3
     166: iload         6
     168: aload_3
     169: iload         6
     171: faload
     172: aload_2
     173: iload         4
     175: aaload
     176: iload         4
     178: faload
     179: fadd
     180: fastore
     181: iinc          4, 1
     184: goto          46
     187: new           #46                 // class kotlin/Pair
     190: dup
     191: aload_2
     192: aload_3
     193: invokespecial #50                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     196: areturn

  private static final float[][] getNormalizedWeights(float[][], float[]);
    Code:
       0: aload_0
       1: checkcast     #43                 // class "[Ljava/lang/Object;"
       4: arraylength
       5: istore_2
       6: iconst_0
       7: istore        4
       9: iload_2
      10: anewarray     #44                 // class "[F"
      13: astore        5
      15: iload         4
      17: iload_2
      18: if_icmpge     39
      21: iload         4
      23: istore        6
      25: aload         5
      27: iload         6
      29: iload_2
      30: newarray       float
      32: aastore
      33: iinc          4, 1
      36: goto          15
      39: aload         5
      41: astore_3
      42: iconst_0
      43: istore        4
      45: iload         4
      47: iload_2
      48: if_icmpge     91
      51: iconst_0
      52: istore        5
      54: iload         5
      56: iload_2
      57: if_icmpge     85
      60: aload_3
      61: iload         4
      63: aaload
      64: iload         5
      66: aload_0
      67: iload         4
      69: aaload
      70: iload         5
      72: faload
      73: aload_1
      74: iload         5
      76: faload
      77: fdiv
      78: fastore
      79: iinc          5, 1
      82: goto          54
      85: iinc          4, 1
      88: goto          45
      91: aload_3
      92: areturn

  private static final float[] getPriorities(float[][]);
    Code:
       0: aload_0
       1: checkcast     #43                 // class "[Ljava/lang/Object;"
       4: arraylength
       5: istore_1
       6: iload_1
       7: newarray       float
       9: astore_2
      10: iconst_0
      11: istore_3
      12: iload_3
      13: iload_1
      14: if_icmpge     60
      17: fconst_0
      18: fstore        4
      20: iconst_0
      21: istore        5
      23: iload         5
      25: iload_1
      26: if_icmpge     46
      29: fload         4
      31: aload_0
      32: iload_3
      33: aaload
      34: iload         5
      36: faload
      37: fadd
      38: fstore        4
      40: iinc          5, 1
      43: goto          23
      46: aload_2
      47: iload_3
      48: fload         4
      50: iload_1
      51: i2f
      52: fdiv
      53: fastore
      54: iinc          3, 1
      57: goto          12
      60: aload_2
      61: areturn

  private static final kotlin.Pair<java.lang.Float, java.lang.Float> getConsistencyRatio(float[], float[]);
    Code:
       0: aload_0
       1: arraylength
       2: istore_2
       3: aload_0
       4: aload_1
       5: invokestatic  #69                 // Method multiplyVectors:([F[F)F
       8: fstore_3
       9: fload_3
      10: iload_2
      11: i2f
      12: fsub
      13: iload_2
      14: iconst_1
      15: isub
      16: i2f
      17: fdiv
      18: fstore        4
      20: new           #46                 // class kotlin/Pair
      23: dup
      24: fload         4
      26: invokestatic  #75                 // Method java/lang/Float.valueOf:(F)Ljava/lang/Float;
      29: iload_2
      30: invokestatic  #77                 // Method getRandomIndex:(I)F
      33: invokestatic  #75                 // Method java/lang/Float.valueOf:(F)Ljava/lang/Float;
      36: invokespecial #50                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      39: areturn

  public static final com.emirhanaydin.analytichierarchyprocess.AhpResult performAhp(float[][]);
    Code:
       0: aload_0
       1: ldc           #82                 // String ratings
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aconst_null
       7: astore_1
       8: aconst_null
       9: astore_2
      10: aload_0
      11: invokestatic  #84                 // Method getWeights:([[F)Lkotlin/Pair;
      14: astore_3
      15: aload_3
      16: astore        4
      18: iconst_0
      19: istore        5
      21: aload         4
      23: invokevirtual #88                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      26: astore_1
      27: aload         4
      29: invokevirtual #91                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      32: astore_2
      33: nop
      34: nop
      35: aload_1
      36: checkcast     #58                 // class "[[F"
      39: aload_2
      40: checkcast     #44                 // class "[F"
      43: invokestatic  #93                 // Method getNormalizedWeights:([[F[F)[[F
      46: astore_3
      47: aload_3
      48: invokestatic  #95                 // Method getPriorities:([[F)[F
      51: astore        4
      53: fconst_0
      54: fstore        5
      56: fconst_0
      57: fstore        6
      59: aload         4
      61: aload_2
      62: checkcast     #44                 // class "[F"
      65: invokestatic  #97                 // Method getConsistencyRatio:([F[F)Lkotlin/Pair;
      68: astore        7
      70: aload         7
      72: astore        8
      74: iconst_0
      75: istore        9
      77: aload         8
      79: invokevirtual #88                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      82: checkcast     #99                 // class java/lang/Number
      85: invokevirtual #103                // Method java/lang/Number.floatValue:()F
      88: fstore        6
      90: aload         8
      92: invokevirtual #91                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      95: checkcast     #99                 // class java/lang/Number
      98: invokevirtual #103                // Method java/lang/Number.floatValue:()F
     101: fstore        5
     103: nop
     104: nop
     105: new           #105                // class com/emirhanaydin/analytichierarchyprocess/AhpResult
     108: dup
     109: aload         4
     111: fload         6
     113: fload         5
     115: fload         6
     117: fload         5
     119: fdiv
     120: invokespecial #108                // Method com/emirhanaydin/analytichierarchyprocess/AhpResult."<init>":([FFFF)V
     123: areturn
}


package solved.p289

/** The idea is that we will store in original array:
 *  -1  for dead-alive transition
 *   0  for dead-dead transition
 *   1  for alive-alive transition
 *   2  for alive-dead transition
 */
class InPlaceSolution {
    class Solution {
        fun gameOfLife(board: Array<IntArray>) {
            for (i in 0..board.lastIndex) {
                for (j in 0..board[0].lastIndex) {
                    val currentValue = board[i][j]
                    val adjacentValue = adjacentSum(board, i, j)
                    if (currentValue == 1) {
                        if (adjacentValue < 2 || adjacentValue > 3) {
                            board[i][j] = 2
                        } else {
                            board[i][j] = 1
                        }
                    } else {
                        if (adjacentValue == 3) {
                            board[i][j] = -1
                        }
                    }
                }
            }

            for (i in 0..board.lastIndex) {
                for (j in 0..board[0].lastIndex) {
                    val currentValue = board[i][j]
                    if (currentValue == -1) {
                        board[i][j] = 1
                    } else if (currentValue == 2) {
                        board[i][j] = 0
                    }
                }
            }
        }

        private fun adjacentSum(arr: Array<IntArray>, i: Int, j: Int): Int {
            return adjValue(arr, i - 1, j - 1) +
                    adjValue(arr, i - 1, j) +
                    adjValue(arr, i - 1, j + 1) +
                    adjValue(arr, i, j - 1) +
                    adjValue(arr, i, j + 1) +
                    adjValue(arr, i + 1, j - 1) +
                    adjValue(arr, i + 1, j) +
                    adjValue(arr, i + 1, j + 1)
        }

        private fun adjValue(arr: Array<IntArray>, i: Int, j: Int): Int {
            if (i >= 0 && i <= arr.lastIndex && j >= 0 && j <= arr[0].lastIndex) {
                val value = arr[i][j]
                if (value == 1 || value == 2) {
                    return 1
                }
            }
            return 0
        }
    }
}

Compiled from "InPlaceSolution.kt"
public final class solved.p289.InPlaceSolution {
  public solved.p289.InPlaceSolution();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return
}

Compiled from "InPlaceSolution.kt"
public final class solved.p289.InPlaceSolution$Solution {
  public solved.p289.InPlaceSolution$Solution();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void gameOfLife(int[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String board
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_1
       9: checkcast     #23                 // class "[Ljava/lang/Object;"
      12: invokestatic  #29                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
      15: istore_3
      16: iload_2
      17: iload_3
      18: if_icmpgt     132
      21: iconst_0
      22: istore        4
      24: aload_1
      25: iconst_0
      26: aaload
      27: invokestatic  #32                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      30: istore        5
      32: iload         4
      34: iload         5
      36: if_icmpgt     121
      39: aload_1
      40: iload_2
      41: aaload
      42: iload         4
      44: iaload
      45: istore        6
      47: aload_0
      48: aload_1
      49: iload_2
      50: iload         4
      52: invokespecial #36                 // Method adjacentSum:([[III)I
      55: istore        7
      57: iload         6
      59: iconst_1
      60: if_icmpne     95
      63: iload         7
      65: iconst_2
      66: if_icmplt     75
      69: iload         7
      71: iconst_3
      72: if_icmple     85
      75: aload_1
      76: iload_2
      77: aaload
      78: iload         4
      80: iconst_2
      81: iastore
      82: goto          108
      85: aload_1
      86: iload_2
      87: aaload
      88: iload         4
      90: iconst_1
      91: iastore
      92: goto          108
      95: iload         7
      97: iconst_3
      98: if_icmpne     108
     101: aload_1
     102: iload_2
     103: aaload
     104: iload         4
     106: iconst_m1
     107: iastore
     108: iload         4
     110: iload         5
     112: if_icmpeq     121
     115: iinc          4, 1
     118: goto          39
     121: iload_2
     122: iload_3
     123: if_icmpeq     132
     126: iinc          2, 1
     129: goto          21
     132: iconst_0
     133: istore_2
     134: aload_1
     135: checkcast     #23                 // class "[Ljava/lang/Object;"
     138: invokestatic  #29                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     141: istore_3
     142: iload_2
     143: iload_3
     144: if_icmpgt     245
     147: iconst_0
     148: istore        4
     150: aload_1
     151: iconst_0
     152: aaload
     153: invokestatic  #32                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
     156: istore        5
     158: iload         4
     160: iload         5
     162: if_icmpgt     234
     165: aload_1
     166: iload_2
     167: aaload
     168: iload         4
     170: iaload
     171: istore        6
     173: iload         6
     175: tableswitch   { // -1 to 2
                    -1: 204
                     0: 221
                     1: 221
                     2: 214
               default: 221
          }
     204: aload_1
     205: iload_2
     206: aaload
     207: iload         4
     209: iconst_1
     210: iastore
     211: goto          221
     214: aload_1
     215: iload_2
     216: aaload
     217: iload         4
     219: iconst_0
     220: iastore
     221: iload         4
     223: iload         5
     225: if_icmpeq     234
     228: iinc          4, 1
     231: goto          165
     234: iload_2
     235: iload_3
     236: if_icmpeq     245
     239: iinc          2, 1
     242: goto          147
     245: return

  private final int adjacentSum(int[][], int, int);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: iconst_1
       4: isub
       5: iload_3
       6: iconst_1
       7: isub
       8: invokespecial #45                 // Method adjValue:([[III)I
      11: aload_0
      12: aload_1
      13: iload_2
      14: iconst_1
      15: isub
      16: iload_3
      17: invokespecial #45                 // Method adjValue:([[III)I
      20: iadd
      21: aload_0
      22: aload_1
      23: iload_2
      24: iconst_1
      25: isub
      26: iload_3
      27: iconst_1
      28: iadd
      29: invokespecial #45                 // Method adjValue:([[III)I
      32: iadd
      33: aload_0
      34: aload_1
      35: iload_2
      36: iload_3
      37: iconst_1
      38: isub
      39: invokespecial #45                 // Method adjValue:([[III)I
      42: iadd
      43: aload_0
      44: aload_1
      45: iload_2
      46: iload_3
      47: iconst_1
      48: iadd
      49: invokespecial #45                 // Method adjValue:([[III)I
      52: iadd
      53: aload_0
      54: aload_1
      55: iload_2
      56: iconst_1
      57: iadd
      58: iload_3
      59: iconst_1
      60: isub
      61: invokespecial #45                 // Method adjValue:([[III)I
      64: iadd
      65: aload_0
      66: aload_1
      67: iload_2
      68: iconst_1
      69: iadd
      70: iload_3
      71: invokespecial #45                 // Method adjValue:([[III)I
      74: iadd
      75: aload_0
      76: aload_1
      77: iload_2
      78: iconst_1
      79: iadd
      80: iload_3
      81: iconst_1
      82: iadd
      83: invokespecial #45                 // Method adjValue:([[III)I
      86: iadd
      87: ireturn

  private final int adjValue(int[][], int, int);
    Code:
       0: iload_2
       1: iflt          62
       4: iload_2
       5: aload_1
       6: checkcast     #23                 // class "[Ljava/lang/Object;"
       9: invokestatic  #29                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
      12: if_icmpgt     62
      15: iload_3
      16: iflt          62
      19: iload_3
      20: aload_1
      21: iconst_0
      22: aaload
      23: invokestatic  #32                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      26: if_icmpgt     62
      29: aload_1
      30: iload_2
      31: aaload
      32: iload_3
      33: iaload
      34: istore        4
      36: iload         4
      38: tableswitch   { // 1 to 2
                     1: 60
                     2: 60
               default: 62
          }
      60: iconst_1
      61: ireturn
      62: iconst_0
      63: ireturn
}


package solved.p672

class Solution {
    class BruteForceSolution {
        // This was the first idea: generate all possible combinations of button presses
        // and simulate it on given bulbs. Clearly it does't fit any time limits :D
        fun flipLights(n: Int, presses: Int): Int {
            val states = HashSet<MutableList<Boolean>>()

            val combinations = mutableListOf<MutableList<Int>>()
            generatePressesCombinations(combinations, MutableList(presses) { -1 }, presses)

            for (combination in combinations) {
                val lights = MutableList(n) { true }
                for (button in combination) {
                    when (button) {
                        1 -> {
                            for (i in 1..lights.size) {
                                toggle(lights, i)
                            }
                        }
                        2 -> {
                            for (i in 1..lights.size) {
                                if (i % 2 == 0) {
                                    toggle(lights, i)
                                }
                            }
                        }
                        3 -> {
                            for (i in 1..lights.size) {
                                if (i % 2 == 1) {
                                    toggle(lights, i)
                                }
                            }
                        }
                        4 -> {
                            for (i in 1..lights.size) {
                                if ((i - 1) % 3 == 0) {
                                    toggle(lights, i)
                                }
                            }
                        }
                    }
                }
                states.add(lights)
            }

            return states.count()
        }

        private fun toggle(lights: MutableList<Boolean>, i: Int) {
            lights[i - 1] = lights[i - 1].not()
        }

        private fun generatePressesCombinations(
            combinations: MutableList<MutableList<Int>>,
            combination: MutableList<Int>,
            pressesRemaining: Int
        ) {
            if (pressesRemaining > 0) {
                for (button in 1..4) {
                    val tempCombination = mutableListOf(*combination.toTypedArray())
                    tempCombination[tempCombination.size - pressesRemaining] = button
                    generatePressesCombinations(combinations, tempCombination, pressesRemaining - 1)
                }
            } else {
                combinations.add(combination)
            }
        }
    }

    class GodHelpMeSolution { // I'm crying xD
        // This solution came to my mind when I realised there is a finite number of states for given bulbs for every n.
        // For different n it is different. So I built a table/graph representing this state machine.
        // What bulbs are switched on:
        // A - all
        // N - none
        // E - evens
        // O - odds
        // A# - all but thirds
        // N# - none but thirds
        // E# - evens except thirds
        // O# - odds except thirds
        // ___| 1B | 2B | 3B | 4B |
        // A  | N  | O  | E  | A# |
        // N  | A  | E  | O  | N# |
        // O  | E  | N  | A  | O# |
        // E  | O  | A  | N  | E# |
        // A# | N# | O# | E# | A  |
        // N# | A# | E# | O# | N  |
        // O# | E# | N# | A# | O  |
        // E# | O# | A# | N# | E  |
        // Starting from 3 bulbs and 3 presses this system can be in 8 different states described in this table.
        // When bulbs and presses are lower than 3 we can count number of states we can reach with use of table above.
        fun flipLights(bulbs: Int, presses: Int): Int {
            return when (bulbs) {
                0 -> 1
                1 -> when (presses) {
                    0 -> 1
                    else -> 2
                }
                2 -> when (presses) {
                    0 -> 1
                    1 -> 3
                    else -> 4
                }
                else -> when (presses) {
                    0 -> 1
                    1 -> 4
                    2 -> 7
                    else -> 8
                }
            }
        }
    }
}

Compiled from "Solution.kt"
public final class solved.p672.Solution {
  public solved.p672.Solution();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return
}

Compiled from "Solution.kt"
public final class solved.p672.Solution$GodHelpMeSolution {
  public solved.p672.Solution$GodHelpMeSolution();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int flipLights(int, int);
    Code:
       0: iload_1
       1: tableswitch   { // 0 to 2
                     0: 28
                     1: 32
                     2: 44
               default: 80
          }
      28: iconst_1
      29: goto          123
      32: iload_2
      33: ifne          40
      36: iconst_1
      37: goto          123
      40: iconst_2
      41: goto          123
      44: iload_2
      45: tableswitch   { // 0 to 1
                     0: 68
                     1: 72
               default: 76
          }
      68: iconst_1
      69: goto          123
      72: iconst_3
      73: goto          123
      76: iconst_4
      77: goto          123
      80: iload_2
      81: tableswitch   { // 0 to 2
                     0: 108
                     1: 112
                     2: 116
               default: 121
          }
     108: iconst_1
     109: goto          123
     112: iconst_4
     113: goto          123
     116: bipush        7
     118: goto          123
     121: bipush        8
     123: ireturn
}

Compiled from "Solution.kt"
public final class solved.p672.Solution$BruteForceSolution {
  public solved.p672.Solution$BruteForceSolution();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int flipLights(int, int);
    Code:
       0: new           #14                 // class java/util/HashSet
       3: dup
       4: invokespecial #15                 // Method java/util/HashSet."<init>":()V
       7: astore_3
       8: new           #17                 // class java/util/ArrayList
      11: dup
      12: invokespecial #18                 // Method java/util/ArrayList."<init>":()V
      15: checkcast     #20                 // class java/util/List
      18: astore        4
      20: aload_0
      21: aload         4
      23: astore        14
      25: astore        13
      27: new           #17                 // class java/util/ArrayList
      30: dup
      31: iload_2
      32: invokespecial #23                 // Method java/util/ArrayList."<init>":(I)V
      35: astore        5
      37: iconst_0
      38: istore        6
      40: iload         6
      42: iload_2
      43: if_icmpge     78
      46: iload         6
      48: istore        7
      50: aload         5
      52: iload         7
      54: istore        8
      56: astore        15
      58: iconst_0
      59: istore        9
      61: iconst_m1
      62: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: aload         15
      67: swap
      68: invokevirtual #33                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      71: pop
      72: iinc          6, 1
      75: goto          40
      78: aload         5
      80: checkcast     #20                 // class java/util/List
      83: astore        15
      85: aload         13
      87: aload         14
      89: aload         15
      91: iload_2
      92: invokespecial #37                 // Method generatePressesCombinations:(Ljava/util/List;Ljava/util/List;I)V
      95: aload         4
      97: invokeinterface #41,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     102: astore        5
     104: aload         5
     106: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     111: ifeq          453
     114: aload         5
     116: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     121: checkcast     #20                 // class java/util/List
     124: astore        6
     126: new           #17                 // class java/util/ArrayList
     129: dup
     130: iload_1
     131: invokespecial #23                 // Method java/util/ArrayList."<init>":(I)V
     134: astore        8
     136: iconst_0
     137: istore        9
     139: iload         9
     141: iload_1
     142: if_icmpge     177
     145: iload         9
     147: istore        10
     149: aload         8
     151: iload         10
     153: istore        11
     155: astore        13
     157: iconst_0
     158: istore        12
     160: iconst_1
     161: invokestatic  #56                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     164: aload         13
     166: swap
     167: invokevirtual #33                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     170: pop
     171: iinc          9, 1
     174: goto          139
     177: aload         8
     179: checkcast     #20                 // class java/util/List
     182: astore        7
     184: aload         6
     186: invokeinterface #41,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     191: astore        8
     193: aload         8
     195: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     200: ifeq          443
     203: aload         8
     205: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     210: dup
     211: ldc           #58                 // String next(...)
     213: invokestatic  #64                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     216: checkcast     #66                 // class java/lang/Number
     219: invokevirtual #70                 // Method java/lang/Number.intValue:()I
     222: istore        9
     224: iload         9
     226: tableswitch   { // 1 to 4
                     1: 256
                     2: 296
                     3: 343
                     4: 391
               default: 440
          }
     256: iconst_1
     257: istore        11
     259: aload         7
     261: invokeinterface #73,  1           // InterfaceMethod java/util/List.size:()I
     266: istore        12
     268: iload         11
     270: iload         12
     272: if_icmpgt     193
     275: aload_0
     276: aload         7
     278: iload         11
     280: invokespecial #77                 // Method toggle:(Ljava/util/List;I)V
     283: iload         11
     285: iload         12
     287: if_icmpeq     193
     290: iinc          11, 1
     293: goto          275
     296: iconst_1
     297: istore        11
     299: aload         7
     301: invokeinterface #73,  1           // InterfaceMethod java/util/List.size:()I
     306: istore        12
     308: iload         11
     310: iload         12
     312: if_icmpgt     193
     315: iload         11
     317: iconst_2
     318: irem
     319: ifne          330
     322: aload_0
     323: aload         7
     325: iload         11
     327: invokespecial #77                 // Method toggle:(Ljava/util/List;I)V
     330: iload         11
     332: iload         12
     334: if_icmpeq     193
     337: iinc          11, 1
     340: goto          315
     343: iconst_1
     344: istore        11
     346: aload         7
     348: invokeinterface #73,  1           // InterfaceMethod java/util/List.size:()I
     353: istore        12
     355: iload         11
     357: iload         12
     359: if_icmpgt     193
     362: iload         11
     364: iconst_2
     365: irem
     366: iconst_1
     367: if_icmpne     378
     370: aload_0
     371: aload         7
     373: iload         11
     375: invokespecial #77                 // Method toggle:(Ljava/util/List;I)V
     378: iload         11
     380: iload         12
     382: if_icmpeq     193
     385: iinc          11, 1
     388: goto          362
     391: iconst_1
     392: istore        11
     394: aload         7
     396: invokeinterface #73,  1           // InterfaceMethod java/util/List.size:()I
     401: istore        12
     403: iload         11
     405: iload         12
     407: if_icmpgt     193
     410: iload         11
     412: iconst_1
     413: isub
     414: iconst_3
     415: irem
     416: ifne          427
     419: aload_0
     420: aload         7
     422: iload         11
     424: invokespecial #77                 // Method toggle:(Ljava/util/List;I)V
     427: iload         11
     429: iload         12
     431: if_icmpeq     193
     434: iinc          11, 1
     437: goto          410
     440: goto          193
     443: aload_3
     444: aload         7
     446: invokevirtual #78                 // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
     449: pop
     450: goto          104
     453: aload_3
     454: checkcast     #80                 // class java/util/Collection
     457: invokeinterface #81,  1           // InterfaceMethod java/util/Collection.size:()I
     462: ireturn

  private final void toggle(java.util.List<java.lang.Boolean>, int);
    Code:
       0: aload_1
       1: iload_2
       2: iconst_1
       3: isub
       4: aload_1
       5: iload_2
       6: iconst_1
       7: isub
       8: invokeinterface #100,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #53                 // class java/lang/Boolean
      16: invokevirtual #103                // Method java/lang/Boolean.booleanValue:()Z
      19: ifne          26
      22: iconst_1
      23: goto          27
      26: iconst_0
      27: invokestatic  #56                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      30: invokeinterface #107,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      35: pop
      36: return

  private final void generatePressesCombinations(java.util.List<java.util.List<java.lang.Integer>>, java.util.List<java.lang.Integer>, int);
    Code:
       0: iload_3
       1: ifle          93
       4: iconst_1
       5: istore        4
       7: iload         4
       9: iconst_5
      10: if_icmpge     101
      13: aload_2
      14: checkcast     #80                 // class java/util/Collection
      17: astore        7
      19: iconst_0
      20: istore        8
      22: aload         7
      24: astore        9
      26: aload         9
      28: iconst_0
      29: anewarray     #25                 // class java/lang/Integer
      32: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
      37: checkcast     #114                // class "[Ljava/lang/Integer;"
      40: astore        6
      42: aload         6
      44: aload         6
      46: arraylength
      47: invokestatic  #120                // Method java/util/Arrays.copyOf:([Ljava/lang/Object;I)[Ljava/lang/Object;
      50: invokestatic  #126                // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      53: astore        5
      55: aload         5
      57: aload         5
      59: invokeinterface #73,  1           // InterfaceMethod java/util/List.size:()I
      64: iload_3
      65: isub
      66: iload         4
      68: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      71: invokeinterface #107,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      76: pop
      77: aload_0
      78: aload_1
      79: aload         5
      81: iload_3
      82: iconst_1
      83: isub
      84: invokespecial #37                 // Method generatePressesCombinations:(Ljava/util/List;Ljava/util/List;I)V
      87: iinc          4, 1
      90: goto          7
      93: aload_1
      94: aload_2
      95: invokeinterface #127,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     100: pop
     101: return
}


package solved.p1418

class Solution {
    fun displayTable(orders: List<List<String>>): List<List<String>> {
        // A tree set of all tables sorted by natural order
        val tables = sortedSetOf<Int>()
        // A tree set of all dishes sorted by natural order
        val dishes = sortedSetOf<String>()

        // Result map containing unsorted display table (mapOf(table to mapOf(dish to quantity))
        val resultMap = mutableMapOf<Int, MutableMap<String, Int>>()

        for (order in orders) {
            // Skip person name as we are not interested in it in the final solution
            // Parse table number
            val tableNumber = order[1].toInt()
            // Parse dish name
            val dishName = order[2]

            // Add table number to general table set
            tables.add(tableNumber)
            // Add dish to general dish set
            dishes.add(dishName)

            // Get already created table map info or initialize it with empty map
            val tableDishes = resultMap.getOrDefault(tableNumber, mutableMapOf())
            // Get dish quantity already found for this table or initialize it with zero
            val dishQuantity = tableDishes.getOrDefault(dishName, 0)
            // Set dish quantity info and increment it by one
            tableDishes[dishName] = dishQuantity + 1
            // Set table info
            resultMap[tableNumber] = tableDishes
        }

        // Initializing result list of list
        val result = mutableListOf<MutableList<String>>()

        // Create header table
        val header = mutableListOf<String>()
        // Add "Table" string since it is one of the requirements
        header.add("Table")
        for (dish in dishes) {
            // Add all the dishes' names sorted alphabetically
            header.add(dish)
        }
        // Add header to the result table
        result.add(header)

        // Go through all the tables and populate rows corresponding to each table
        for (table in tables) {
            // Initialize table row with zeroes at first
            // dishes.size + 1 is because we have first column populated with table numbers
            val resultRow = MutableList(dishes.size + 1) { "0" }
            // Populate table number
            resultRow[0] = table.toString()

            // Get all the dishes ordered for this table
            val tableDishes = resultMap[table]!!
            for (entry in tableDishes) {
                // Get "alphabetical" dish index to place it to the right position in the final table
                val dishIndex = dishes.indexOf(entry.key) + 1

                // Populate the quantity of dishes ordered for this table (at corresponding index)
                resultRow[dishIndex] = entry.value.toString()
            }
            // Add populated row to the final table
            result.add(resultRow)
        }

        return result
    }
}

Compiled from "Solution.kt"
public final class solved.p1418.Solution {
  public solved.p1418.Solution();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final java.util.List<java.util.List<java.lang.String>> displayTable(java.util.List<? extends java.util.List<java.lang.String>>);
    Code:
       0: aload_1
       1: ldc           #16                 // String orders
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: anewarray     #24                 // class java/lang/Integer
      10: invokestatic  #30                 // Method kotlin/collections/SetsKt.sortedSetOf:([Ljava/lang/Object;)Ljava/util/TreeSet;
      13: astore_2
      14: iconst_0
      15: anewarray     #32                 // class java/lang/String
      18: invokestatic  #30                 // Method kotlin/collections/SetsKt.sortedSetOf:([Ljava/lang/Object;)Ljava/util/TreeSet;
      21: astore_3
      22: new           #34                 // class java/util/LinkedHashMap
      25: dup
      26: invokespecial #35                 // Method java/util/LinkedHashMap."<init>":()V
      29: checkcast     #37                 // class java/util/Map
      32: astore        4
      34: aload_1
      35: invokeinterface #43,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      40: astore        5
      42: aload         5
      44: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          197
      52: aload         5
      54: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: checkcast     #39                 // class java/util/List
      62: astore        6
      64: aload         6
      66: iconst_1
      67: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      72: checkcast     #32                 // class java/lang/String
      75: invokestatic  #61                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      78: istore        7
      80: aload         6
      82: iconst_2
      83: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      88: checkcast     #32                 // class java/lang/String
      91: astore        8
      93: aload_2
      94: iload         7
      96: invokestatic  #65                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: invokevirtual #71                 // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
     102: pop
     103: aload_3
     104: aload         8
     106: invokevirtual #71                 // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
     109: pop
     110: aload         4
     112: iload         7
     114: invokestatic  #65                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     117: new           #34                 // class java/util/LinkedHashMap
     120: dup
     121: invokespecial #35                 // Method java/util/LinkedHashMap."<init>":()V
     124: checkcast     #37                 // class java/util/Map
     127: invokeinterface #75,  3           // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     132: checkcast     #37                 // class java/util/Map
     135: astore        9
     137: aload         9
     139: aload         8
     141: iconst_0
     142: invokestatic  #65                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     145: invokeinterface #75,  3           // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     150: checkcast     #77                 // class java/lang/Number
     153: invokevirtual #81                 // Method java/lang/Number.intValue:()I
     156: istore        10
     158: aload         9
     160: aload         8
     162: iload         10
     164: iconst_1
     165: iadd
     166: invokestatic  #65                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     169: invokeinterface #84,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     174: pop
     175: iload         7
     177: invokestatic  #65                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     180: astore        12
     182: aload         4
     184: aload         12
     186: aload         9
     188: invokeinterface #84,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     193: pop
     194: goto          42
     197: new           #86                 // class java/util/ArrayList
     200: dup
     201: invokespecial #87                 // Method java/util/ArrayList."<init>":()V
     204: checkcast     #39                 // class java/util/List
     207: astore        5
     209: new           #86                 // class java/util/ArrayList
     212: dup
     213: invokespecial #87                 // Method java/util/ArrayList."<init>":()V
     216: checkcast     #39                 // class java/util/List
     219: astore        6
     221: aload         6
     223: ldc           #89                 // String Table
     225: invokeinterface #90,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     230: pop
     231: aload_3
     232: invokevirtual #91                 // Method java/util/TreeSet.iterator:()Ljava/util/Iterator;
     235: dup
     236: ldc           #93                 // String iterator(...)
     238: invokestatic  #96                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     241: astore        7
     243: aload         7
     245: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     250: ifeq          284
     253: aload         7
     255: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     260: dup
     261: ldc           #98                 // String next(...)
     263: invokestatic  #96                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     266: checkcast     #32                 // class java/lang/String
     269: astore        8
     271: aload         6
     273: aload         8
     275: invokeinterface #90,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     280: pop
     281: goto          243
     284: aload         5
     286: aload         6
     288: invokeinterface #90,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     293: pop
     294: aload_2
     295: invokevirtual #91                 // Method java/util/TreeSet.iterator:()Ljava/util/Iterator;
     298: dup
     299: ldc           #93                 // String iterator(...)
     301: invokestatic  #96                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     304: astore        7
     306: aload         7
     308: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     313: ifeq          534
     316: aload         7
     318: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     323: dup
     324: ldc           #98                 // String next(...)
     326: invokestatic  #96                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     329: checkcast     #77                 // class java/lang/Number
     332: invokevirtual #81                 // Method java/lang/Number.intValue:()I
     335: istore        8
     337: aload_3
     338: invokevirtual #101                // Method java/util/TreeSet.size:()I
     341: iconst_1
     342: iadd
     343: istore        10
     345: new           #86                 // class java/util/ArrayList
     348: dup
     349: iload         10
     351: invokespecial #104                // Method java/util/ArrayList."<init>":(I)V
     354: astore        11
     356: iconst_0
     357: istore        12
     359: iload         12
     361: iload         10
     363: if_icmpge     396
     366: iload         12
     368: istore        13
     370: aload         11
     372: iload         13
     374: istore        14
     376: astore        16
     378: iconst_0
     379: istore        15
     381: ldc           #106                // String 0
     383: aload         16
     385: swap
     386: invokevirtual #107                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     389: pop
     390: iinc          12, 1
     393: goto          359
     396: aload         11
     398: checkcast     #39                 // class java/util/List
     401: astore        9
     403: aload         9
     405: iconst_0
     406: iload         8
     408: invokestatic  #110                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
     411: invokeinterface #114,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     416: pop
     417: aload         4
     419: iload         8
     421: invokestatic  #65                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     424: invokeinterface #117,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     429: dup
     430: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     433: checkcast     #37                 // class java/util/Map
     436: astore        10
     438: aload         10
     440: invokeinterface #125,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     445: invokeinterface #128,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     450: astore        11
     452: aload         11
     454: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     459: ifeq          521
     462: aload         11
     464: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     469: checkcast     #130                // class java/util/Map$Entry
     472: astore        12
     474: aload_3
     475: checkcast     #132                // class java/lang/Iterable
     478: aload         12
     480: invokeinterface #135,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     485: invokestatic  #141                // Method kotlin/collections/CollectionsKt.indexOf:(Ljava/lang/Iterable;Ljava/lang/Object;)I
     488: iconst_1
     489: iadd
     490: istore        13
     492: aload         9
     494: iload         13
     496: aload         12
     498: invokeinterface #144,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     503: checkcast     #77                 // class java/lang/Number
     506: invokevirtual #81                 // Method java/lang/Number.intValue:()I
     509: invokestatic  #110                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
     512: invokeinterface #114,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     517: pop
     518: goto          452
     521: aload         5
     523: aload         9
     525: invokeinterface #90,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     530: pop
     531: goto          306
     534: aload         5
     536: areturn
}