import java.io.File

data class Matrix(
    val matrix:Array<ArrayList<String>>,
    var row:Int = 0,
    var column:Int = 0
)

fun main(args: Array<String>) {
    var words:Array<String> = splitStringByDelimiter(readFile("./input.txt"), "\n")

    printStringArray(words)

    var maxWordLength = words.map{ it:String -> it.length }.max() ?: 0
    var maxWord = words.maxBy{ it:String -> it.length }
    println(maxWordLength)
    println(maxWord)

    var wordMatrix: Array<ArrayList<String>> = Array<ArrayList<String>>(maxWordLength) { arrayListOf() }

    //Counting sort
    for (word in words) {
        wordMatrix[word.length-1].add(word)
    }

    for (array in wordMatrix) {
        println("ARRAY")
        for (word in array) {
            println(word)
        }
    }

    var wordMatrixClass:Matrix = Matrix(wordMatrix)
}

fun readFile(filename:String):String = File(filename).inputStream().readBytes().toString(Charsets.UTF_8)

fun splitStringByDelimiter(input:String, delimiter:String):Array<String> = input.split(delimiter).map { it -> it.trim()}.dropLast(1).toTypedArray()

fun printStringArray(stringArray:Array<String>) {
    for (string in stringArray) {
        println(string)
    }
}

fun isSolutionValid(wordLength:Int, solutionLength:Int, solutionWord:String, referenceWord:String):Boolean = ((wordLength + solutionLength) <= referenceWord.length ) && referenceWord.startsWith(solutionWord)

fun isSolutionComplete(referenceWord:String, solutionWord:String):Boolean = referenceWord == solutionWord

fun buildMatchingWordArrayRec(wordMatrix:Matrix, solutionArrayList:ArrayList<String>, solutionLength:Int, solutionCalculation:String, solutionWord:String, referenceWord:String) {

    if (!isSolutionValid(wordMatrix.row, solutionLength, solutionWord, referenceWord)) {
        return
    }

    if (isSolutionComplete(referenceWord, solutionWord)) {
        println(solutionWord)
        solutionArrayList.add(solutionWord)
    }

    while (wordMatrix.row < wordMatrix.matrix.size) {
        while(wordMatrix.column < wordMatrix.matrix[wordMatrix.row].size) {

            //Add current word to word solution
            solutionWord.plus(wordMatrix.matrix[wordMatrix.row][wordMatrix.column])
            //solutionLength is now equal to the original length + matrixRow
            buildMatchingWordArrayRec(wordMatrix, solutionArrayList, solutionLength + wordMatrix.row, solutionCalculation, solutionWord, referenceWord)

            wordMatrix.column + 1
        }
        wordMatrix.row + 1
        wordMatrix.column = 0
    }
}

