package day10

class Day10(private val input: List<String>) {

    private val commands = parseCommands(input)

    private fun parseCommands(input: List<String>): List<Command> {
        return input.flatMap { parseCommand(it) }
    }

    private fun parseCommand(input: String): List<Command> {
        if (input == "noop") return listOf(Command.Noop)
        val split = input.split(" ")
        if (split[0] == "addx") return listOf(Command.AddFirstCycle(split[1].toInt()), Command.AddSecondCycle(split[1].toInt()))
        return listOf()
    }

    fun part1(): Int {
        val _20 = commands.take(19).fold(1) { initial, command -> initial + command.compute() } * 20
        val _60 = commands.take(59).fold(1) { initial, command -> initial + command.compute() } * 60
        val _100 = commands.take(99).fold(1) { initial, command -> initial + command.compute() } * 100
        val _140 = commands.take(139).fold(1) { initial, command -> initial + command.compute() } * 140
        val _180 = commands.take(179).fold(1) { initial, command -> initial + command.compute() } * 180
        val _220 = commands.take(219).foldIndexed(1) { i, initial, command -> initial + command.compute() } * 220
        return _20 + _60 + _100 + _140 + _180 + _220
    }

    fun part2(): String {
        val emptyRow = (0 until 40).joinToString("") { "." }
        val firstRow = Row(cyclePosition = 0, currentRow = emptyRow, 1)
        val row1 = commands.take(40).fold(firstRow) { row, command -> row.handleCommand(command)}
        val secondRow = Row(cyclePosition = 0, currentRow = emptyRow, registerX = row1.registerX)
        val row2 = commands.drop(40).take(40).fold(secondRow) { row, command -> row.handleCommand(command)}
        val third = Row(cyclePosition = 0, currentRow = emptyRow, registerX = row2.registerX)
        val row3 = commands.drop(80).take(40).fold(third) { row, command -> row.handleCommand(command)}
        val fourth = Row(cyclePosition = 0, currentRow = emptyRow, row3.registerX)
        val row4 = commands.drop(120).take(40).fold(fourth) { row, command -> row.handleCommand(command)}
        val fifth = Row(cyclePosition = 0, currentRow = emptyRow, registerX = row4.registerX)
        val row5 = commands.drop(160).take(40).fold(fifth) { row, command -> row.handleCommand(command)}
        val sixth = Row(cyclePosition = 0, currentRow = emptyRow, registerX = row5.registerX)
        val row6 = commands.drop(200).take(40).fold(sixth) { row, command -> row.handleCommand(command)}

        return "\n${row1.currentRow}\n" +
                "${row2.currentRow}\n" +
                "${row3.currentRow}\n" +
                "${row4.currentRow}\n" +
                "${row5.currentRow}\n" +
                "${row6.currentRow}\n"
    }
}

sealed class Command {
    abstract fun compute(): Int
    object Noop : Command() {
        override fun compute(): Int = 0
    }

    data class AddFirstCycle(val value: Int) : Command() {
        override fun compute(): Int = 0
    }

    data class AddSecondCycle(val value: Int) : Command() {
        override fun compute(): Int = value
    }
}

data class Row(val cyclePosition: Int, val currentRow: String, val registerX: Int) {
    fun handleCommand(command: Command): Row {
        val nextRow = drawPixel()
        val nextCyclePosition = cyclePosition + 1
        val nextRegisterX = registerX + command.compute()
        return Row(nextCyclePosition, nextRow, nextRegisterX)
    }

    fun drawPixel(): String {
        return if ((registerX - 1..registerX + 1).contains(cyclePosition)) currentRow.replaceRange(cyclePosition, cyclePosition+1, "#")
        else currentRow
    }
}

data class Row2(val cyclePosition: Int, val currentRow: String, val registerX: Int) {
    fun handleCommand(command: Command): Row {
        val nextRow = drawPixel()
        val nextCyclePosition = cyclePosition + 1
        val nextRegisterX = registerX + command.compute()
        return Row(nextCyclePosition, nextRow, nextRegisterX)
    }

    fun drawPixel(): String {
        return if ((registerX - 1..registerX + 1).contains(cyclePosition)) currentRow.replaceRange(cyclePosition, cyclePosition+1, "#")
        else currentRow
    }
}

fun main() {
    val testInput = Day10::class.java.getResourceAsStream("/day10_test.txt").bufferedReader().readLines()
    val input = Day10::class.java.getResourceAsStream("/day10_input.txt").bufferedReader().readLines()

    val day10test = Day10(testInput)
    val day10input = Day10(input)

    println("Day10 part 1 test result: ${day10test.part1()}")
    println("Day10 part 1 result: ${day10input.part1()}")
    println("Day10 part 2 test result: ${day10test.part2()}")
    println("Day10 part 2 result: ${day10input.part2()}")
}

Compiled from "Day10.kt"
public final class day10.Day10 {
  private final java.util.List<java.lang.String> input;

  private final java.util.List<day10.Command> commands;