Compiled from "Main.kt"
public final class MainKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #17                 // String ./input.txt
       8: invokestatic  #21                 // Method readFile:(Ljava/lang/String;)Ljava/lang/String;
      11: ldc           #23                 // String \n
      13: invokestatic  #27                 // Method splitStringByDelimiter:(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;
      16: astore_1
      17: aload_1
      18: invokestatic  #30                 // Method printStringArray:([Ljava/lang/String;)V
      21: aload_1
      22: astore        4
      24: iconst_0
      25: istore        5
      27: aload         4
      29: astore        6
      31: new           #32                 // class java/util/ArrayList
      34: dup
      35: aload         4
      37: arraylength
      38: invokespecial #36                 // Method java/util/ArrayList."<init>":(I)V
      41: checkcast     #38                 // class java/util/Collection
      44: astore        7
      46: iconst_0
      47: istore        8
      49: iconst_0
      50: istore        9
      52: aload         6
      54: arraylength
      55: istore        10
      57: iload         9
      59: iload         10
      61: if_icmpge     105
      64: aload         6
      66: iload         9
      68: aaload
      69: astore        11
      71: aload         7
      73: aload         11
      75: astore        12
      77: astore        14
      79: iconst_0
      80: istore        13
      82: aload         12
      84: invokevirtual #44                 // Method java/lang/String.length:()I
      87: invokestatic  #50                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      90: aload         14
      92: swap
      93: invokeinterface #54,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      98: pop
      99: iinc          9, 1
     102: goto          57
     105: aload         7
     107: checkcast     #56                 // class java/util/List
     110: nop
     111: checkcast     #58                 // class java/lang/Iterable
     114: invokestatic  #64                 // Method kotlin/collections/CollectionsKt.maxOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     117: checkcast     #66                 // class java/lang/Number
     120: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     123: istore_2
     124: aload_1
     125: astore        4
     127: iconst_0
     128: istore        5
     130: aload         4
     132: arraylength
     133: ifne          140
     136: iconst_1
     137: goto          141
     140: iconst_0
     141: ifeq          152
     144: new           #71                 // class java/util/NoSuchElementException
     147: dup
     148: invokespecial #74                 // Method java/util/NoSuchElementException."<init>":()V
     151: athrow
     152: aload         4
     154: iconst_0
     155: aaload
     156: astore        6
     158: aload         4
     160: invokestatic  #80                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     163: istore        7
     165: iload         7
     167: ifne          175
     170: aload         6
     172: goto          250
     175: aload         6
     177: astore        8
     179: iconst_0
     180: istore        9
     182: aload         8
     184: invokevirtual #44                 // Method java/lang/String.length:()I
     187: istore        8
     189: iconst_1
     190: istore        9
     192: iload         9
     194: iload         7
     196: if_icmpgt     248
     199: aload         4
     201: iload         9
     203: aaload
     204: astore        10
     206: aload         10
     208: astore        11
     210: iconst_0
     211: istore        12
     213: aload         11
     215: invokevirtual #44                 // Method java/lang/String.length:()I
     218: istore        11
     220: iload         8
     222: iload         11
     224: if_icmpge     235
     227: aload         10
     229: astore        6
     231: iload         11
     233: istore        8
     235: iload         9
     237: iload         7
     239: if_icmpeq     248
     242: iinc          9, 1
     245: goto          199
     248: aload         6
     250: astore_3
     251: getstatic     #86                 // Field java/lang/System.out:Ljava/io/PrintStream;
     254: iload_2
     255: invokevirtual #91                 // Method java/io/PrintStream.println:(I)V
     258: getstatic     #86                 // Field java/lang/System.out:Ljava/io/PrintStream;
     261: aload_3
     262: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     265: iconst_0
     266: istore        5
     268: iload_2
     269: istore        6
     271: iload         6
     273: anewarray     #32                 // class java/util/ArrayList
     276: astore        7
     278: iload         5
     280: iload         6
     282: if_icmpge     307
     285: iload         5
     287: istore        8
     289: aload         7
     291: iload         8
     293: new           #32                 // class java/util/ArrayList
     296: dup
     297: invokespecial #95                 // Method java/util/ArrayList."<init>":()V
     300: aastore
     301: iinc          5, 1
     304: goto          278
     307: aload         7
     309: astore        4
     311: aload_1
     312: astore        5
     314: iconst_0
     315: istore        6
     317: aload         5
     319: arraylength
     320: istore        7
     322: iload         6
     324: iload         7
     326: if_icmpge     358
     329: aload         5
     331: iload         6
     333: aaload
     334: astore        8
     336: aload         4
     338: aload         8
     340: invokevirtual #44                 // Method java/lang/String.length:()I
     343: iconst_1
     344: isub
     345: aaload
     346: aload         8
     348: invokevirtual #96                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     351: pop
     352: iinc          6, 1
     355: goto          322
     358: aload         4
     360: astore        5
     362: iconst_0
     363: istore        6
     365: aload         5
     367: arraylength
     368: istore        7
     370: iload         6
     372: iload         7
     374: if_icmpge     451
     377: aload         5
     379: iload         6
     381: aaload
     382: astore        8
     384: ldc           #98                 // String ARRAY
     386: getstatic     #86                 // Field java/lang/System.out:Ljava/io/PrintStream;
     389: swap
     390: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     393: aload         8
     395: invokevirtual #102                // Method java/util/ArrayList.iterator:()Ljava/util/Iterator;
     398: dup
     399: ldc           #104                // String iterator(...)
     401: invokestatic  #107                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     404: astore        9
     406: aload         9
     408: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     413: ifeq          445
     416: aload         9
     418: invokeinterface #117,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     423: dup
     424: ldc           #119                // String next(...)
     426: invokestatic  #107                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     429: checkcast     #40                 // class java/lang/String
     432: astore        10
     434: getstatic     #86                 // Field java/lang/System.out:Ljava/io/PrintStream;
     437: aload         10
     439: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     442: goto          406
     445: iinc          6, 1
     448: goto          370
     451: new           #121                // class Matrix
     454: dup
     455: aload         4
     457: iconst_0
     458: iconst_0
     459: bipush        6
     461: aconst_null
     462: invokespecial #124                // Method Matrix."<init>":([Ljava/util/ArrayList;IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     465: astore        5
     467: return

  public static final java.lang.String readFile(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #161                // String filename
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #40                 // class java/lang/String
       9: dup
      10: new           #163                // class java/io/FileInputStream
      13: dup
      14: new           #165                // class java/io/File
      17: dup
      18: aload_0
      19: invokespecial #168                // Method java/io/File."<init>":(Ljava/lang/String;)V
      22: invokespecial #171                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      25: checkcast     #173                // class java/io/InputStream
      28: invokestatic  #179                // Method kotlin/io/ByteStreamsKt.readBytes:(Ljava/io/InputStream;)[B
      31: getstatic     #185                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      34: invokespecial #188                // Method java/lang/String."<init>":([BLjava/nio/charset/Charset;)V
      37: areturn

  public static final java.lang.String[] splitStringByDelimiter(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #190                // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #192                // String delimiter
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #194                // class java/lang/CharSequence
      16: iconst_1
      17: anewarray     #40                 // class java/lang/String
      20: astore_2
      21: aload_2
      22: iconst_0
      23: aload_1
      24: aastore
      25: aload_2
      26: iconst_0
      27: iconst_0
      28: bipush        6
      30: aconst_null
      31: invokestatic  #200                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      34: checkcast     #58                 // class java/lang/Iterable
      37: astore_2
      38: iconst_0
      39: istore_3
      40: aload_2
      41: astore        4
      43: new           #32                 // class java/util/ArrayList
      46: dup
      47: aload_2
      48: bipush        10
      50: invokestatic  #204                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      53: invokespecial #36                 // Method java/util/ArrayList."<init>":(I)V
      56: checkcast     #38                 // class java/util/Collection
      59: astore        5
      61: iconst_0
      62: istore        6
      64: aload         4
      66: invokeinterface #205,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      71: astore        7
      73: aload         7
      75: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      80: ifeq          130
      83: aload         7
      85: invokeinterface #117,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      90: astore        8
      92: aload         5
      94: aload         8
      96: checkcast     #40                 // class java/lang/String
      99: astore        9
     101: astore        11
     103: iconst_0
     104: istore        10
     106: aload         9
     108: checkcast     #194                // class java/lang/CharSequence
     111: invokestatic  #209                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     114: invokevirtual #213                // Method java/lang/Object.toString:()Ljava/lang/String;
     117: nop
     118: aload         11
     120: swap
     121: invokeinterface #54,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     126: pop
     127: goto          73
     130: aload         5
     132: checkcast     #56                 // class java/util/List
     135: nop
     136: iconst_1
     137: invokestatic  #217                // Method kotlin/collections/CollectionsKt.dropLast:(Ljava/util/List;I)Ljava/util/List;
     140: checkcast     #38                 // class java/util/Collection
     143: astore_2
     144: iconst_0
     145: istore_3
     146: aload_2
     147: astore        4
     149: aload         4
     151: iconst_0
     152: anewarray     #40                 // class java/lang/String
     155: invokeinterface #221,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     160: checkcast     #158                // class "[Ljava/lang/String;"
     163: areturn

  public static final void printStringArray(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #228                // String stringArray
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: arraylength
      10: istore_2
      11: iload_1
      12: iload_2
      13: if_icmpge     33
      16: aload_0
      17: iload_1
      18: aaload
      19: astore_3
      20: getstatic     #86                 // Field java/lang/System.out:Ljava/io/PrintStream;
      23: aload_3
      24: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      27: iinc          1, 1
      30: goto          11
      33: return

  public static final boolean isSolutionValid(int, int, java.lang.String, java.lang.String);
    Code:
       0: aload_2
       1: ldc           #233                // String solutionWord
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #235                // String referenceWord
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_0
      13: iload_1
      14: iadd
      15: aload_3
      16: invokevirtual #44                 // Method java/lang/String.length:()I
      19: if_icmpgt     37
      22: aload_3
      23: aload_2
      24: iconst_0
      25: iconst_2
      26: aconst_null
      27: invokestatic  #239                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      30: ifeq          37
      33: iconst_1
      34: goto          38
      37: iconst_0
      38: ireturn

  public static final boolean isSolutionComplete(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #235                // String referenceWord
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #233                // String solutionWord
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokestatic  #247                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      17: ireturn

  public static final void buildMatchingWordArrayRec(Matrix, java.util.ArrayList<java.lang.String>, int, java.lang.String, java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #251                // String wordMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #253                // String solutionArrayList
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #255                // String solutionCalculation
      15: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload         4
      20: ldc           #233                // String solutionWord
      22: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      25: aload         5
      27: ldc           #235                // String referenceWord
      29: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      32: aload_0
      33: invokevirtual #258                // Method Matrix.getRow:()I
      36: iload_2
      37: aload         4
      39: aload         5
      41: invokestatic  #260                // Method isSolutionValid:(IILjava/lang/String;Ljava/lang/String;)Z
      44: ifne          48
      47: return
      48: aload         5
      50: aload         4
      52: invokestatic  #262                // Method isSolutionComplete:(Ljava/lang/String;Ljava/lang/String;)Z
      55: ifeq          73
      58: getstatic     #86                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: aload         4
      63: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: aload_1
      67: aload         4
      69: invokevirtual #96                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      72: pop
      73: aload_0
      74: invokevirtual #258                // Method Matrix.getRow:()I
      77: aload_0
      78: invokevirtual #266                // Method Matrix.getMatrix:()[Ljava/util/ArrayList;
      81: arraylength
      82: if_icmpge     183
      85: aload_0
      86: invokevirtual #269                // Method Matrix.getColumn:()I
      89: aload_0
      90: invokevirtual #266                // Method Matrix.getMatrix:()[Ljava/util/ArrayList;
      93: aload_0
      94: invokevirtual #258                // Method Matrix.getRow:()I
      97: aaload
      98: invokevirtual #272                // Method java/util/ArrayList.size:()I
     101: if_icmpge     168
     104: new           #274                // class java/lang/StringBuilder
     107: dup
     108: invokespecial #275                // Method java/lang/StringBuilder."<init>":()V
     111: aload         4
     113: invokevirtual #279                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     116: aload_0
     117: invokevirtual #266                // Method Matrix.getMatrix:()[Ljava/util/ArrayList;
     120: aload_0
     121: invokevirtual #258                // Method Matrix.getRow:()I
     124: aaload
     125: aload_0
     126: invokevirtual #269                // Method Matrix.getColumn:()I
     129: invokevirtual #283                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     132: checkcast     #40                 // class java/lang/String
     135: invokevirtual #279                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     138: invokevirtual #284                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     141: pop
     142: aload_0
     143: aload_1
     144: iload_2
     145: aload_0
     146: invokevirtual #258                // Method Matrix.getRow:()I
     149: iadd
     150: aload_3
     151: aload         4
     153: aload         5
     155: invokestatic  #286                // Method buildMatchingWordArrayRec:(LMatrix;Ljava/util/ArrayList;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
     158: aload_0
     159: invokevirtual #269                // Method Matrix.getColumn:()I
     162: iconst_1
     163: iadd
     164: pop
     165: goto          85
     168: aload_0
     169: invokevirtual #258                // Method Matrix.getRow:()I
     172: iconst_1
     173: iadd
     174: pop
     175: aload_0
     176: iconst_0
     177: invokevirtual #289                // Method Matrix.setColumn:(I)V
     180: goto          73
     183: return
}


import java.io.File
import kotlin.streams.toList

fun main(args: Array<String>) {
    val input = "res/day_2_input.txt"
    val answer1 = Day2.part1(input)
    println("Part 1: $answer1")
    val answer2 = Day2.part2(input)
    println("Part 2: $answer2")
}

object Day2 {

    fun part1(input: String): Int {
        val reader = File(input).bufferedReader()
        val amounts = reader.lines()
                .map { parsePresent(it) }
                .map { it.surfaceArea() + it.slack() }
                .toList()
        return amounts.sum()
    }

    fun part2(input: String): Int {
        val reader = File(input).bufferedReader()
        val amounts = reader.lines()
                .map { parsePresent(it) }
                .map { it.ribbon() + it.bow() }
                .toList()
        return amounts.sum()
    }

    private fun parsePresent(dimensions: String): Present {
        val components = dimensions.split("x")
        return Present(components[0].toInt(), components[1].toInt(), components[2].toInt())
    }

}

data class Present(val width: Int, val height: Int, val length: Int) {
    fun surfaceArea(): Int {
        return 2 * length * width + 2 * width * height + 2 * height * length
    }

    fun slack(): Int {
        val sorted = listOf(width, height, length).sorted()
        return sorted[0] * sorted[1]
    }

    fun ribbon(): Int {
        val sorted = listOf(width, height, length).sorted()
        return sorted[0] * 2 + sorted[1] * 2
    }

    fun bow(): Int {
        return width * height * length
    }
}

Compiled from "day_2.kt"
public final class Day_2Kt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #17                 // String res/day_2_input.txt
       8: astore_1
       9: getstatic     #23                 // Field Day2.INSTANCE:LDay2;
      12: aload_1
      13: invokevirtual #27                 // Method Day2.part1:(Ljava/lang/String;)I
      16: istore_2
      17: new           #29                 // class java/lang/StringBuilder
      20: dup
      21: invokespecial #33                 // Method java/lang/StringBuilder."<init>":()V
      24: ldc           #35                 // String Part 1:
      26: invokevirtual #39                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      29: iload_2
      30: invokevirtual #42                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: invokevirtual #46                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      36: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      39: swap
      40: invokevirtual #58                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      43: getstatic     #23                 // Field Day2.INSTANCE:LDay2;
      46: aload_1
      47: invokevirtual #61                 // Method Day2.part2:(Ljava/lang/String;)I
      50: istore_3
      51: new           #29                 // class java/lang/StringBuilder
      54: dup
      55: invokespecial #33                 // Method java/lang/StringBuilder."<init>":()V
      58: ldc           #63                 // String Part 2:
      60: invokevirtual #39                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      63: iload_3
      64: invokevirtual #42                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      67: invokevirtual #46                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      70: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      73: swap
      74: invokevirtual #58                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      77: return
}


import java.io.File

fun main(args: Array<String>) {
    val input = "res/day_3_input.txt"
    val answer1 = Day3.part1(input)
    println("Part 1: $answer1")
    val answer2 = Day3.part2(input)
    println("Part 2: $answer2")
}

object Day3 {

    private enum class Turn {
        SANTA, ROBO_SANTA;

        fun nextTurn(): Turn {
            return when (this) {
                Turn.SANTA -> Turn.ROBO_SANTA
                else -> Turn.SANTA
            }
        }
    }

    fun part1(input: String): Int {
        val directions = File(input).readText().toCharArray()
        var currentPosition = Position(0, 0)
        val positions = mutableSetOf<Position>()
        positions.add(currentPosition)
        for (direction in directions) {
            val nextPosition = currentPosition.move(direction)
            positions.add(nextPosition)
            currentPosition = nextPosition
        }
        return positions.size
    }

    fun part2(input: String): Int {
        val directions = File(input).readText().toCharArray()
        var currentSantaPosition = Position(0, 0)
        var currentRoboSantaPosition = Position(0, 0)
        val positions = mutableSetOf<Position>()
        positions.add(currentSantaPosition)

        var turn = Turn.SANTA
        for (direction in directions) {
            when (turn) {
                Turn.SANTA -> {
                    val nextPosition = currentSantaPosition.move(direction)
                    positions.add(nextPosition)
                    currentSantaPosition = nextPosition

                }
                Turn.ROBO_SANTA -> {
                    val nextPosition = currentRoboSantaPosition.move(direction)
                    positions.add(nextPosition)
                    currentRoboSantaPosition = nextPosition
                }
            }
            turn = turn.nextTurn()
        }

        return positions.size
    }

}

data class Position(val x: Int, val y: Int) {
    fun move(direction: Char): Position {
        return when (direction) {
            '^' -> Position(this.x, this.y + 1)
            '>' -> Position(this.x + 1, this.y)
            'v' -> Position(this.x, this.y - 1)
            '<' -> Position(this.x - 1, this.y)
            else -> throw IllegalArgumentException("Input contained invalid character: $direction")
        }
    }
}

Compiled from "day_3.kt"
public final class Day_3Kt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #17                 // String res/day_3_input.txt
       8: astore_1
       9: getstatic     #23                 // Field Day3.INSTANCE:LDay3;
      12: aload_1
      13: invokevirtual #27                 // Method Day3.part1:(Ljava/lang/String;)I
      16: istore_2
      17: new           #29                 // class java/lang/StringBuilder
      20: dup
      21: invokespecial #33                 // Method java/lang/StringBuilder."<init>":()V
      24: ldc           #35                 // String Part 1:
      26: invokevirtual #39                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      29: iload_2
      30: invokevirtual #42                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: invokevirtual #46                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      36: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      39: swap
      40: invokevirtual #58                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      43: getstatic     #23                 // Field Day3.INSTANCE:LDay3;
      46: aload_1
      47: invokevirtual #61                 // Method Day3.part2:(Ljava/lang/String;)I
      50: istore_3
      51: new           #29                 // class java/lang/StringBuilder
      54: dup
      55: invokespecial #33                 // Method java/lang/StringBuilder."<init>":()V
      58: ldc           #63                 // String Part 2:
      60: invokevirtual #39                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      63: iload_3
      64: invokevirtual #42                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      67: invokevirtual #46                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      70: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      73: swap
      74: invokevirtual #58                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      77: return
}


import java.lang.StringBuilder

fun main(args: Array<String>) {
    val input = "1113222113"
    val answer1 = Day10.part1(input)
    println("Part 1: $answer1")
    val answer2 = Day10.part2(input)
    println("Part 2: $answer2")
}

object Day10 {

    private fun lookAndSay(sequence: String): String {
        val digits = sequence.toCharArray().map { Character.getNumericValue(it) }
        val stringBuilder = StringBuilder()
        var lastDigit = -1
        var currentDigit: Int
        var quantity = 0
        for (i in 0 until digits.size) {
            currentDigit = digits[i]
            if (i == digits.size - 1) {
                if (currentDigit != lastDigit) {
                    stringBuilder.append("$quantity$lastDigit")
                    stringBuilder.append("1$currentDigit")
                } else {
                    stringBuilder.append("${(quantity + 1)}$lastDigit")
                }
            } else if (currentDigit != lastDigit && lastDigit != -1) {
                stringBuilder.append("$quantity$lastDigit")
                quantity = 1
            } else {
                quantity++
            }
            lastDigit = currentDigit
        }
        return stringBuilder.toString()
    }

    fun part1(sequence: String): Int {
        var nextSequence = sequence
        repeat(40) {
            nextSequence = lookAndSay(nextSequence)
        }
        return nextSequence.length
    }

    fun part2(sequence: String): Int {
        var nextSequence = sequence
        repeat(50) {
            nextSequence = lookAndSay(nextSequence)
        }
        return nextSequence.length
    }

}

Compiled from "day_10.kt"
public final class Day_10Kt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #17                 // String 1113222113
       8: astore_1
       9: getstatic     #23                 // Field Day10.INSTANCE:LDay10;
      12: aload_1
      13: invokevirtual #27                 // Method Day10.part1:(Ljava/lang/String;)I
      16: istore_2
      17: new           #29                 // class java/lang/StringBuilder
      20: dup
      21: invokespecial #33                 // Method java/lang/StringBuilder."<init>":()V
      24: ldc           #35                 // String Part 1:
      26: invokevirtual #39                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      29: iload_2
      30: invokevirtual #42                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: invokevirtual #46                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      36: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      39: swap
      40: invokevirtual #58                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      43: getstatic     #23                 // Field Day10.INSTANCE:LDay10;
      46: aload_1
      47: invokevirtual #61                 // Method Day10.part2:(Ljava/lang/String;)I
      50: istore_3
      51: new           #29                 // class java/lang/StringBuilder
      54: dup
      55: invokespecial #33                 // Method java/lang/StringBuilder."<init>":()V
      58: ldc           #63                 // String Part 2:
      60: invokevirtual #39                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      63: iload_3
      64: invokevirtual #42                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      67: invokevirtual #46                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      70: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      73: swap
      74: invokevirtual #58                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      77: return
}


import java.io.File
import java.util.regex.Matcher

fun main(args: Array<String>) {
    val filename = "res/day_7_input.txt"
    val answer1 = Day7.part1(File(filename))
    println("Part 1: $answer1")
    val answer2 = Day7.part2(File(filename), answer1)
    println("Part 2: $answer2")
}

object Day7 {

    fun part1(file: File): Int {
        val wires = mutableMapOf<String, Gate>()
        file.useLines { lines ->
            lines.map { Gate.parse(it) }.forEach { wires[it.target] = it }
        }
        return wires["a"]!!.evaluate(wires)
    }

    fun part2(file: File, a: Int): Int {
        val wires = mutableMapOf<String, Gate>()
        file.useLines { lines ->
            lines.map { Gate.parse(it) }.forEach { wires[it.target] = it }
        }
        wires["b"]!!.wireValue = a
        return wires["a"]!!.evaluate(wires)
    }

}

sealed class Gate(val target: String) {

    companion object {

        private val andRegex = Regex("(?<left>[\\w\\d]+) AND (?<right>[\\w\\d]+) -> (?<target>\\w+)").toPattern()
        private val orRegex = Regex("(?<left>[\\w\\d]+) OR (?<right>[\\w\\d]+) -> (?<target>\\w+)").toPattern()
        private val lshiftRegex = Regex("(?<left>[\\w\\d]+) LSHIFT (?<right>[\\d]+) -> (?<target>\\w+)").toPattern()
        private val rshiftRegex = Regex("(?<left>[\\w\\d]+) RSHIFT (?<right>[\\d]+) -> (?<target>\\w+)").toPattern()
        private val notRegex = Regex("NOT (?<source>[\\w]+) -> (?<target>\\w+)").toPattern()
        private val signalRegex = Regex("(?<source>[\\w\\d]+) -> (?<target>\\w+)").toPattern()

        operator fun Matcher.get(name: String): String {
            return this.group(name)
        }

        fun parse(instruction: String): Gate {
            var matcher = andRegex.matcher(instruction)
            if (matcher.matches()) {
                return AndGate(matcher["left"], matcher["right"], matcher["target"])
            }
            matcher = orRegex.matcher(instruction)
            if (matcher.matches()) {
                return OrGate(matcher["left"], matcher["right"], matcher["target"])
            }
            matcher = lshiftRegex.matcher(instruction)
            if (matcher.matches()) {
                return LshiftGate(matcher["left"], matcher["right"].toInt(), matcher["target"])
            }
            matcher = rshiftRegex.matcher(instruction)
            if (matcher.matches()) {
                return RshiftGate(matcher["left"], matcher["right"].toInt(), matcher["target"])
            }
            matcher = notRegex.matcher(instruction)
            if (matcher.matches()) {
                return NotGate(matcher["source"], matcher["target"])
            }
            matcher = signalRegex.matcher(instruction)
            if (matcher.matches()) {
                return SignalGate(matcher["source"], matcher["target"])
            }
            throw IllegalArgumentException("Instruction '$instruction' could not be parsed")
        }

    }

    var wireValue: Int? = null

    abstract fun evaluate(wires: Map<String, Gate>): Int

}

class AndGate(private val left: String, private val right: String, target: String) : Gate(target) {
    override fun evaluate(wires: Map<String, Gate>): Int {
        if (wireValue == null) {
            wireValue = (left.toIntOrNull() ?: wires[left]!!.evaluate(wires)) and (right.toIntOrNull() ?: wires[right]!!.evaluate(wires))
        }
        return wireValue!!.toInt()
    }
}

class OrGate(private val left: String, private val right: String, target: String) : Gate(target) {
    override fun evaluate(wires: Map<String, Gate>): Int {
        if (wireValue == null) {
            wireValue = (left.toIntOrNull() ?: wires[left]!!.evaluate(wires)) or (right.toIntOrNull() ?: wires[right]!!.evaluate(wires))
        }
        return wireValue!!.toInt()
    }
}

class LshiftGate(private val left: String, private val right: Int, target: String) : Gate(target) {
    override fun evaluate(wires: Map<String, Gate>): Int {
        if (wireValue == null) {
            wireValue = (left.toIntOrNull() ?: wires[left]!!.evaluate(wires)) shl right
        }
        return wireValue!!.toInt()
    }
}

class RshiftGate(private val left: String, private val right: Int, target: String) : Gate(target) {
    override fun evaluate(wires: Map<String, Gate>): Int {
        if (wireValue == null) {
            wireValue = (left.toIntOrNull() ?: wires[left]!!.evaluate(wires)) shr right
        }
        return wireValue!!.toInt();
    }
}

class NotGate(private val source: String, target: String) : Gate(target) {
    override fun evaluate(wires: Map<String, Gate>): Int {
        if (wireValue == null) {
            wireValue = (source.toIntOrNull() ?: wires[source]!!.evaluate(wires)).inv()
        }
        return wireValue!!.toInt()
    }
}

class SignalGate(private val source: String, target: String) : Gate(target) {
    override fun evaluate(wires: Map<String, Gate>): Int {
        if (wireValue == null) {
            wireValue = source.toIntOrNull() ?: wires[source]!!.evaluate(wires)
        }
        return wireValue!!.toInt()
    }
}

Compiled from "day_7.kt"
public final class Day_7Kt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #17                 // String res/day_7_input.txt
       8: astore_1
       9: getstatic     #23                 // Field Day7.INSTANCE:LDay7;
      12: new           #25                 // class java/io/File
      15: dup
      16: aload_1
      17: invokespecial #29                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      20: invokevirtual #33                 // Method Day7.part1:(Ljava/io/File;)I
      23: istore_2
      24: new           #35                 // class java/lang/StringBuilder
      27: dup
      28: invokespecial #38                 // Method java/lang/StringBuilder."<init>":()V
      31: ldc           #40                 // String Part 1:
      33: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: iload_2
      37: invokevirtual #47                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      40: invokevirtual #51                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      43: getstatic     #57                 // Field java/lang/System.out:Ljava/io/PrintStream;
      46: swap
      47: invokevirtual #63                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      50: getstatic     #23                 // Field Day7.INSTANCE:LDay7;
      53: new           #25                 // class java/io/File
      56: dup
      57: aload_1
      58: invokespecial #29                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      61: iload_2
      62: invokevirtual #67                 // Method Day7.part2:(Ljava/io/File;I)I
      65: istore_3
      66: new           #35                 // class java/lang/StringBuilder
      69: dup
      70: invokespecial #38                 // Method java/lang/StringBuilder."<init>":()V
      73: ldc           #69                 // String Part 2:
      75: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      78: iload_3
      79: invokevirtual #47                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      82: invokevirtual #51                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      85: getstatic     #57                 // Field java/lang/System.out:Ljava/io/PrintStream;
      88: swap
      89: invokevirtual #63                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      92: return
}


import java.util.*

fun maxMatching(n: Int, graph: Array<MutableList<Int>>): Int {
    val matching = IntArray(n) { -1 }
    val seen = BooleanArray(n)
    fun dfs(i: Int): Boolean {
        seen[i].also { seen[i] = true }
        graph[i].forEach { j ->
            if (matching[j] == -1 || (!seen[matching[j]] && dfs(matching[j]))) {
                matching[j] = i
                return true
            }
        }
        return false
    }

    var matches = 0
    (0 until n).forEach { i ->
        if (dfs(i)) {
            matches++
        }
        seen.fill(false)
    }
    return matches
}

// The code above implements the Hopcroft-Karp algorithm for finding the maximum matching in a bipartite graph. The algorithm starts by initializing the matching array to -1, which represents the fact that no node has been matched yet. The function dfs(i) attempts to find an augmenting path starting from node i, and updates the matching array if it succeeds. The maxMatching function loops over all nodes in one side of the bipartite graph, calling dfs on each node and incrementing the matches counter if a match is found. This process continues until no more augmenting paths can be found. The final value of matches is the size of the maximum matching in the bipartite graph.

Compiled from "kt.kt"
public final class KtKt {
  public static final int maxMatching(int, java.util.List<java.lang.Integer>[]);
    Code:
       0: aload_1
       1: ldc           #10                 // String graph
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_3
       8: iload_0
       9: newarray       int
      11: astore        4
      13: iload_3
      14: iload_0
      15: if_icmpge     33
      18: iload_3
      19: istore        5
      21: aload         4
      23: iload         5
      25: iconst_m1
      26: iastore
      27: iinc          3, 1
      30: goto          13
      33: aload         4
      35: astore_2
      36: iload_0
      37: newarray       boolean
      39: astore_3
      40: iconst_0
      41: istore        4
      43: iconst_0
      44: iload_0
      45: invokestatic  #22                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      48: checkcast     #24                 // class java/lang/Iterable
      51: astore        5
      53: iconst_0
      54: istore        6
      56: aload         5
      58: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        7
      65: aload         7
      67: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          124
      75: aload         7
      77: checkcast     #36                 // class kotlin/collections/IntIterator
      80: invokevirtual #40                 // Method kotlin/collections/IntIterator.nextInt:()I
      83: istore        8
      85: iload         8
      87: istore        9
      89: iconst_0
      90: istore        10
      92: aload_3
      93: aload_1
      94: aload_2
      95: iload         9
      97: invokestatic  #44                 // Method maxMatching$dfs:([Z[Ljava/util/List;[II)Z
     100: ifeq          109
     103: iload         4
     105: iconst_1
     106: iadd
     107: istore        4
     109: aload_3
     110: iconst_0
     111: iconst_0
     112: iconst_0
     113: bipush        6
     115: aconst_null
     116: invokestatic  #50                 // Method kotlin/collections/ArraysKt.fill$default:([ZZIIILjava/lang/Object;)V
     119: nop
     120: nop
     121: goto          65
     124: nop
     125: iload         4
     127: ireturn