  public day10.Day10(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #22                 // Field input:Ljava/util/List;
      15: aload_0
      16: aload_0
      17: aload_0
      18: getfield      #22                 // Field input:Ljava/util/List;
      21: invokespecial #26                 // Method parseCommands:(Ljava/util/List;)Ljava/util/List;
      24: putfield      #29                 // Field commands:Ljava/util/List;
      27: return

  private final java.util.List<day10.Command> parseCommands(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #34                 // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: astore        4
      10: new           #36                 // class java/util/ArrayList
      13: dup
      14: invokespecial #37                 // Method java/util/ArrayList."<init>":()V
      17: checkcast     #39                 // class java/util/Collection
      20: astore        5
      22: iconst_0
      23: istore        6
      25: aload         4
      27: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      32: astore        7
      34: aload         7
      36: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          85
      44: aload         7
      46: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: astore        8
      53: aload         8
      55: checkcast     #55                 // class java/lang/String
      58: astore        9
      60: iconst_0
      61: istore        10
      63: aload_0
      64: aload         9
      66: invokespecial #59                 // Method parseCommand:(Ljava/lang/String;)Ljava/util/List;
      69: checkcast     #34                 // class java/lang/Iterable
      72: astore        9
      74: aload         5
      76: aload         9
      78: invokestatic  #65                 // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
      81: pop
      82: goto          34
      85: aload         5
      87: checkcast     #67                 // class java/util/List
      90: nop
      91: areturn

  private final java.util.List<day10.Command> parseCommand(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #84                 // String noop
       3: invokestatic  #88                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       6: ifeq          16
       9: getstatic     #94                 // Field day10/Command$Noop.INSTANCE:Lday10/Command$Noop;
      12: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      15: areturn
      16: aload_1
      17: checkcast     #100                // class java/lang/CharSequence
      20: iconst_1
      21: anewarray     #55                 // class java/lang/String
      24: astore_3
      25: aload_3
      26: iconst_0
      27: ldc           #102                // String
      29: aastore
      30: aload_3
      31: iconst_0
      32: iconst_0
      33: bipush        6
      35: aconst_null
      36: invokestatic  #108                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      39: astore_2
      40: aload_2
      41: iconst_0
      42: invokeinterface #112,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      47: ldc           #114                // String addx
      49: invokestatic  #88                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      52: ifeq          111
      55: iconst_2
      56: anewarray     #116                // class day10/Command
      59: astore_3
      60: aload_3
      61: iconst_0
      62: new           #118                // class day10/Command$AddFirstCycle
      65: dup
      66: aload_2
      67: iconst_1
      68: invokeinterface #112,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      73: checkcast     #55                 // class java/lang/String
      76: invokestatic  #124                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      79: invokespecial #127                // Method day10/Command$AddFirstCycle."<init>":(I)V
      82: aastore
      83: aload_3
      84: iconst_1
      85: new           #129                // class day10/Command$AddSecondCycle
      88: dup
      89: aload_2
      90: iconst_1
      91: invokeinterface #112,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      96: checkcast     #55                 // class java/lang/String
      99: invokestatic  #124                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     102: invokespecial #130                // Method day10/Command$AddSecondCycle."<init>":(I)V
     105: aastore
     106: aload_3
     107: invokestatic  #133                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     110: areturn
     111: invokestatic  #137                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     114: areturn

  public final int part1();
    Code:
       0: aload_0
       1: getfield      #29                 // Field commands:Ljava/util/List;
       4: checkcast     #34                 // class java/lang/Iterable
       7: bipush        19
       9: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      12: checkcast     #34                 // class java/lang/Iterable
      15: astore_2
      16: iconst_1
      17: istore_3
      18: iconst_0
      19: istore        4
      21: iload_3
      22: istore        5
      24: aload_2
      25: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      30: astore        6
      32: aload         6
      34: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          78
      42: aload         6
      44: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        7
      51: iload         5
      53: aload         7
      55: checkcast     #116                // class day10/Command
      58: astore        8
      60: istore        9
      62: iconst_0
      63: istore        10
      65: iload         9
      67: aload         8
      69: invokevirtual #149                // Method day10/Command.compute:()I
      72: iadd
      73: istore        5
      75: goto          32
      78: iload         5
      80: bipush        20
      82: imul
      83: istore_1
      84: aload_0
      85: getfield      #29                 // Field commands:Ljava/util/List;
      88: checkcast     #34                 // class java/lang/Iterable
      91: bipush        59
      93: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      96: checkcast     #34                 // class java/lang/Iterable
      99: astore_3
     100: iconst_1
     101: istore        4
     103: iconst_0
     104: istore        5
     106: iload         4
     108: istore        6
     110: aload_3
     111: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        7
     118: aload         7
     120: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          164
     128: aload         7
     130: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: astore        8
     137: iload         6
     139: aload         8
     141: checkcast     #116                // class day10/Command
     144: astore        9
     146: istore        10
     148: iconst_0
     149: istore        11
     151: iload         10
     153: aload         9
     155: invokevirtual #149                // Method day10/Command.compute:()I
     158: iadd
     159: istore        6
     161: goto          118
     164: iload         6
     166: bipush        60
     168: imul
     169: istore_2
     170: aload_0
     171: getfield      #29                 // Field commands:Ljava/util/List;
     174: checkcast     #34                 // class java/lang/Iterable
     177: bipush        99
     179: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     182: checkcast     #34                 // class java/lang/Iterable
     185: astore        4
     187: iconst_1
     188: istore        5
     190: iconst_0
     191: istore        6
     193: iload         5
     195: istore        7
     197: aload         4
     199: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     204: astore        8
     206: aload         8
     208: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     213: ifeq          252
     216: aload         8
     218: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     223: astore        9
     225: iload         7
     227: aload         9
     229: checkcast     #116                // class day10/Command
     232: astore        10
     234: istore        11
     236: iconst_0
     237: istore        12
     239: iload         11
     241: aload         10
     243: invokevirtual #149                // Method day10/Command.compute:()I
     246: iadd
     247: istore        7
     249: goto          206
     252: iload         7
     254: bipush        100
     256: imul
     257: istore_3
     258: aload_0
     259: getfield      #29                 // Field commands:Ljava/util/List;
     262: checkcast     #34                 // class java/lang/Iterable
     265: sipush        139
     268: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     271: checkcast     #34                 // class java/lang/Iterable
     274: astore        5
     276: iconst_1
     277: istore        6
     279: iconst_0
     280: istore        7
     282: iload         6
     284: istore        8
     286: aload         5
     288: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     293: astore        9
     295: aload         9
     297: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     302: ifeq          341
     305: aload         9
     307: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     312: astore        10
     314: iload         8
     316: aload         10
     318: checkcast     #116                // class day10/Command
     321: astore        11
     323: istore        12
     325: iconst_0
     326: istore        13
     328: iload         12
     330: aload         11
     332: invokevirtual #149                // Method day10/Command.compute:()I
     335: iadd
     336: istore        8
     338: goto          295
     341: iload         8
     343: sipush        140
     346: imul
     347: istore        4
     349: aload_0
     350: getfield      #29                 // Field commands:Ljava/util/List;
     353: checkcast     #34                 // class java/lang/Iterable
     356: sipush        179
     359: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     362: checkcast     #34                 // class java/lang/Iterable
     365: astore        6
     367: iconst_1
     368: istore        7
     370: iconst_0
     371: istore        8
     373: iload         7
     375: istore        9
     377: aload         6
     379: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     384: astore        10
     386: aload         10
     388: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     393: ifeq          432
     396: aload         10
     398: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     403: astore        11
     405: iload         9
     407: aload         11
     409: checkcast     #116                // class day10/Command
     412: astore        12
     414: istore        13
     416: iconst_0
     417: istore        14
     419: iload         13
     421: aload         12
     423: invokevirtual #149                // Method day10/Command.compute:()I
     426: iadd
     427: istore        9
     429: goto          386
     432: iload         9
     434: sipush        180
     437: imul
     438: istore        5
     440: aload_0
     441: getfield      #29                 // Field commands:Ljava/util/List;
     444: checkcast     #34                 // class java/lang/Iterable
     447: sipush        219
     450: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     453: checkcast     #34                 // class java/lang/Iterable
     456: astore        7
     458: iconst_1
     459: istore        8
     461: iconst_0
     462: istore        9
     464: iconst_0
     465: istore        10
     467: iload         8
     469: istore        11
     471: aload         7
     473: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     478: astore        12
     480: aload         12
     482: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     487: ifeq          545
     490: aload         12
     492: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     497: astore        13
     499: iload         10
     501: iinc          10, 1
     504: istore        14
     506: iload         14
     508: ifge          514
     511: invokestatic  #152                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     514: iload         14
     516: iload         11
     518: aload         13
     520: checkcast     #116                // class day10/Command
     523: astore        15
     525: istore        16
     527: istore        17
     529: iconst_0
     530: istore        18
     532: iload         16
     534: aload         15
     536: invokevirtual #149                // Method day10/Command.compute:()I
     539: iadd
     540: istore        11
     542: goto          480
     545: iload         11
     547: sipush        220
     550: imul
     551: istore        6
     553: iload_1
     554: iload_2
     555: iadd
     556: iload_3
     557: iadd
     558: iload         4
     560: iadd
     561: iload         5
     563: iadd
     564: iload         6
     566: iadd
     567: ireturn

  public final java.lang.String part2();
    Code:
       0: iconst_0
       1: bipush        40
       3: invokestatic  #184                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       6: checkcast     #34                 // class java/lang/Iterable
       9: ldc           #186                // String
      11: checkcast     #100                // class java/lang/CharSequence
      14: aconst_null
      15: aconst_null
      16: iconst_0
      17: aconst_null
      18: invokedynamic #206,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      23: bipush        30
      25: aconst_null
      26: invokestatic  #210                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      29: astore_1
      30: new           #212                // class day10/Row
      33: dup
      34: iconst_0
      35: aload_1
      36: iconst_1
      37: invokespecial #215                // Method day10/Row."<init>":(ILjava/lang/String;I)V
      40: astore_2
      41: aload_0
      42: getfield      #29                 // Field commands:Ljava/util/List;
      45: checkcast     #34                 // class java/lang/Iterable
      48: bipush        40
      50: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      53: checkcast     #34                 // class java/lang/Iterable
      56: astore        4
      58: iconst_0
      59: istore        5
      61: aload_2
      62: astore        6
      64: aload         4
      66: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      71: astore        7
      73: aload         7
      75: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      80: ifeq          118
      83: aload         7
      85: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      90: astore        8
      92: aload         6
      94: aload         8
      96: checkcast     #116                // class day10/Command
      99: astore        9
     101: astore        10
     103: iconst_0
     104: istore        11
     106: aload         10
     108: aload         9
     110: invokevirtual #219                // Method day10/Row.handleCommand:(Lday10/Command;)Lday10/Row;
     113: astore        6
     115: goto          73
     118: aload         6
     120: astore_3
     121: new           #212                // class day10/Row
     124: dup
     125: iconst_0
     126: aload_1
     127: aload_3
     128: invokevirtual #222                // Method day10/Row.getRegisterX:()I
     131: invokespecial #215                // Method day10/Row."<init>":(ILjava/lang/String;I)V
     134: astore        4
     136: aload_0
     137: getfield      #29                 // Field commands:Ljava/util/List;
     140: checkcast     #34                 // class java/lang/Iterable
     143: bipush        40
     145: invokestatic  #225                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     148: checkcast     #34                 // class java/lang/Iterable
     151: bipush        40
     153: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     156: checkcast     #34                 // class java/lang/Iterable
     159: astore        6
     161: iconst_0
     162: istore        7
     164: aload         4
     166: astore        8
     168: aload         6
     170: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     175: astore        9
     177: aload         9
     179: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     184: ifeq          222
     187: aload         9
     189: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     194: astore        10
     196: aload         8
     198: aload         10
     200: checkcast     #116                // class day10/Command
     203: astore        11
     205: astore        12
     207: iconst_0
     208: istore        13
     210: aload         12
     212: aload         11
     214: invokevirtual #219                // Method day10/Row.handleCommand:(Lday10/Command;)Lday10/Row;
     217: astore        8
     219: goto          177
     222: aload         8
     224: astore        5
     226: new           #212                // class day10/Row
     229: dup
     230: iconst_0
     231: aload_1
     232: aload         5
     234: invokevirtual #222                // Method day10/Row.getRegisterX:()I
     237: invokespecial #215                // Method day10/Row."<init>":(ILjava/lang/String;I)V
     240: astore        6
     242: aload_0
     243: getfield      #29                 // Field commands:Ljava/util/List;
     246: checkcast     #34                 // class java/lang/Iterable
     249: bipush        80
     251: invokestatic  #225                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     254: checkcast     #34                 // class java/lang/Iterable
     257: bipush        40
     259: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     262: checkcast     #34                 // class java/lang/Iterable
     265: astore        8
     267: iconst_0
     268: istore        9
     270: aload         6
     272: astore        10
     274: aload         8
     276: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     281: astore        11
     283: aload         11
     285: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     290: ifeq          328
     293: aload         11
     295: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     300: astore        12
     302: aload         10
     304: aload         12
     306: checkcast     #116                // class day10/Command
     309: astore        13
     311: astore        14
     313: iconst_0
     314: istore        15
     316: aload         14
     318: aload         13
     320: invokevirtual #219                // Method day10/Row.handleCommand:(Lday10/Command;)Lday10/Row;
     323: astore        10
     325: goto          283
     328: aload         10
     330: astore        7
     332: new           #212                // class day10/Row
     335: dup
     336: iconst_0
     337: aload_1
     338: aload         7
     340: invokevirtual #222                // Method day10/Row.getRegisterX:()I
     343: invokespecial #215                // Method day10/Row."<init>":(ILjava/lang/String;I)V
     346: astore        8
     348: aload_0
     349: getfield      #29                 // Field commands:Ljava/util/List;
     352: checkcast     #34                 // class java/lang/Iterable
     355: bipush        120
     357: invokestatic  #225                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     360: checkcast     #34                 // class java/lang/Iterable
     363: bipush        40
     365: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     368: checkcast     #34                 // class java/lang/Iterable
     371: astore        10
     373: iconst_0
     374: istore        11
     376: aload         8
     378: astore        12
     380: aload         10
     382: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     387: astore        13
     389: aload         13
     391: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     396: ifeq          434
     399: aload         13
     401: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     406: astore        14
     408: aload         12
     410: aload         14
     412: checkcast     #116                // class day10/Command
     415: astore        15
     417: astore        16
     419: iconst_0
     420: istore        17
     422: aload         16
     424: aload         15
     426: invokevirtual #219                // Method day10/Row.handleCommand:(Lday10/Command;)Lday10/Row;
     429: astore        12
     431: goto          389
     434: aload         12
     436: astore        9
     438: new           #212                // class day10/Row
     441: dup
     442: iconst_0
     443: aload_1
     444: aload         9
     446: invokevirtual #222                // Method day10/Row.getRegisterX:()I
     449: invokespecial #215                // Method day10/Row."<init>":(ILjava/lang/String;I)V
     452: astore        10
     454: aload_0
     455: getfield      #29                 // Field commands:Ljava/util/List;
     458: checkcast     #34                 // class java/lang/Iterable
     461: sipush        160
     464: invokestatic  #225                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     467: checkcast     #34                 // class java/lang/Iterable
     470: bipush        40
     472: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     475: checkcast     #34                 // class java/lang/Iterable
     478: astore        12
     480: iconst_0
     481: istore        13
     483: aload         10
     485: astore        14
     487: aload         12
     489: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     494: astore        15
     496: aload         15
     498: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     503: ifeq          541
     506: aload         15
     508: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     513: astore        16
     515: aload         14
     517: aload         16
     519: checkcast     #116                // class day10/Command
     522: astore        17
     524: astore        18
     526: iconst_0
     527: istore        19
     529: aload         18
     531: aload         17
     533: invokevirtual #219                // Method day10/Row.handleCommand:(Lday10/Command;)Lday10/Row;
     536: astore        14
     538: goto          496
     541: aload         14
     543: astore        11
     545: new           #212                // class day10/Row
     548: dup
     549: iconst_0
     550: aload_1
     551: aload         11
     553: invokevirtual #222                // Method day10/Row.getRegisterX:()I
     556: invokespecial #215                // Method day10/Row."<init>":(ILjava/lang/String;I)V
     559: astore        12
     561: aload_0
     562: getfield      #29                 // Field commands:Ljava/util/List;
     565: checkcast     #34                 // class java/lang/Iterable
     568: sipush        200
     571: invokestatic  #225                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     574: checkcast     #34                 // class java/lang/Iterable
     577: bipush        40
     579: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     582: checkcast     #34                 // class java/lang/Iterable
     585: astore        14
     587: iconst_0
     588: istore        15
     590: aload         12
     592: astore        16
     594: aload         14
     596: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     601: astore        17
     603: aload         17
     605: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     610: ifeq          648
     613: aload         17
     615: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     620: astore        18
     622: aload         16
     624: aload         18
     626: checkcast     #116                // class day10/Command
     629: astore        19
     631: astore        20
     633: iconst_0
     634: istore        21
     636: aload         20
     638: aload         19
     640: invokevirtual #219                // Method day10/Row.handleCommand:(Lday10/Command;)Lday10/Row;
     643: astore        16
     645: goto          603
     648: aload         16
     650: astore        13
     652: new           #227                // class java/lang/StringBuilder
     655: dup
     656: invokespecial #228                // Method java/lang/StringBuilder."<init>":()V
     659: bipush        10
     661: invokevirtual #232                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     664: aload_3
     665: invokevirtual #235                // Method day10/Row.getCurrentRow:()Ljava/lang/String;
     668: invokevirtual #238                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     671: bipush        10
     673: invokevirtual #232                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     676: aload         5
     678: invokevirtual #235                // Method day10/Row.getCurrentRow:()Ljava/lang/String;
     681: invokevirtual #238                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     684: bipush        10
     686: invokevirtual #232                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     689: aload         7
     691: invokevirtual #235                // Method day10/Row.getCurrentRow:()Ljava/lang/String;
     694: invokevirtual #238                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     697: bipush        10
     699: invokevirtual #232                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     702: aload         9
     704: invokevirtual #235                // Method day10/Row.getCurrentRow:()Ljava/lang/String;
     707: invokevirtual #238                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     710: bipush        10
     712: invokevirtual #232                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     715: aload         11
     717: invokevirtual #235                // Method day10/Row.getCurrentRow:()Ljava/lang/String;
     720: invokevirtual #238                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     723: bipush        10
     725: invokevirtual #232                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     728: aload         13
     730: invokevirtual #235                // Method day10/Row.getCurrentRow:()Ljava/lang/String;
     733: invokevirtual #238                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     736: bipush        10
     738: invokevirtual #232                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     741: invokevirtual #241                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     744: areturn

  private static final java.lang.CharSequence part2$lambda$7(int);
    Code:
       0: ldc_w         #264                // String .
       3: checkcast     #100                // class java/lang/CharSequence
       6: areturn
}

Compiled from "Day10.kt"
public final class day10.Day10Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // class day10/Day10
       2: ldc           #10                 // String /day10_test.txt
       4: invokevirtual #16                 // Method java/lang/Class.getResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
       7: dup
       8: ldc           #18                 // String getResourceAsStream(...)
      10: invokestatic  #24                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      13: astore_1
      14: getstatic     #30                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      17: astore_2
      18: new           #32                 // class java/io/InputStreamReader
      21: dup
      22: aload_1
      23: aload_2
      24: invokespecial #36                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      27: checkcast     #38                 // class java/io/Reader
      30: astore_3
      31: sipush        8192
      34: istore        4
      36: aload_3
      37: instanceof    #40                 // class java/io/BufferedReader
      40: ifeq          50
      43: aload_3
      44: checkcast     #40                 // class java/io/BufferedReader
      47: goto          60
      50: new           #40                 // class java/io/BufferedReader
      53: dup
      54: aload_3
      55: iload         4
      57: invokespecial #43                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      60: checkcast     #38                 // class java/io/Reader
      63: invokestatic  #49                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      66: astore_0
      67: ldc           #8                  // class day10/Day10
      69: ldc           #51                 // String /day10_input.txt
      71: invokevirtual #16                 // Method java/lang/Class.getResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
      74: dup
      75: ldc           #18                 // String getResourceAsStream(...)
      77: invokestatic  #24                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      80: astore_2
      81: getstatic     #30                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      84: astore_3
      85: new           #32                 // class java/io/InputStreamReader
      88: dup
      89: aload_2
      90: aload_3
      91: invokespecial #36                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      94: checkcast     #38                 // class java/io/Reader
      97: astore        4
      99: sipush        8192
     102: istore        5
     104: aload         4
     106: instanceof    #40                 // class java/io/BufferedReader
     109: ifeq          120
     112: aload         4
     114: checkcast     #40                 // class java/io/BufferedReader
     117: goto          131
     120: new           #40                 // class java/io/BufferedReader
     123: dup
     124: aload         4
     126: iload         5
     128: invokespecial #43                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
     131: checkcast     #38                 // class java/io/Reader
     134: invokestatic  #49                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
     137: astore_1
     138: new           #8                  // class day10/Day10
     141: dup
     142: aload_0
     143: invokespecial #54                 // Method day10/Day10."<init>":(Ljava/util/List;)V
     146: astore_2
     147: new           #8                  // class day10/Day10
     150: dup
     151: aload_1
     152: invokespecial #54                 // Method day10/Day10."<init>":(Ljava/util/List;)V
     155: astore_3
     156: new           #56                 // class java/lang/StringBuilder
     159: dup
     160: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
     163: ldc           #60                 // String Day10 part 1 test result:
     165: invokevirtual #64                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     168: aload_2
     169: invokevirtual #68                 // Method day10/Day10.part1:()I
     172: invokevirtual #71                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     175: invokevirtual #75                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     178: getstatic     #81                 // Field java/lang/System.out:Ljava/io/PrintStream;
     181: swap
     182: invokevirtual #87                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     185: new           #56                 // class java/lang/StringBuilder
     188: dup
     189: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
     192: ldc           #89                 // String Day10 part 1 result:
     194: invokevirtual #64                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     197: aload_3
     198: invokevirtual #68                 // Method day10/Day10.part1:()I
     201: invokevirtual #71                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     204: invokevirtual #75                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     207: getstatic     #81                 // Field java/lang/System.out:Ljava/io/PrintStream;
     210: swap
     211: invokevirtual #87                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     214: new           #56                 // class java/lang/StringBuilder
     217: dup
     218: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
     221: ldc           #91                 // String Day10 part 2 test result:
     223: invokevirtual #64                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     226: aload_2
     227: invokevirtual #94                 // Method day10/Day10.part2:()Ljava/lang/String;
     230: invokevirtual #64                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     233: invokevirtual #75                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     236: getstatic     #81                 // Field java/lang/System.out:Ljava/io/PrintStream;
     239: swap
     240: invokevirtual #87                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     243: new           #56                 // class java/lang/StringBuilder
     246: dup
     247: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
     250: ldc           #96                 // String Day10 part 2 result:
     252: invokevirtual #64                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     255: aload_3
     256: invokevirtual #94                 // Method day10/Day10.part2:()Ljava/lang/String;
     259: invokevirtual #64                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     262: invokevirtual #75                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     265: getstatic     #81                 // Field java/lang/System.out:Ljava/io/PrintStream;
     268: swap
     269: invokevirtual #87                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     272: return

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


package day2

import java.io.File

val values = mapOf("A" to 1, "B" to 2, "C" to 3)
val values2 = mapOf("X" to 1, "Y" to 2, "Z" to 3)
val winValues = mapOf("X" to "C", "Y" to "A", "Z" to "B")
val lossValues = mapOf("X" to "B", "Y" to "C", "Z" to "A")
val drawValues = mapOf("X" to "A", "Y" to "B", "Z" to "C")
var totalScore = 0

fun main() {
    task2()
    println(totalScore)
}

fun task1() {
    loadFile().useLines {
        it.iterator().forEachRemaining { line ->
            val hand = line.split(" ")
            if (hand[0] == drawValues[hand[1]]) {
                totalScore += 3
            }
            else if(hand[0] == winValues[hand[1]]) {
                totalScore += 6
            }
            totalScore += values[drawValues[hand[1]]]!!.toInt()
        }
    }
}

fun task2() {
    loadFile().useLines {
        it.iterator().forEachRemaining { line ->
            val hand = line.split(" ")
            when(hand[1]) {
                "Y" -> totalScore += 3 + values2[invertMap(drawValues)[hand[0]]!!]!!.toInt()
                "Z" -> totalScore += 6 + values2[invertMap(winValues)[hand[0]]!!]!!.toInt()
                else -> totalScore += values2[invertMap(lossValues)[hand[0]]!!]!!.toInt()
            }
        }
    }
}

private fun loadFile(): File {
    return File("C:\\dev\\Advent_of_code_2022\\src\\main\\kotlin\\day2\\input.txt")
}

private fun invertMap(ogMap: Map<String, String>): Map<String, String> = ogMap.entries.associateBy({ it.value }) { it.key }

Compiled from "Day2.kt"
public final class day2.Day2Kt {
  private static final java.util.Map<java.lang.String, java.lang.Integer> values;

  private static final java.util.Map<java.lang.String, java.lang.Integer> values2;

  private static final java.util.Map<java.lang.String, java.lang.String> winValues;

  private static final java.util.Map<java.lang.String, java.lang.String> lossValues;

  private static final java.util.Map<java.lang.String, java.lang.String> drawValues;

  private static int totalScore;

  public static final java.util.Map<java.lang.String, java.lang.Integer> getValues();
    Code:
       0: getstatic     #12                 // Field values:Ljava/util/Map;
       3: areturn

  public static final java.util.Map<java.lang.String, java.lang.Integer> getValues2();
    Code:
       0: getstatic     #16                 // Field values2:Ljava/util/Map;
       3: areturn

  public static final java.util.Map<java.lang.String, java.lang.String> getWinValues();
    Code:
       0: getstatic     #21                 // Field winValues:Ljava/util/Map;
       3: areturn

  public static final java.util.Map<java.lang.String, java.lang.String> getLossValues();
    Code:
       0: getstatic     #25                 // Field lossValues:Ljava/util/Map;
       3: areturn

  public static final java.util.Map<java.lang.String, java.lang.String> getDrawValues();
    Code:
       0: getstatic     #29                 // Field drawValues:Ljava/util/Map;
       3: areturn

  public static final int getTotalScore();
    Code:
       0: getstatic     #35                 // Field totalScore:I
       3: ireturn

  public static final void setTotalScore(int);
    Code:
       0: iload_0
       1: putstatic     #35                 // Field totalScore:I
       4: return

  public static final void main();
    Code:
       0: invokestatic  #43                 // Method task2:()V
       3: getstatic     #35                 // Field totalScore:I
       6: istore_0
       7: getstatic     #49                 // Field java/lang/System.out:Ljava/io/PrintStream;
      10: iload_0
      11: invokevirtual #54                 // Method java/io/PrintStream.println:(I)V
      14: return

  public static final void task1();
    Code:
       0: invokestatic  #61                 // Method loadFile:()Ljava/io/File;
       3: astore_0
       4: getstatic     #67                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_0
      11: astore_3
      12: sipush        8192
      15: istore        4
      17: aload_3
      18: astore        5
      20: new           #69                 // class java/io/InputStreamReader
      23: dup
      24: new           #71                 // class java/io/FileInputStream
      27: dup
      28: aload         5
      30: invokespecial #75                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      33: checkcast     #77                 // class java/io/InputStream
      36: aload_1
      37: invokespecial #80                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      40: checkcast     #82                 // class java/io/Reader
      43: astore        5
      45: aload         5
      47: instanceof    #84                 // class java/io/BufferedReader
      50: ifeq          61
      53: aload         5
      55: checkcast     #84                 // class java/io/BufferedReader
      58: goto          72
      61: new           #84                 // class java/io/BufferedReader
      64: dup
      65: aload         5
      67: iload         4
      69: invokespecial #87                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      72: checkcast     #89                 // class java/io/Closeable
      75: astore_3
      76: aconst_null
      77: astore        4
      79: nop
      80: aload_3
      81: checkcast     #84                 // class java/io/BufferedReader
      84: astore        5
      86: iconst_0
      87: istore        6
      89: aload         5
      91: invokestatic  #95                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
      94: astore        7
      96: iconst_0
      97: istore        8
      99: aload         7
     101: invokeinterface #101,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     106: invokedynamic #120,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     111: invokedynamic #131,  0            // InvokeDynamic #1:accept:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/Consumer;
     116: invokeinterface #137,  2          // InterfaceMethod java/util/Iterator.forEachRemaining:(Ljava/util/function/Consumer;)V
     121: nop
     122: getstatic     #143                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     125: astore        5
     127: aload_3
     128: aload         4
     130: invokestatic  #149                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     133: goto          156
     136: astore        6
     138: aload         6
     140: astore        4
     142: aload         6
     144: athrow
     145: astore        6
     147: aload_3
     148: aload         4
     150: invokestatic  #149                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     153: aload         6
     155: athrow
     156: nop
     157: return
    Exception table:
       from    to  target type
          79   127   136   Class java/lang/Throwable
          79   127   145   any
         136   145   145   any
         145   147   145   any

  public static final void task2();
    Code:
       0: invokestatic  #61                 // Method loadFile:()Ljava/io/File;
       3: astore_0
       4: getstatic     #67                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_0
      11: astore_3
      12: sipush        8192
      15: istore        4
      17: aload_3
      18: astore        5
      20: new           #69                 // class java/io/InputStreamReader
      23: dup
      24: new           #71                 // class java/io/FileInputStream
      27: dup
      28: aload         5
      30: invokespecial #75                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      33: checkcast     #77                 // class java/io/InputStream
      36: aload_1
      37: invokespecial #80                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      40: checkcast     #82                 // class java/io/Reader
      43: astore        5
      45: aload         5
      47: instanceof    #84                 // class java/io/BufferedReader
      50: ifeq          61
      53: aload         5
      55: checkcast     #84                 // class java/io/BufferedReader
      58: goto          72
      61: new           #84                 // class java/io/BufferedReader
      64: dup
      65: aload         5
      67: iload         4
      69: invokespecial #87                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      72: checkcast     #89                 // class java/io/Closeable
      75: astore_3
      76: aconst_null
      77: astore        4
      79: nop
      80: aload_3
      81: checkcast     #84                 // class java/io/BufferedReader
      84: astore        5
      86: iconst_0
      87: istore        6
      89: aload         5
      91: invokestatic  #95                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
      94: astore        7
      96: iconst_0
      97: istore        8
      99: aload         7
     101: invokeinterface #101,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     106: invokedynamic #168,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
     111: invokedynamic #173,  0            // InvokeDynamic #3:accept:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/Consumer;
     116: invokeinterface #137,  2          // InterfaceMethod java/util/Iterator.forEachRemaining:(Ljava/util/function/Consumer;)V
     121: nop
     122: getstatic     #143                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     125: astore        5
     127: aload_3
     128: aload         4
     130: invokestatic  #149                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     133: goto          156
     136: astore        6
     138: aload         6
     140: astore        4
     142: aload         6
     144: athrow
     145: astore        6
     147: aload_3
     148: aload         4
     150: invokestatic  #149                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     153: aload         6
     155: athrow
     156: nop
     157: return
    Exception table:
       from    to  target type
          79   127   136   Class java/lang/Throwable
          79   127   145   any
         136   145   145   any
         145   147   145   any

  private static final java.io.File loadFile();
    Code:
       0: new           #161                // class java/io/File
       3: dup
       4: ldc           #176                // String C:\\dev\\Advent_of_code_2022\\src\\main\\kotlin\\day2\\input.txt
       6: invokespecial #179                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: areturn

  private static final java.util.Map<java.lang.String, java.lang.String> invertMap(java.util.Map<java.lang.String, java.lang.String>);
    Code:
       0: aload_0
       1: invokeinterface #188,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
       6: checkcast     #190                // class java/lang/Iterable
       9: astore_1
      10: iconst_0
      11: istore_2
      12: aload_1
      13: bipush        10
      15: invokestatic  #196                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      18: invokestatic  #202                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      21: bipush        16
      23: invokestatic  #208                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      26: istore_3
      27: aload_1
      28: astore        4
      30: new           #210                // class java/util/LinkedHashMap
      33: dup
      34: iload_3
      35: invokespecial #212                // Method java/util/LinkedHashMap."<init>":(I)V
      38: checkcast     #184                // class java/util/Map
      41: astore        5
      43: iconst_0
      44: istore        6
      46: aload         4
      48: invokeinterface #213,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        7
      55: aload         7
      57: invokeinterface #217,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          142
      65: aload         7
      67: invokeinterface #221,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: astore        8
      74: aload         5
      76: aload         8
      78: checkcast     #223                // class java/util/Map$Entry
      81: astore        9
      83: astore        11
      85: iconst_0
      86: istore        10
      88: aload         9
      90: invokeinterface #226,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      95: checkcast     #228                // class java/lang/String
      98: aload         11
     100: swap
     101: aload         8
     103: checkcast     #223                // class java/util/Map$Entry
     106: astore        9
     108: astore        12
     110: astore        11
     112: iconst_0
     113: istore        10
     115: aload         9
     117: invokeinterface #231,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     122: checkcast     #228                // class java/lang/String
     125: astore        13
     127: aload         11
     129: aload         12
     131: aload         13
     133: invokeinterface #235,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     138: pop
     139: goto          55
     142: aload         5
     144: nop
     145: areturn

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

  private static final kotlin.Unit task1$lambda$2$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #255                // String line
       3: invokestatic  #261                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #263                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #228                // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc_w         #265                // String
      20: aastore
      21: aload_2
      22: iconst_0
      23: iconst_0
      24: bipush        6
      26: aconst_null
      27: invokestatic  #271                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      30: astore_1
      31: aload_1
      32: iconst_0
      33: invokeinterface #277,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      38: getstatic     #29                 // Field drawValues:Ljava/util/Map;
      41: aload_1
      42: iconst_1
      43: invokeinterface #277,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      48: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      53: invokestatic  #283                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      56: ifeq          70
      59: getstatic     #35                 // Field totalScore:I
      62: iconst_3
      63: iadd
      64: putstatic     #35                 // Field totalScore:I
      67: goto          107
      70: aload_1
      71: iconst_0
      72: invokeinterface #277,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      77: getstatic     #21                 // Field winValues:Ljava/util/Map;
      80: aload_1
      81: iconst_1
      82: invokeinterface #277,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      87: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      92: invokestatic  #283                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      95: ifeq          107
      98: getstatic     #35                 // Field totalScore:I
     101: bipush        6
     103: iadd
     104: putstatic     #35                 // Field totalScore:I
     107: getstatic     #35                 // Field totalScore:I
     110: getstatic     #12                 // Field values:Ljava/util/Map;
     113: getstatic     #29                 // Field drawValues:Ljava/util/Map;
     116: aload_1
     117: iconst_1
     118: invokeinterface #277,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     123: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     128: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     133: dup
     134: invokestatic  #286                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     137: checkcast     #288                // class java/lang/Number
     140: invokevirtual #291                // Method java/lang/Number.intValue:()I
     143: iadd
     144: putstatic     #35                 // Field totalScore:I
     147: getstatic     #143                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     150: areturn

  private static final void task1$lambda$2$lambda$1(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #299,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: pop
       8: return

  private static final kotlin.Unit task2$lambda$5$lambda$3(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #255                // String line
       3: invokestatic  #261                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #263                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #228                // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc_w         #265                // String
      20: aastore
      21: aload_2
      22: iconst_0
      23: iconst_0
      24: bipush        6
      26: aconst_null
      27: invokestatic  #271                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      30: astore_1
      31: aload_1
      32: iconst_1
      33: invokeinterface #277,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      38: checkcast     #228                // class java/lang/String
      41: astore_2
      42: aload_2
      43: ldc_w         #304                // String Y
      46: invokestatic  #283                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      49: ifeq          104
      52: getstatic     #35                 // Field totalScore:I
      55: iconst_3
      56: getstatic     #16                 // Field values2:Ljava/util/Map;
      59: getstatic     #29                 // Field drawValues:Ljava/util/Map;
      62: invokestatic  #306                // Method invertMap:(Ljava/util/Map;)Ljava/util/Map;
      65: aload_1
      66: iconst_0
      67: invokeinterface #277,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      72: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      77: dup
      78: invokestatic  #286                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      81: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      86: dup
      87: invokestatic  #286                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      90: checkcast     #288                // class java/lang/Number
      93: invokevirtual #291                // Method java/lang/Number.intValue:()I
      96: iadd
      97: iadd
      98: putstatic     #35                 // Field totalScore:I
     101: goto          214
     104: aload_2
     105: ldc_w         #308                // String Z
     108: invokestatic  #283                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     111: ifeq          167
     114: getstatic     #35                 // Field totalScore:I
     117: bipush        6
     119: getstatic     #16                 // Field values2:Ljava/util/Map;
     122: getstatic     #21                 // Field winValues:Ljava/util/Map;
     125: invokestatic  #306                // Method invertMap:(Ljava/util/Map;)Ljava/util/Map;
     128: aload_1
     129: iconst_0
     130: invokeinterface #277,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     135: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     140: dup
     141: invokestatic  #286                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     144: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     149: dup
     150: invokestatic  #286                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     153: checkcast     #288                // class java/lang/Number
     156: invokevirtual #291                // Method java/lang/Number.intValue:()I
     159: iadd
     160: iadd
     161: putstatic     #35                 // Field totalScore:I
     164: goto          214
     167: getstatic     #35                 // Field totalScore:I
     170: getstatic     #16                 // Field values2:Ljava/util/Map;
     173: getstatic     #25                 // Field lossValues:Ljava/util/Map;
     176: invokestatic  #306                // Method invertMap:(Ljava/util/Map;)Ljava/util/Map;
     179: aload_1
     180: iconst_0
     181: invokeinterface #277,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     191: dup
     192: invokestatic  #286                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     195: invokeinterface #279,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     200: dup
     201: invokestatic  #286                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     204: checkcast     #288                // class java/lang/Number
     207: invokevirtual #291                // Method java/lang/Number.intValue:()I
     210: iadd
     211: putstatic     #35                 // Field totalScore:I
     214: getstatic     #143                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     217: areturn

  private static final void task2$lambda$5$lambda$4(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #299,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: pop
       8: return

  static {};
    Code:
       0: iconst_3
       1: anewarray     #311                // class kotlin/Pair
       4: astore_0
       5: aload_0
       6: iconst_0
       7: ldc_w         #313                // String A
      10: iconst_1
      11: invokestatic  #319                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      14: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      17: aastore
      18: aload_0
      19: iconst_1
      20: ldc_w         #327                // String B
      23: iconst_2
      24: invokestatic  #319                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      27: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      30: aastore
      31: aload_0
      32: iconst_2
      33: ldc_w         #329                // String C
      36: iconst_3
      37: invokestatic  #319                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      43: aastore
      44: aload_0
      45: invokestatic  #333                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      48: putstatic     #12                 // Field values:Ljava/util/Map;
      51: iconst_3
      52: anewarray     #311                // class kotlin/Pair
      55: astore_0
      56: aload_0
      57: iconst_0
      58: ldc_w         #335                // String X
      61: iconst_1
      62: invokestatic  #319                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      68: aastore
      69: aload_0
      70: iconst_1
      71: ldc_w         #304                // String Y
      74: iconst_2
      75: invokestatic  #319                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      81: aastore
      82: aload_0
      83: iconst_2
      84: ldc_w         #308                // String Z
      87: iconst_3
      88: invokestatic  #319                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      94: aastore
      95: aload_0
      96: invokestatic  #333                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      99: putstatic     #16                 // Field values2:Ljava/util/Map;
     102: iconst_3
     103: anewarray     #311                // class kotlin/Pair
     106: astore_0
     107: aload_0
     108: iconst_0
     109: ldc_w         #335                // String X
     112: ldc_w         #329                // String C
     115: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     118: aastore
     119: aload_0
     120: iconst_1
     121: ldc_w         #304                // String Y
     124: ldc_w         #313                // String A
     127: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     130: aastore
     131: aload_0
     132: iconst_2
     133: ldc_w         #308                // String Z
     136: ldc_w         #327                // String B
     139: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     142: aastore
     143: aload_0
     144: invokestatic  #333                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     147: putstatic     #21                 // Field winValues:Ljava/util/Map;
     150: iconst_3
     151: anewarray     #311                // class kotlin/Pair
     154: astore_0
     155: aload_0
     156: iconst_0
     157: ldc_w         #335                // String X
     160: ldc_w         #327                // String B
     163: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     166: aastore
     167: aload_0
     168: iconst_1
     169: ldc_w         #304                // String Y
     172: ldc_w         #329                // String C
     175: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     178: aastore
     179: aload_0
     180: iconst_2
     181: ldc_w         #308                // String Z
     184: ldc_w         #313                // String A
     187: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     190: aastore
     191: aload_0
     192: invokestatic  #333                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     195: putstatic     #25                 // Field lossValues:Ljava/util/Map;
     198: iconst_3
     199: anewarray     #311                // class kotlin/Pair
     202: astore_0
     203: aload_0
     204: iconst_0
     205: ldc_w         #335                // String X
     208: ldc_w         #313                // String A
     211: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     214: aastore
     215: aload_0
     216: iconst_1
     217: ldc_w         #304                // String Y
     220: ldc_w         #327                // String B
     223: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     226: aastore
     227: aload_0
     228: iconst_2
     229: ldc_w         #308                // String Z
     232: ldc_w         #329                // String C
     235: invokestatic  #325                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     238: aastore
     239: aload_0
     240: invokestatic  #333                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     243: putstatic     #29                 // Field drawValues:Ljava/util/Map;
     246: return
}


package dev.kosmx.needle.util

/**
 * O(n+m) pattern matching with Knuth-Morris-Pratt algo
 *
 * @param T has to be comparable (== or .equals has to work as data-classes)
 */
class Word<T>(val word: Array<T>, private val comparator: (T, T) -> Boolean = { a, b -> a == b }) {
    init {
        require(word.isNotEmpty()) { "Matcher can't match empty word" }
    }
    private val pattern = Pattern()

    fun matcher() = Matcher(pattern)

    inner class Matcher internal constructor (private val pattern: Pattern) {
        val word: Array<T>
            get() = this@Word.word

        private var pos = -1

        /**
         * Matcher check next entry
         * @return true if full match present
         */
        fun checkNextChar(char: T): Boolean {
            pos++
            findLoop@ while (pos >= 0) {
                if (comparator(char, word[pos]) ) {
                    break@findLoop
                } else {
                    pos = pattern.table[pos]
                }
            }
            if (pos + 1 == word.size) {
                pos = pattern.table[pos + 1]
                return true
            }
            return false
        }
    }

    inner class Pattern internal constructor() {
        internal val table: IntArray = IntArray(word.size + 1)

        //https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm#Description_of_pseudocode_for_the_table-building_algorithm
        init {
            table[0] = -1
            var cnd = 0
            for (i in word.indices.drop(1)) {
                if (comparator(word[i], word[cnd])) {
                    table[i] = table[cnd]
                } else {
                    table[i] = cnd
                    while (cnd >= 0 && !comparator(word[cnd], word[i])) {
                        cnd = table[cnd]
                    }
                }
                cnd++
            }
            table[word.size] = cnd
        }
    }
}

fun <T> Word<T>.match(iterable: Iterable<T>) = match(iterable.asSequence())

fun <T> Word<T>.match(sequence: Sequence<T>): Int = match(sequence.iterator())

fun <T> Word<T>.match(sequence: Iterator<T>): Int {
    val m = matcher()
    var pos = 0
    sequence.forEach {
        if (m.checkNextChar(it)) {
            return@match pos - word.size + 1
        }
        pos++
    }
    return -1
}

Compiled from "KMP.kt"
public final class dev.kosmx.needle.util.KMPKt {
  public static final <T> int match(dev.kosmx.needle.util.Word<T>, java.lang.Iterable<? extends T>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String iterable
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      17: invokestatic  #27                 // Method match:(Ldev/kosmx/needle/util/Word;Lkotlin/sequences/Sequence;)I
      20: ireturn

  public static final <T> int match(dev.kosmx.needle.util.Word<T>, kotlin.sequences.Sequence<? extends T>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #33                 // String sequence
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokeinterface #39,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      19: invokestatic  #42                 // Method match:(Ldev/kosmx/needle/util/Word;Ljava/util/Iterator;)I
      22: ireturn

  public static final <T> int match(dev.kosmx.needle.util.Word<T>, java.util.Iterator<? extends T>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #33                 // String sequence
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #50                 // Method dev/kosmx/needle/util/Word.matcher:()Ldev/kosmx/needle/util/Word$Matcher;
      16: astore_2
      17: iconst_0
      18: istore_3
      19: aload_1
      20: astore        4
      22: iconst_0
      23: istore        5
      25: aload         4
      27: astore        6
      29: aload         6
      31: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          83
      39: aload         6
      41: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        7
      48: aload         7
      50: astore        8
      52: iconst_0
      53: istore        9
      55: aload_2
      56: aload         8
      58: invokevirtual #66                 // Method dev/kosmx/needle/util/Word$Matcher.checkNextChar:(Ljava/lang/Object;)Z
      61: ifeq          74
      64: iload_3
      65: aload_0
      66: invokevirtual #70                 // Method dev/kosmx/needle/util/Word.getWord:()[Ljava/lang/Object;
      69: arraylength
      70: isub
      71: iconst_1
      72: iadd
      73: ireturn
      74: iload_3
      75: iconst_1
      76: iadd
      77: istore_3
      78: nop
      79: nop
      80: goto          29
      83: nop
      84: iconst_m1
      85: ireturn
}