  private static final boolean maxMatching$dfs(boolean[], java.util.List<java.lang.Integer>[], int[], int);
    Code:
       0: aload_0
       1: iload_3
       2: baload
       3: istore        4
       5: iload         4
       7: istore        5
       9: iconst_0
      10: istore        6
      12: aload_0
      13: iload_3
      14: iconst_1
      15: bastore
      16: nop
      17: aload_1
      18: iload_3
      19: aaload
      20: checkcast     #24                 // class java/lang/Iterable
      23: astore        4
      25: iconst_0
      26: istore        5
      28: aload         4
      30: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      35: astore        6
      37: aload         6
      39: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          111
      47: aload         6
      49: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      54: astore        7
      56: aload         7
      58: checkcast     #74                 // class java/lang/Number
      61: invokevirtual #77                 // Method java/lang/Number.intValue:()I
      64: istore        8
      66: iconst_0
      67: istore        9
      69: aload_2
      70: iload         8
      72: iaload
      73: iconst_m1
      74: if_icmpeq     99
      77: aload_0
      78: aload_2
      79: iload         8
      81: iaload
      82: baload
      83: ifne          106
      86: aload_0
      87: aload_1
      88: aload_2
      89: aload_2
      90: iload         8
      92: iaload
      93: invokestatic  #44                 // Method maxMatching$dfs:([Z[Ljava/util/List;[II)Z
      96: ifeq          106
      99: aload_2
     100: iload         8
     102: iload_3
     103: iastore
     104: iconst_1
     105: ireturn
     106: nop
     107: nop
     108: goto          37
     111: nop
     112: iconst_0
     113: ireturn
}


class Day03 {
    fun part1(input: List<String>): Int {
        var priorityScore = 0

        for (line in input) {
            val matchingChar = getMatchingChar(line)
            priorityScore += getPriorityScore(matchingChar)
        }

        return priorityScore
    }

    fun part2(input: List<String>): Int {
        var priorityScore = 0

        for (lines in input.chunked(3)) {
            priorityScore += getPriorityScore(getMatchingCharThreeLines(lines))
        }

        return priorityScore
    }

    // Get char that matches across three lines
    private fun getMatchingCharThreeLines(lines: List<String>): Char {
        for (char in lines[0]) {
            if (lines[1].contains(char) && lines[2].contains(char)) {
                return char
            }
        }

        throw IllegalArgumentException("Lines do not contain matching char")
    }

    private fun getMatchingChar(line: String): Char {
        val firstRucksackRange = IntRange(0, line.length/2 - 1)
        val secondRucksackRange = IntRange(line.length/2, line.length - 1)

        for (char in line.substring(firstRucksackRange)) {
            if (char in line.substring(secondRucksackRange)) {
                return char
            }
        }

        throw IllegalArgumentException("Line does not contain matching character")
    }

    private fun getPriorityScore(matchingChar: Char): Int {
        return if (matchingChar.isLowerCase()) {
            matchingChar.code - 96
        } else {
            matchingChar.code - 38
        }
    }
}

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

  public final int part1(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_1
       9: invokeinterface #28,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      14: astore_3
      15: aload_3
      16: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      21: ifeq          55
      24: aload_3
      25: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      30: checkcast     #40                 // class java/lang/String
      33: astore        4
      35: aload_0
      36: aload         4
      38: invokespecial #44                 // Method getMatchingChar:(Ljava/lang/String;)C
      41: istore        5
      43: iload_2
      44: aload_0
      45: iload         5
      47: invokespecial #48                 // Method getPriorityScore:(C)I
      50: iadd
      51: istore_2
      52: goto          15
      55: iload_2
      56: ireturn

  public final int part2(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_1
       9: checkcast     #58                 // class java/lang/Iterable
      12: iconst_3
      13: invokestatic  #64                 // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
      16: invokeinterface #28,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      21: astore_3
      22: aload_3
      23: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      28: ifeq          58
      31: aload_3
      32: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      37: checkcast     #24                 // class java/util/List
      40: astore        4
      42: iload_2
      43: aload_0
      44: aload_0
      45: aload         4
      47: invokespecial #68                 // Method getMatchingCharThreeLines:(Ljava/util/List;)C
      50: invokespecial #48                 // Method getPriorityScore:(C)I
      53: iadd
      54: istore_2
      55: goto          22
      58: iload_2
      59: ireturn

  private final char getMatchingCharThreeLines(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: iconst_0
       2: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #40                 // class java/lang/String
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: invokevirtual #78                 // Method java/lang/String.length:()I
      17: istore        4
      19: iload_3
      20: iload         4
      22: if_icmpge     83
      25: aload_2
      26: iload_3
      27: invokevirtual #82                 // Method java/lang/String.charAt:(I)C
      30: istore        5
      32: aload_1
      33: iconst_1
      34: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      39: checkcast     #84                 // class java/lang/CharSequence
      42: iload         5
      44: iconst_0
      45: iconst_2
      46: aconst_null
      47: invokestatic  #90                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
      50: ifeq          77
      53: aload_1
      54: iconst_2
      55: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #84                 // class java/lang/CharSequence
      63: iload         5
      65: iconst_0
      66: iconst_2
      67: aconst_null
      68: invokestatic  #90                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
      71: ifeq          77
      74: iload         5
      76: ireturn
      77: iinc          3, 1
      80: goto          19
      83: new           #92                 // class java/lang/IllegalArgumentException
      86: dup
      87: ldc           #94                 // String Lines do not contain matching char
      89: invokespecial #97                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      92: athrow

  private final char getMatchingChar(java.lang.String);
    Code:
       0: new           #100                // class kotlin/ranges/IntRange
       3: dup
       4: iconst_0
       5: aload_1
       6: invokevirtual #78                 // Method java/lang/String.length:()I
       9: iconst_2
      10: idiv
      11: iconst_1
      12: isub
      13: invokespecial #103                // Method kotlin/ranges/IntRange."<init>":(II)V
      16: astore_2
      17: new           #100                // class kotlin/ranges/IntRange
      20: dup
      21: aload_1
      22: invokevirtual #78                 // Method java/lang/String.length:()I
      25: iconst_2
      26: idiv
      27: aload_1
      28: invokevirtual #78                 // Method java/lang/String.length:()I
      31: iconst_1
      32: isub
      33: invokespecial #103                // Method kotlin/ranges/IntRange."<init>":(II)V
      36: astore_3
      37: aload_1
      38: aload_2
      39: invokestatic  #107                // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
      42: astore        4
      44: iconst_0
      45: istore        5
      47: aload         4
      49: invokevirtual #78                 // Method java/lang/String.length:()I
      52: istore        6
      54: iload         5
      56: iload         6
      58: if_icmpge     98
      61: aload         4
      63: iload         5
      65: invokevirtual #82                 // Method java/lang/String.charAt:(I)C
      68: istore        7
      70: aload_1
      71: aload_3
      72: invokestatic  #107                // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
      75: checkcast     #84                 // class java/lang/CharSequence
      78: iload         7
      80: iconst_0
      81: iconst_2
      82: aconst_null
      83: invokestatic  #90                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
      86: ifeq          92
      89: iload         7
      91: ireturn
      92: iinc          5, 1
      95: goto          54
      98: new           #92                 // class java/lang/IllegalArgumentException
     101: dup
     102: ldc           #109                // String Line does not contain matching character
     104: invokespecial #97                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     107: athrow

  private final int getPriorityScore(char);
    Code:
       0: iload_1
       1: invokestatic  #118                // Method java/lang/Character.isLowerCase:(C)Z
       4: ifeq          14
       7: iload_1
       8: bipush        96
      10: isub
      11: goto          18
      14: iload_1
      15: bipush        38
      17: isub
      18: ireturn
}


class Day02 {
    private val scores1 = mapOf(
        'X' to mapOf('A' to 4, 'B' to 1, 'C' to 7),
        'Y' to mapOf('A' to 8, 'B' to 5, 'C' to 2),
        'Z' to mapOf('A' to 3, 'B' to 9, 'C' to 6)
    )

    private val scores2 = mapOf(
        'X' to mapOf('A' to 3, 'B' to 1, 'C' to 2),
        'Y' to mapOf('A' to 4, 'B' to 5, 'C' to 6),
        'Z' to mapOf('A' to 8, 'B' to 9, 'C' to 7)
    )

    fun part1(input: List<String>): Int {
        var score = 0

        for (line in input) {
            val opChoice = line[0]
            val myChoice = line[2]

            score += scores1[myChoice]!![opChoice]!!
        }

        return score
    }

    fun part2(input: List<String>): Int {
        var score = 0

        for (line in input) {
            val opChoice = line[0]
            val myOutcome = line[2]

            score += scores2[myOutcome]!![opChoice]!!
        }

        return score
    }
}

Compiled from "Day02.kt"
public final class Day02 {
  private final java.util.Map<java.lang.Character, java.util.Map<java.lang.Character, java.lang.Integer>> scores1;

  private final java.util.Map<java.lang.Character, java.util.Map<java.lang.Character, java.lang.Integer>> scores2;

  public Day02();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iconst_3
       6: anewarray     #10                 // class kotlin/Pair
       9: astore_1
      10: aload_1
      11: iconst_0
      12: bipush        88
      14: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      17: iconst_3
      18: anewarray     #10                 // class kotlin/Pair
      21: astore_2
      22: aload_2
      23: iconst_0
      24: bipush        65
      26: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      29: iconst_4
      30: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      36: aastore
      37: aload_2
      38: iconst_1
      39: bipush        66
      41: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      44: iconst_1
      45: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      48: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      51: aastore
      52: aload_2
      53: iconst_2
      54: bipush        67
      56: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      59: bipush        7
      61: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      64: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      67: aastore
      68: aload_2
      69: invokestatic  #33                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      72: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      75: aastore
      76: aload_1
      77: iconst_1
      78: bipush        89
      80: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      83: iconst_3
      84: anewarray     #10                 // class kotlin/Pair
      87: astore_2
      88: aload_2
      89: iconst_0
      90: bipush        65
      92: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      95: bipush        8
      97: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     100: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     103: aastore
     104: aload_2
     105: iconst_1
     106: bipush        66
     108: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     111: iconst_5
     112: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     115: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     118: aastore
     119: aload_2
     120: iconst_2
     121: bipush        67
     123: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     126: iconst_2
     127: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     130: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     133: aastore
     134: aload_2
     135: invokestatic  #33                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     138: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     141: aastore
     142: aload_1
     143: iconst_2
     144: bipush        90
     146: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     149: iconst_3
     150: anewarray     #10                 // class kotlin/Pair
     153: astore_2
     154: aload_2
     155: iconst_0
     156: bipush        65
     158: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     161: iconst_3
     162: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     165: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     168: aastore
     169: aload_2
     170: iconst_1
     171: bipush        66
     173: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     176: bipush        9
     178: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     181: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     184: aastore
     185: aload_2
     186: iconst_2
     187: bipush        67
     189: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     192: bipush        6
     194: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     197: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     200: aastore
     201: aload_2
     202: invokestatic  #33                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     205: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     208: aastore
     209: aload_1
     210: invokestatic  #33                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     213: putfield      #37                 // Field scores1:Ljava/util/Map;
     216: aload_0
     217: iconst_3
     218: anewarray     #10                 // class kotlin/Pair
     221: astore_1
     222: aload_1
     223: iconst_0
     224: bipush        88
     226: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     229: iconst_3
     230: anewarray     #10                 // class kotlin/Pair
     233: astore_2
     234: aload_2
     235: iconst_0
     236: bipush        65
     238: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     241: iconst_3
     242: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     245: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     248: aastore
     249: aload_2
     250: iconst_1
     251: bipush        66
     253: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     256: iconst_1
     257: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     260: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     263: aastore
     264: aload_2
     265: iconst_2
     266: bipush        67
     268: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     271: iconst_2
     272: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     275: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     278: aastore
     279: aload_2
     280: invokestatic  #33                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     283: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     286: aastore
     287: aload_1
     288: iconst_1
     289: bipush        89
     291: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     294: iconst_3
     295: anewarray     #10                 // class kotlin/Pair
     298: astore_2
     299: aload_2
     300: iconst_0
     301: bipush        65
     303: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     306: iconst_4
     307: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     310: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     313: aastore
     314: aload_2
     315: iconst_1
     316: bipush        66
     318: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     321: iconst_5
     322: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     325: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     328: aastore
     329: aload_2
     330: iconst_2
     331: bipush        67
     333: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     336: bipush        6
     338: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     341: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     344: aastore
     345: aload_2
     346: invokestatic  #33                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     349: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     352: aastore
     353: aload_1
     354: iconst_2
     355: bipush        90
     357: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     360: iconst_3
     361: anewarray     #10                 // class kotlin/Pair
     364: astore_2
     365: aload_2
     366: iconst_0
     367: bipush        65
     369: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     372: bipush        8
     374: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     377: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     380: aastore
     381: aload_2
     382: iconst_1
     383: bipush        66
     385: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     388: bipush        9
     390: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     393: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     396: aastore
     397: aload_2
     398: iconst_2
     399: bipush        67
     401: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     404: bipush        7
     406: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     409: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     412: aastore
     413: aload_2
     414: invokestatic  #33                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     417: invokestatic  #27                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     420: aastore
     421: aload_1
     422: invokestatic  #33                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     425: putfield      #40                 // Field scores2:Ljava/util/Map;
     428: return

  public final int part1(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #48                 // String input
       3: invokestatic  #54                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_1
       9: invokeinterface #60,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      14: astore_3
      15: aload_3
      16: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      21: ifeq          98
      24: aload_3
      25: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      30: checkcast     #72                 // class java/lang/String
      33: astore        4
      35: aload         4
      37: iconst_0
      38: invokevirtual #76                 // Method java/lang/String.charAt:(I)C
      41: istore        5
      43: aload         4
      45: iconst_2
      46: invokevirtual #76                 // Method java/lang/String.charAt:(I)C
      49: istore        6
      51: iload_2
      52: aload_0
      53: getfield      #37                 // Field scores1:Ljava/util/Map;
      56: iload         6
      58: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      61: invokeinterface #82,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      66: dup
      67: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      70: checkcast     #78                 // class java/util/Map
      73: iload         5
      75: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      78: invokeinterface #82,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      83: dup
      84: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      87: checkcast     #88                 // class java/lang/Number
      90: invokevirtual #92                 // Method java/lang/Number.intValue:()I
      93: iadd
      94: istore_2
      95: goto          15
      98: iload_2
      99: ireturn

  public final int part2(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #48                 // String input
       3: invokestatic  #54                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_1
       9: invokeinterface #60,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      14: astore_3
      15: aload_3
      16: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      21: ifeq          98
      24: aload_3
      25: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      30: checkcast     #72                 // class java/lang/String
      33: astore        4
      35: aload         4
      37: iconst_0
      38: invokevirtual #76                 // Method java/lang/String.charAt:(I)C
      41: istore        5
      43: aload         4
      45: iconst_2
      46: invokevirtual #76                 // Method java/lang/String.charAt:(I)C
      49: istore        6
      51: iload_2
      52: aload_0
      53: getfield      #40                 // Field scores2:Ljava/util/Map;
      56: iload         6
      58: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      61: invokeinterface #82,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      66: dup
      67: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      70: checkcast     #78                 // class java/util/Map
      73: iload         5
      75: invokestatic  #16                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      78: invokeinterface #82,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      83: dup
      84: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      87: checkcast     #88                 // class java/lang/Number
      90: invokevirtual #92                 // Method java/lang/Number.intValue:()I
      93: iadd
      94: istore_2
      95: goto          15
      98: iload_2
      99: ireturn
}


/**
 * 邻接矩阵
 * 1 2 0 0
 * 0 0 1 0
 * 1 0 0 1
 * 0 0 1 0
 */
val matrix = arrayOf(
        "1200",
        "0010",
        "1001",
        "0010"
)

/**
 * 矩阵乘法
 */
fun multiply(a: Array<IntArray>, b: Array<IntArray>): Array<IntArray> {
    val arr = Array(a.size) { IntArray(b[0].size) }
    for (i in a.indices) {
        for (j in 0 until b[0].size) {
            for (k in 0 until a[0].size) {
                arr[i][j] += a[i][k] * b[k][j]
            }
        }
    }
    return arr
}

/**
 * 输出矩阵
 */
fun printMatrix(a: Array<IntArray>, mode: Int = 0) {
    val n = a.size
    for (i in 0 until n) {
        for (j in 0 until n) {
            print(if (mode == 0) "${a[i][j]} " else "${if (a[i][j] != 0) 1 else 0} ")
        }
        println()
    }
}

/**
 * 矩阵内元素和
 */
fun sumMatrix(a: Array<IntArray>): Int {
    val n = a.size
    var t = 0
    for (i in 0 until n) {
        for (j in 0 until n) {
            t += a[i][j]
        }
    }
    return t
}

/**
 * 矩阵加法
 */
fun add(a: Array<IntArray>, b: Array<IntArray>): Array<IntArray> {
    val n = a.size
    val arr = Array(n) { IntArray(n) }
    for (i in 0 until n) {
        for (j in 0 until n) {
            arr[i][j] = a[i][j] + b[i][j]
        }
    }
    return arr
}

/**
 * 主函数
 */
fun main(args: Array<String>) {
    val n = matrix.size
    //创建二维数组存储矩阵
    val arr = Array(n) { IntArray(n) }
    //初始化矩阵，将文本形式的矩阵转换成数组形式
    (0 until n).forEach { i ->
        var t = matrix[i].toInt()
        (0 until n).forEach {
            arr[i][n - 1 - it] = t % 10
            t /= 10
        }
    }
    //输出邻接矩阵
    println("邻接矩阵")
    printMatrix(arr)
    println()

    //计算并存储矩阵的n次方
    val arr2 = multiply(arr, arr)
    val arr3 = multiply(arr, arr2)
    val arr4 = multiply(arr, arr3)
    println("邻接矩阵4次方")
    printMatrix(arr4)
    println("长度为4的通路")
    println(sumMatrix(arr4))
    println()

    //合并矩阵
    val arrs = add(arr, add(arr2, arr3))
    println("可达矩阵")
    printMatrix(arrs, 1)
}

Compiled from "Matrix.kt"
public final class MatrixKt {
  private static final java.lang.String[] matrix;

  public static final java.lang.String[] getMatrix();
    Code:
       0: getstatic     #11                 // Field matrix:[Ljava/lang/String;
       3: areturn

  public static final int[][] multiply(int[][], int[][]);
    Code:
       0: aload_0
       1: ldc           #15                 // String a
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #23                 // String b
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_3
      14: aload_0
      15: checkcast     #25                 // class "[Ljava/lang/Object;"
      18: arraylength
      19: istore        4
      21: iload         4
      23: anewarray     #27                 // class "[I"
      26: astore        5
      28: iload_3
      29: iload         4
      31: if_icmpge     54
      34: iload_3
      35: istore        6
      37: aload         5
      39: iload         6
      41: aload_1
      42: iconst_0
      43: aaload
      44: arraylength
      45: newarray       int
      47: aastore
      48: iinc          3, 1
      51: goto          28
      54: aload         5
      56: astore_2
      57: iconst_0
      58: istore_3
      59: aload_0
      60: checkcast     #25                 // class "[Ljava/lang/Object;"
      63: arraylength
      64: istore        4
      66: iload_3
      67: iload         4
      69: if_icmpge     156
      72: iconst_0
      73: istore        5
      75: aload_1
      76: iconst_0
      77: aaload
      78: arraylength
      79: istore        6
      81: iload         5
      83: iload         6
      85: if_icmpge     150
      88: iconst_0
      89: istore        7
      91: aload_0
      92: iconst_0
      93: aaload
      94: arraylength
      95: istore        8
      97: iload         7
      99: iload         8
     101: if_icmpge     144
     104: aload_2
     105: iload_3
     106: aaload
     107: astore        9
     109: iload         5
     111: istore        10
     113: aload         9
     115: iload         10
     117: aload         9
     119: iload         10
     121: iaload
     122: aload_0
     123: iload_3
     124: aaload
     125: iload         7
     127: iaload
     128: aload_1
     129: iload         7
     131: aaload
     132: iload         5
     134: iaload
     135: imul
     136: iadd
     137: iastore
     138: iinc          7, 1
     141: goto          97
     144: iinc          5, 1
     147: goto          81
     150: iinc          3, 1
     153: goto          66
     156: aload_2
     157: areturn

  public static final void printMatrix(int[][], int);
    Code:
       0: aload_0
       1: ldc           #15                 // String a
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #25                 // class "[Ljava/lang/Object;"
      10: arraylength
      11: istore_2
      12: iconst_0
      13: istore_3
      14: iload_3
      15: iload_2
      16: if_icmpge     116
      19: iconst_0
      20: istore        4
      22: iload         4
      24: iload_2
      25: if_icmpge     104
      28: iload_1
      29: ifne          59
      32: new           #38                 // class java/lang/StringBuilder
      35: dup
      36: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      39: aload_0
      40: iload_3
      41: aaload
      42: iload         4
      44: iaload
      45: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      48: bipush        32
      50: invokevirtual #49                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      53: invokevirtual #53                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      56: goto          91
      59: new           #38                 // class java/lang/StringBuilder
      62: dup
      63: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      66: aload_0
      67: iload_3
      68: aaload
      69: iload         4
      71: iaload
      72: ifeq          79
      75: iconst_1
      76: goto          80
      79: iconst_0
      80: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      83: bipush        32
      85: invokevirtual #49                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      88: invokevirtual #53                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      91: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
      94: swap
      95: invokevirtual #65                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      98: iinc          4, 1
     101: goto          22
     104: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     107: invokevirtual #68                 // Method java/io/PrintStream.println:()V
     110: iinc          3, 1
     113: goto          14
     116: return

  public static void printMatrix$default(int[][], int, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_1
       8: aload_0
       9: iload_1
      10: invokestatic  #76                 // Method printMatrix:([[II)V
      13: return

  public static final int sumMatrix(int[][]);
    Code:
       0: aload_0
       1: ldc           #15                 // String a
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #25                 // class "[Ljava/lang/Object;"
      10: arraylength
      11: istore_1
      12: iconst_0
      13: istore_2
      14: iconst_0
      15: istore_3
      16: iload_3
      17: iload_1
      18: if_icmpge     51
      21: iconst_0
      22: istore        4
      24: iload         4
      26: iload_1
      27: if_icmpge     45
      30: iload_2
      31: aload_0
      32: iload_3
      33: aaload
      34: iload         4
      36: iaload
      37: iadd
      38: istore_2
      39: iinc          4, 1
      42: goto          24
      45: iinc          3, 1
      48: goto          16
      51: iload_2
      52: ireturn

  public static final int[][] add(int[][], int[][]);
    Code:
       0: aload_0
       1: ldc           #15                 // String a
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #23                 // String b
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #25                 // class "[Ljava/lang/Object;"
      16: arraylength
      17: istore_2
      18: iconst_0
      19: istore        4
      21: iload_2
      22: anewarray     #27                 // class "[I"
      25: astore        5
      27: iload         4
      29: iload_2
      30: if_icmpge     51
      33: iload         4
      35: istore        6
      37: aload         5
      39: iload         6
      41: iload_2
      42: newarray       int
      44: aastore
      45: iinc          4, 1
      48: goto          27
      51: aload         5
      53: astore_3
      54: iconst_0
      55: istore        4
      57: iload         4
      59: iload_2
      60: if_icmpge     106
      63: iconst_0
      64: istore        5
      66: iload         5
      68: iload_2
      69: if_icmpge     100
      72: aload_3
      73: iload         4
      75: aaload
      76: iload         5
      78: aload_0
      79: iload         4
      81: aaload
      82: iload         5
      84: iaload
      85: aload_1
      86: iload         4
      88: aaload
      89: iload         5
      91: iaload
      92: iadd
      93: iastore
      94: iinc          5, 1
      97: goto          66
     100: iinc          4, 1
     103: goto          57
     106: aload_3
     107: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #84                 // String args
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: getstatic     #11                 // Field matrix:[Ljava/lang/String;
       9: arraylength
      10: istore_1
      11: iconst_0
      12: istore_3
      13: iload_1
      14: anewarray     #27                 // class "[I"
      17: astore        4
      19: iload_3
      20: iload_1
      21: if_icmpge     41
      24: iload_3
      25: istore        5
      27: aload         4
      29: iload         5
      31: iload_1
      32: newarray       int
      34: aastore
      35: iinc          3, 1
      38: goto          19
      41: aload         4
      43: astore_2
      44: iconst_0
      45: iload_1
      46: invokestatic  #90                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      49: checkcast     #92                 // class java/lang/Iterable
      52: astore_3
      53: iconst_0
      54: istore        4
      56: aload_3
      57: invokeinterface #96,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      62: astore        5
      64: aload         5
      66: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      71: ifeq          188
      74: aload         5
      76: checkcast     #104                // class kotlin/collections/IntIterator
      79: invokevirtual #108                // Method kotlin/collections/IntIterator.nextInt:()I
      82: istore        6
      84: iload         6
      86: istore        7
      88: iconst_0
      89: istore        8
      91: iconst_0
      92: istore        9
      94: getstatic     #11                 // Field matrix:[Ljava/lang/String;
      97: iload         7
      99: aaload
     100: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     103: istore        9
     105: iconst_0
     106: iload_1
     107: invokestatic  #90                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     110: checkcast     #92                 // class java/lang/Iterable
     113: astore        10
     115: iconst_0
     116: istore        11
     118: aload         10
     120: invokeinterface #96,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     125: astore        12
     127: aload         12
     129: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     134: ifeq          182
     137: aload         12
     139: checkcast     #104                // class kotlin/collections/IntIterator
     142: invokevirtual #108                // Method kotlin/collections/IntIterator.nextInt:()I
     145: istore        13
     147: iload         13
     149: istore        14
     151: iconst_0
     152: istore        15
     154: aload_2
     155: iload         7
     157: aaload
     158: iload_1
     159: iconst_1
     160: isub
     161: iload         14
     163: isub
     164: iload         9
     166: bipush        10
     168: irem
     169: iastore
     170: iload         9
     172: bipush        10
     174: idiv
     175: istore        9
     177: nop
     178: nop
     179: goto          127
     182: nop
     183: nop
     184: nop
     185: goto          64
     188: nop
     189: ldc           #116                // String 邻接矩阵
     191: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     194: swap
     195: invokevirtual #118                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     198: aload_2
     199: iconst_0
     200: iconst_2
     201: aconst_null
     202: invokestatic  #120                // Method printMatrix$default:([[IIILjava/lang/Object;)V
     205: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     208: invokevirtual #68                 // Method java/io/PrintStream.println:()V
     211: aload_2
     212: aload_2
     213: invokestatic  #122                // Method multiply:([[I[[I)[[I
     216: astore_3
     217: aload_2
     218: aload_3
     219: invokestatic  #122                // Method multiply:([[I[[I)[[I
     222: astore        4
     224: aload_2
     225: aload         4
     227: invokestatic  #122                // Method multiply:([[I[[I)[[I
     230: astore        5
     232: ldc           #124                // String 邻接矩阵4次方
     234: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     237: swap
     238: invokevirtual #118                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     241: aload         5
     243: iconst_0
     244: iconst_2
     245: aconst_null
     246: invokestatic  #120                // Method printMatrix$default:([[IIILjava/lang/Object;)V
     249: ldc           #126                // String 长度为4的通路
     251: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     254: swap
     255: invokevirtual #118                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     258: aload         5
     260: invokestatic  #128                // Method sumMatrix:([[I)I
     263: istore        6
     265: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     268: iload         6
     270: invokevirtual #131                // Method java/io/PrintStream.println:(I)V
     273: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     276: invokevirtual #68                 // Method java/io/PrintStream.println:()V
     279: aload_2
     280: aload_3
     281: aload         4
     283: invokestatic  #133                // Method add:([[I[[I)[[I
     286: invokestatic  #133                // Method add:([[I[[I)[[I
     289: astore        6
     291: ldc           #135                // String 可达矩阵
     293: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     296: swap
     297: invokevirtual #118                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     300: aload         6
     302: iconst_1
     303: invokestatic  #76                 // Method printMatrix:([[II)V
     306: return

  static {};
    Code:
       0: iconst_4
       1: anewarray     #72                 // class java/lang/String
       4: astore_0
       5: aload_0
       6: iconst_0
       7: ldc           #150                // String 1200
       9: aastore
      10: aload_0
      11: iconst_1
      12: ldc           #152                // String 0010
      14: aastore
      15: aload_0
      16: iconst_2
      17: ldc           #154                // String 1001
      19: aastore
      20: aload_0
      21: iconst_3
      22: ldc           #152                // String 0010
      24: aastore
      25: aload_0
      26: putstatic     #11                 // Field matrix:[Ljava/lang/String;
      29: return
}