package day11

import java.io.File
import java.lang.Exception

data class Monkey(
    val id: Int,
    val items: List<Long>,
    val operation: (Long) -> Long,
    val nextMonkey: (Long) -> Int,
    val monkeyActivity: Int = 0
) {

    fun doATurn(monkeys: List<Monkey>, reduceLevel: Int = 1, verbose: Boolean = false): List<Monkey> {
        if (items.isEmpty()) return monkeys
        val updatedMonkeys = items.fold(monkeys) { acc, item ->
            if (verbose) println("Monkey $id inspects an item with a worry level of $item.")
            val newLevel = operation(item)
            if (verbose) println("\tWorry level is now $newLevel.")
            val dividedLevel = newLevel/reduceLevel.toLong()
            if (verbose) println("\tMonkey gets bored with item. Worry level is divided by 3 to $dividedLevel.")
            val receiverMonkeyId = nextMonkey(dividedLevel)
            if (verbose) println("\tItem with worry level $dividedLevel is thrown to monkey $receiverMonkeyId.")
            val receiverMonkey = acc.first { it.id == receiverMonkeyId }

            acc.filter { it.id != receiverMonkeyId } + receiverMonkey.copy(
                items = receiverMonkey.items + dividedLevel
            )
        }
        return updatedMonkeys.filter { it.id != id } +
                this.copy(items = emptyList(), monkeyActivity = monkeyActivity + items.size)
    }

}

fun parseNextMonkey(input: String): (Long) -> Int {
    val divisor = Regex("Test: divisible by ([0-9]+)").find(input)!!.groupValues[1].toInt()
    val ifTrue = Regex("If true: throw to monkey ([0-9]+)").find(input)!!.groupValues[1].toInt()
    val ifFalse = Regex("If false: throw to monkey ([0-9]+)").find(input)!!.groupValues[1].toInt()
    return { it -> if (it%divisor.toLong() == 0.toLong()) ifTrue else ifFalse}
}

fun parseOperation(rawOperation: String): (Long) -> Long {
    Regex("new = ([0-9a-z]+) ([*+-]) ([0-9a-z]+)")
        .find(rawOperation)!!
        .groupValues
        .let { groups ->
            val first = groups[1]
            val op = groups[2]
            val second = groups[3]
            return if(first == "old" && second == "old") {
                when(op) {
                    "+" -> { it -> it + it }
                    "*" -> { it -> it * it }
                    else -> throw Exception("Operation not supported")
                }
            } else {
                when(op) {
                    "+" -> { it -> it + second.toLong() }
                    "*" -> { it -> it * second.toLong() }
                    else -> throw Exception("Operation not supported")
                }
            }
        }
}

fun parseInputFile() =
    File("src/main/kotlin/day11/input.txt")
        .readText()
        .split(Regex("\r\n\r\n"))
        .fold(emptyList<Monkey>()) { acc, rawMonkey ->
            val monkeyId = Regex("Monkey ([0-9]+)").find(rawMonkey)!!.groupValues[1].toInt()
            val items = Regex("[0-9]+").findAll(
                Regex("Starting items: ([0-9]+,? ?)+").find(rawMonkey)!!.value
            ).toList().map { it.value.toLong() }
            val operation = parseOperation(
                Regex("Operation: new = [a-z0-9]+ [*+-] [a-z0-9]+").find(rawMonkey)!!.value
            )
            val nextMonkey = parseNextMonkey(rawMonkey)
            acc + Monkey(
                monkeyId,
                items,
                operation,
                nextMonkey
            )
        }

fun findMonkeyBusinessAfterNthRound(round: Int, worryLevel: Int): Int {
    val monkeys = parseInputFile()
    val ids = (monkeys.indices)
    val finalMonkeys = (0 until round).fold(monkeys) { m, _ ->
       ids.fold(m) { acc, id ->
            val monkey = acc.first { it.id == id }
            monkey.doATurn(acc, worryLevel)
        }
    }
    val monkeyActivity = finalMonkeys.map { it.monkeyActivity }.sortedDescending()
    return monkeyActivity[0] * monkeyActivity[1]
}

fun main() {
    println("The level of monkey business after 20 rounds is ${findMonkeyBusinessAfterNthRound(20, 3)}")
}

Compiled from "Solution.kt"
public final class day11.SolutionKt {
  public static final kotlin.jvm.functions.Function1<java.lang.Long, java.lang.Integer> parseNextMonkey(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class kotlin/text/Regex
       9: dup
      10: ldc           #20                 // String Test: divisible by ([0-9]+)
      12: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: aload_0
      16: checkcast     #26                 // class java/lang/CharSequence
      19: iconst_0
      20: iconst_2
      21: aconst_null
      22: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      25: dup
      26: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      29: invokeinterface #40,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      34: iconst_1
      35: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      40: checkcast     #48                 // class java/lang/String
      43: invokestatic  #54                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      46: istore_1
      47: new           #18                 // class kotlin/text/Regex
      50: dup
      51: ldc           #56                 // String If true: throw to monkey ([0-9]+)
      53: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      56: aload_0
      57: checkcast     #26                 // class java/lang/CharSequence
      60: iconst_0
      61: iconst_2
      62: aconst_null
      63: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      66: dup
      67: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      70: invokeinterface #40,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      75: iconst_1
      76: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      81: checkcast     #48                 // class java/lang/String
      84: invokestatic  #54                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      87: istore_2
      88: new           #18                 // class kotlin/text/Regex
      91: dup
      92: ldc           #58                 // String If false: throw to monkey ([0-9]+)
      94: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      97: aload_0
      98: checkcast     #26                 // class java/lang/CharSequence
     101: iconst_0
     102: iconst_2
     103: aconst_null
     104: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     107: dup
     108: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     111: invokeinterface #40,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     116: iconst_1
     117: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     122: checkcast     #48                 // class java/lang/String
     125: invokestatic  #54                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     128: istore_3
     129: iload_1
     130: iload_2
     131: iload_3
     132: invokedynamic #78,  0             // InvokeDynamic #0:invoke:(III)Lkotlin/jvm/functions/Function1;
     137: areturn

  public static final kotlin.jvm.functions.Function1<java.lang.Long, java.lang.Long> parseOperation(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #87                 // String rawOperation
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class kotlin/text/Regex
       9: dup
      10: ldc           #89                 // String new = ([0-9a-z]+) ([*+-]) ([0-9a-z]+)
      12: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: aload_0
      16: checkcast     #26                 // class java/lang/CharSequence
      19: iconst_0
      20: iconst_2
      21: aconst_null
      22: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      25: dup
      26: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      29: invokeinterface #40,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      34: astore_1
      35: iconst_0
      36: istore_2
      37: aload_1
      38: iconst_1
      39: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      44: checkcast     #48                 // class java/lang/String
      47: astore_3
      48: aload_1
      49: iconst_2
      50: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      55: checkcast     #48                 // class java/lang/String
      58: astore        4
      60: aload_1
      61: iconst_3
      62: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #48                 // class java/lang/String
      70: astore        5
      72: aload_3
      73: ldc           #91                 // String old
      75: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      78: ifeq          141
      81: aload         5
      83: ldc           #91                 // String old
      85: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      88: ifeq          141
      91: aload         4
      93: astore        6
      95: aload         6
      97: ldc           #97                 // String +
      99: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     102: ifeq          113
     105: invokedynamic #107,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
     110: goto          195
     113: aload         6
     115: ldc           #109                // String *
     117: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     120: ifeq          131
     123: invokedynamic #114,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
     128: goto          195
     131: new           #116                // class java/lang/Exception
     134: dup
     135: ldc           #118                // String Operation not supported
     137: invokespecial #119                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
     140: athrow
     141: aload         4
     143: astore        6
     145: aload         6
     147: ldc           #97                 // String +
     149: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     152: ifeq          165
     155: aload         5
     157: invokedynamic #126,  0            // InvokeDynamic #3:invoke:(Ljava/lang/String;)Lkotlin/jvm/functions/Function1;
     162: goto          195
     165: aload         6
     167: ldc           #109                // String *
     169: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     172: ifeq          185
     175: aload         5
     177: invokedynamic #131,  0            // InvokeDynamic #4:invoke:(Ljava/lang/String;)Lkotlin/jvm/functions/Function1;
     182: goto          195
     185: new           #116                // class java/lang/Exception
     188: dup
     189: ldc           #118                // String Operation not supported
     191: invokespecial #119                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
     194: athrow
     195: areturn

  public static final java.util.List<day11.Monkey> parseInputFile();
    Code:
       0: new           #143                // class java/io/File
       3: dup
       4: ldc           #145                // String src/main/kotlin/day11/input.txt
       6: invokespecial #146                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #152                // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: checkcast     #26                 // class java/lang/CharSequence
      18: astore_0
      19: new           #18                 // class kotlin/text/Regex
      22: dup
      23: ldc           #154                // String \r\n\r\n
      25: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      28: astore_1
      29: iconst_0
      30: istore_2
      31: aload_1
      32: aload_0
      33: iload_2
      34: invokevirtual #158                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      37: checkcast     #160                // class java/lang/Iterable
      40: astore_0
      41: invokestatic  #165                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      44: astore_1
      45: iconst_0
      46: istore_2
      47: aload_1
      48: astore_3
      49: aload_0
      50: invokeinterface #169,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      55: astore        4
      57: aload         4
      59: invokeinterface #175,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      64: ifeq          365
      67: aload         4
      69: invokeinterface #179,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      74: astore        5
      76: aload_3
      77: aload         5
      79: checkcast     #48                 // class java/lang/String
      82: astore        6
      84: astore        7
      86: iconst_0
      87: istore        8
      89: new           #18                 // class kotlin/text/Regex
      92: dup
      93: ldc           #181                // String Monkey ([0-9]+)
      95: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      98: aload         6
     100: checkcast     #26                 // class java/lang/CharSequence
     103: iconst_0
     104: iconst_2
     105: aconst_null
     106: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     109: dup
     110: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     113: invokeinterface #40,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     118: iconst_1
     119: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     124: checkcast     #48                 // class java/lang/String
     127: invokestatic  #54                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     130: istore        9
     132: new           #18                 // class kotlin/text/Regex
     135: dup
     136: ldc           #183                // String [0-9]+
     138: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     141: new           #18                 // class kotlin/text/Regex
     144: dup
     145: ldc           #185                // String Starting items: ([0-9]+,? ?)+
     147: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     150: aload         6
     152: checkcast     #26                 // class java/lang/CharSequence
     155: iconst_0
     156: iconst_2
     157: aconst_null
     158: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     161: dup
     162: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     165: invokeinterface #189,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     170: checkcast     #26                 // class java/lang/CharSequence
     173: iconst_0
     174: iconst_2
     175: aconst_null
     176: invokestatic  #193                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
     179: invokestatic  #199                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     182: checkcast     #160                // class java/lang/Iterable
     185: astore        10
     187: iconst_0
     188: istore        11
     190: aload         10
     192: astore        12
     194: new           #201                // class java/util/ArrayList
     197: dup
     198: aload         10
     200: bipush        10
     202: invokestatic  #205                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     205: invokespecial #208                // Method java/util/ArrayList."<init>":(I)V
     208: checkcast     #210                // class java/util/Collection
     211: astore        13
     213: iconst_0
     214: istore        14
     216: aload         12
     218: invokeinterface #169,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     223: astore        15
     225: aload         15
     227: invokeinterface #175,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     232: ifeq          284
     235: aload         15
     237: invokeinterface #179,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     242: astore        16
     244: aload         13
     246: aload         16
     248: checkcast     #36                 // class kotlin/text/MatchResult
     251: astore        17
     253: astore        18
     255: iconst_0
     256: istore        19
     258: aload         17
     260: invokeinterface #189,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     265: invokestatic  #216                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     268: nop
     269: invokestatic  #220                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     272: aload         18
     274: swap
     275: invokeinterface #224,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     280: pop
     281: goto          225
     284: aload         13
     286: checkcast     #42                 // class java/util/List
     289: nop
     290: astore        20
     292: new           #18                 // class kotlin/text/Regex
     295: dup
     296: ldc           #226                // String Operation: new = [a-z0-9]+ [*+-] [a-z0-9]+
     298: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     301: aload         6
     303: checkcast     #26                 // class java/lang/CharSequence
     306: iconst_0
     307: iconst_2
     308: aconst_null
     309: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     312: dup
     313: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     316: invokeinterface #189,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     321: invokestatic  #228                // Method parseOperation:(Ljava/lang/String;)Lkotlin/jvm/functions/Function1;
     324: astore        10
     326: aload         6
     328: invokestatic  #230                // Method parseNextMonkey:(Ljava/lang/String;)Lkotlin/jvm/functions/Function1;
     331: astore        11
     333: aload         7
     335: checkcast     #210                // class java/util/Collection
     338: new           #232                // class day11/Monkey
     341: dup
     342: iload         9
     344: aload         20
     346: aload         10
     348: aload         11
     350: iconst_0
     351: bipush        16
     353: aconst_null
     354: invokespecial #235                // Method day11/Monkey."<init>":(ILjava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
     357: invokestatic  #239                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     360: nop
     361: astore_3
     362: goto          57
     365: aload_3
     366: areturn

  public static final int findMonkeyBusinessAfterNthRound(int, int);
    Code:
       0: invokestatic  #268                // Method parseInputFile:()Ljava/util/List;
       3: astore_2
       4: aload_2
       5: checkcast     #210                // class java/util/Collection
       8: invokestatic  #272                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
      11: astore_3
      12: iconst_0
      13: iload_0
      14: invokestatic  #278                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      17: checkcast     #160                // class java/lang/Iterable
      20: astore        5
      22: iconst_0
      23: istore        6
      25: aload_2
      26: astore        7
      28: aload         5
      30: invokeinterface #169,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      35: astore        8
      37: aload         8
      39: invokeinterface #175,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          228
      47: aload         8
      49: checkcast     #280                // class kotlin/collections/IntIterator
      52: invokevirtual #284                // Method kotlin/collections/IntIterator.nextInt:()I
      55: istore        9
      57: aload         7
      59: astore        11
      61: iconst_0
      62: istore        12
      64: aload_3
      65: checkcast     #160                // class java/lang/Iterable
      68: astore        13
      70: iconst_0
      71: istore        14
      73: aload         11
      75: astore        15
      77: aload         13
      79: invokeinterface #169,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      84: astore        16
      86: aload         16
      88: invokeinterface #175,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      93: ifeq          220
      96: aload         16
      98: checkcast     #280                // class kotlin/collections/IntIterator
     101: invokevirtual #284                // Method kotlin/collections/IntIterator.nextInt:()I
     104: istore        17
     106: aload         15
     108: iload         17
     110: istore        18
     112: astore        19
     114: iconst_0
     115: istore        20
     117: aload         19
     119: checkcast     #160                // class java/lang/Iterable
     122: astore        21
     124: iconst_0
     125: istore        22
     127: aload         21
     129: invokeinterface #169,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     134: astore        23
     136: aload         23
     138: invokeinterface #175,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     143: ifeq          188
     146: aload         23
     148: invokeinterface #179,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     153: astore        24
     155: aload         24
     157: checkcast     #232                // class day11/Monkey
     160: astore        25
     162: iconst_0
     163: istore        26
     165: aload         25
     167: invokevirtual #287                // Method day11/Monkey.getId:()I
     170: iload         18
     172: if_icmpne     179
     175: iconst_1
     176: goto          180
     179: iconst_0
     180: ifeq          136
     183: aload         24
     185: goto          199
     188: new           #289                // class java/util/NoSuchElementException
     191: dup
     192: ldc_w         #291                // String Collection contains no element matching the predicate.
     195: invokespecial #292                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     198: athrow
     199: checkcast     #232                // class day11/Monkey
     202: astore        27
     204: aload         27
     206: aload         19
     208: iload_1
     209: iconst_0
     210: iconst_4
     211: aconst_null
     212: invokestatic  #296                // Method day11/Monkey.doATurn$default:(Lday11/Monkey;Ljava/util/List;IZILjava/lang/Object;)Ljava/util/List;
     215: astore        15
     217: goto          86
     220: aload         15
     222: nop
     223: astore        7
     225: goto          37
     228: aload         7
     230: astore        4
     232: aload         4
     234: checkcast     #160                // class java/lang/Iterable
     237: astore        6
     239: iconst_0
     240: istore        7
     242: aload         6
     244: astore        8
     246: new           #201                // class java/util/ArrayList
     249: dup
     250: aload         6
     252: bipush        10
     254: invokestatic  #205                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     257: invokespecial #208                // Method java/util/ArrayList."<init>":(I)V
     260: checkcast     #210                // class java/util/Collection
     263: astore        9
     265: iconst_0
     266: istore        10
     268: aload         8
     270: invokeinterface #169,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     275: astore        11
     277: aload         11
     279: invokeinterface #175,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     284: ifeq          330
     287: aload         11
     289: invokeinterface #179,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     294: astore        12
     296: aload         9
     298: aload         12
     300: checkcast     #232                // class day11/Monkey
     303: astore        13
     305: astore        28
     307: iconst_0
     308: istore        14
     310: aload         13
     312: invokevirtual #299                // Method day11/Monkey.getMonkeyActivity:()I
     315: invokestatic  #302                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     318: aload         28
     320: swap
     321: invokeinterface #224,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     326: pop
     327: goto          277
     330: aload         9
     332: checkcast     #42                 // class java/util/List
     335: nop
     336: checkcast     #160                // class java/lang/Iterable
     339: invokestatic  #306                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     342: astore        5
     344: aload         5
     346: iconst_0
     347: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     352: checkcast     #308                // class java/lang/Number
     355: invokevirtual #311                // Method java/lang/Number.intValue:()I
     358: aload         5
     360: iconst_1
     361: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     366: checkcast     #308                // class java/lang/Number
     369: invokevirtual #311                // Method java/lang/Number.intValue:()I
     372: imul
     373: ireturn

  public static final void main();
    Code:
       0: new           #334                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #336                // Method java/lang/StringBuilder."<init>":()V
       7: ldc_w         #338                // String The level of monkey business after 20 rounds is
      10: invokevirtual #342                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      13: bipush        20
      15: iconst_3
      16: invokestatic  #344                // Method findMonkeyBusinessAfterNthRound:(II)I
      19: invokevirtual #347                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      22: invokevirtual #350                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      25: getstatic     #356                // Field java/lang/System.out:Ljava/io/PrintStream;
      28: swap
      29: invokevirtual #361                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      32: return

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

  private static final int parseNextMonkey$lambda$0(int, int, int, long);
    Code:
       0: lload_3
       1: iload_0
       2: i2l
       3: lrem
       4: lconst_0
       5: lcmp
       6: ifne          13
       9: iload_1
      10: goto          14
      13: iload_2
      14: ireturn

  private static final long parseOperation$lambda$5$lambda$1(long);
    Code:
       0: lload_0
       1: lload_0
       2: ladd
       3: lreturn

  private static final long parseOperation$lambda$5$lambda$2(long);
    Code:
       0: lload_0
       1: lload_0
       2: lmul
       3: lreturn

  private static final long parseOperation$lambda$5$lambda$3(java.lang.String, long);
    Code:
       0: lload_1
       1: aload_0
       2: invokestatic  #216                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
       5: ladd
       6: lreturn

  private static final long parseOperation$lambda$5$lambda$4(java.lang.String, long);
    Code:
       0: lload_1
       1: aload_0
       2: invokestatic  #216                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
       5: lmul
       6: lreturn
}


package day10

import java.io.File

data class RegisterHistory(
    val history: Map<Int, Int> = mapOf(0 to 1)
) {
    fun addNoOp(): RegisterHistory {
        val lastClock = history.keys.last()
        val lastRegister = history.values.last()
        return this.copy(history = history + (lastClock+1 to lastRegister))
    }

    fun addAddxOp(amount: Int): RegisterHistory {
        val lastClock = history.keys.last()
        val lastRegister = history.values.last()
        return this.copy(history = history + (lastClock + 2 to lastRegister + amount))
    }

    fun getRegisterValueAtClock(clock: Int) =
        history.keys.last { it < clock }.let {
            history[it]
        } ?: 0
}

data class CrtRender(
    val crt: List<Char> = emptyList()
) {

    fun renderSprite(spriteCenter: Int): CrtRender =
        if (crt.size < 240) {
            val adjustedSprite = spriteCenter + (crt.size/40) * 40
            if (crt.size >= adjustedSprite-1 && crt.size <= adjustedSprite+1)
                this.copy(crt = crt + listOf('#'))
            else this.copy(crt = crt + listOf('.'))
        } else this

    fun printRendered() {
        crt.chunked(40).onEach {
            println(String(it.toCharArray()))
        }
    }

}

fun parseInputFile() =
    File("src/main/kotlin/day10/input.txt")
        .readLines()
        .fold(RegisterHistory()) { acc, cmd ->
            if(cmd == "noop") acc.addNoOp()
            else {
                val (_, amount) = cmd.split(" ")
                acc.addAddxOp(amount.toInt())
            }
        }

fun findSignalLevelAtClocks() = parseInputFile()
    .let { registerHistory ->
        List(6){ it*40+20 }.fold(0) { sum, it ->
            sum + registerHistory.getRegisterValueAtClock(it)*it
        }
    }

fun renderCrt() = parseInputFile()
    .let {
        (1 .. 240).fold(CrtRender()) { crt, clock ->
            crt.renderSprite(it.getRegisterValueAtClock(clock))
        }.printRendered()
    }

fun main() {
    println("The sum of the signal strengths during the 20th, 60th, 100th, 140th, 180th, and 220th cycles is: ${findSignalLevelAtClocks()}")
    println("The final CRT render is:")
    renderCrt()
}

Compiled from "Solution.kt"
public final class day10.SolutionKt {
  public static final day10.RegisterHistory parseInputFile();
    Code:
       0: new           #9                  // class java/io/File
       3: dup
       4: ldc           #11                 // String src/main/kotlin/day10/input.txt
       6: invokespecial #15                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #21                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #23                 // class java/lang/Iterable
      18: astore_0
      19: new           #25                 // class day10/RegisterHistory
      22: dup
      23: aconst_null
      24: iconst_1
      25: aconst_null
      26: invokespecial #28                 // Method day10/RegisterHistory."<init>":(Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      29: astore_1
      30: iconst_0
      31: istore_2
      32: aload_1
      33: astore_3
      34: aload_0
      35: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        4
      42: aload         4
      44: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          145
      52: aload         4
      54: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        5
      61: aload_3
      62: aload         5
      64: checkcast     #44                 // class java/lang/String
      67: astore        6
      69: astore        7
      71: iconst_0
      72: istore        8
      74: aload         6
      76: ldc           #46                 // String noop
      78: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      81: ifeq          92
      84: aload         7
      86: invokevirtual #55                 // Method day10/RegisterHistory.addNoOp:()Lday10/RegisterHistory;
      89: goto          140
      92: aload         6
      94: checkcast     #57                 // class java/lang/CharSequence
      97: iconst_1
      98: anewarray     #44                 // class java/lang/String
     101: astore        9
     103: aload         9
     105: iconst_0
     106: ldc           #59                 // String
     108: aastore
     109: aload         9
     111: iconst_0
     112: iconst_0
     113: bipush        6
     115: aconst_null
     116: invokestatic  #65                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     119: iconst_1
     120: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     125: checkcast     #44                 // class java/lang/String
     128: astore        9
     130: aload         7
     132: aload         9
     134: invokestatic  #77                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     137: invokevirtual #81                 // Method day10/RegisterHistory.addAddxOp:(I)Lday10/RegisterHistory;
     140: nop
     141: astore_3
     142: goto          42
     145: aload_3
     146: areturn

  public static final int findSignalLevelAtClocks();
    Code:
       0: invokestatic  #99                 // Method parseInputFile:()Lday10/RegisterHistory;
       3: astore_0
       4: iconst_0
       5: istore_1
       6: bipush        6
       8: istore_2
       9: new           #101                // class java/util/ArrayList
      12: dup
      13: iload_2
      14: invokespecial #104                // Method java/util/ArrayList."<init>":(I)V
      17: astore_3
      18: iconst_0
      19: istore        4
      21: iload         4
      23: iload_2
      24: if_icmpge     65
      27: iload         4
      29: istore        5
      31: aload_3
      32: iload         5
      34: istore        6
      36: astore        7
      38: iconst_0
      39: istore        8
      41: iload         6
      43: bipush        40
      45: imul
      46: bipush        20
      48: iadd
      49: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      52: aload         7
      54: swap
      55: invokevirtual #112                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      58: pop
      59: iinc          4, 1
      62: goto          21
      65: aload_3
      66: checkcast     #67                 // class java/util/List
      69: checkcast     #23                 // class java/lang/Iterable
      72: astore_2
      73: iconst_0
      74: istore_3
      75: iconst_0
      76: istore        4
      78: iload_3
      79: istore        5
      81: aload_2
      82: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      87: astore        6
      89: aload         6
      91: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      96: ifeq          142
      99: aload         6
     101: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     106: astore        8
     108: iload         5
     110: aload         8
     112: checkcast     #114                // class java/lang/Number
     115: invokevirtual #117                // Method java/lang/Number.intValue:()I
     118: istore        9
     120: istore        10
     122: iconst_0
     123: istore        11
     125: iload         10
     127: aload_0
     128: iload         9
     130: invokevirtual #121                // Method day10/RegisterHistory.getRegisterValueAtClock:(I)I
     133: iload         9
     135: imul
     136: iadd
     137: istore        5
     139: goto          89
     142: iload         5
     144: nop
     145: nop
     146: ireturn

  public static final void renderCrt();
    Code:
       0: invokestatic  #99                 // Method parseInputFile:()Lday10/RegisterHistory;
       3: astore_0
       4: iconst_0
       5: istore_1
       6: new           #131                // class kotlin/ranges/IntRange
       9: dup
      10: iconst_1
      11: sipush        240
      14: invokespecial #134                // Method kotlin/ranges/IntRange."<init>":(II)V
      17: checkcast     #23                 // class java/lang/Iterable
      20: astore_2
      21: new           #136                // class day10/CrtRender
      24: dup
      25: aconst_null
      26: iconst_1
      27: aconst_null
      28: invokespecial #139                // Method day10/CrtRender."<init>":(Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      31: astore_3
      32: iconst_0
      33: istore        4
      35: aload_3
      36: astore        5
      38: aload_2
      39: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        6
      46: aload         6
      48: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          93
      56: aload         6
      58: checkcast     #141                // class kotlin/collections/IntIterator
      61: invokevirtual #144                // Method kotlin/collections/IntIterator.nextInt:()I
      64: istore        7
      66: aload         5
      68: iload         7
      70: istore        8
      72: astore        9
      74: iconst_0
      75: istore        10
      77: aload         9
      79: aload_0
      80: iload         8
      82: invokevirtual #121                // Method day10/RegisterHistory.getRegisterValueAtClock:(I)I
      85: invokevirtual #148                // Method day10/CrtRender.renderSprite:(I)Lday10/CrtRender;
      88: astore        5
      90: goto          46
      93: aload         5
      95: invokevirtual #151                // Method day10/CrtRender.printRendered:()V
      98: nop
      99: nop
     100: return

  public static final void main();
    Code:
       0: new           #159                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #161                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #163                // String The sum of the signal strengths during the 20th, 60th, 100th, 140th, 180th, and 220th cycles is:
       9: invokevirtual #167                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: invokestatic  #169                // Method findSignalLevelAtClocks:()I
      15: invokevirtual #172                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      18: invokevirtual #176                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      21: getstatic     #182                // Field java/lang/System.out:Ljava/io/PrintStream;
      24: swap
      25: invokevirtual #188                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      28: ldc           #190                // String The final CRT render is:
      30: getstatic     #182                // Field java/lang/System.out:Ljava/io/PrintStream;
      33: swap
      34: invokevirtual #188                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      37: invokestatic  #192                // Method renderCrt:()V
      40: return

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


package dev.fwcd.adventofcode2021

import kotlin.math.sign

data class Vec(val x: Int, val y: Int) {
    operator fun plus(rhs: Vec) = Vec(x + rhs.x, y + rhs.y)
}

data class Rect(val min: Vec, val max: Vec) {
    operator fun contains(pos: Vec): Boolean =
           pos.x >= min.x && pos.x <= max.x
        && pos.y >= min.y && pos.y <= max.y
}

data class SimulationResults(val hitTarget: Boolean, val maxY: Int)

fun simulate(startVelocity: Vec, target: Rect): SimulationResults {
    var pos = Vec(0, 0)
    var velocity = startVelocity
    var maxY = 0

    while (pos.x <= target.max.x && pos.y >= target.min.y) {
        if (pos in target) {
            return SimulationResults(hitTarget = true, maxY)
        }
        pos += velocity
        maxY = Math.max(pos.y, maxY)
        velocity = Vec(velocity.x - velocity.x.sign, velocity.y - 1)
    }

    return SimulationResults(hitTarget = false, maxY)
}

fun main() {
    val input = object {}.javaClass.getResource("/input.txt").readText()
    val pattern = """target area: x=(-?\d+)..(-?\d+), y=(-?\d+)..(-?\d+)""".toRegex()
    val (x1, x2, y1, y2) = pattern.find(input)!!.groupValues.drop(1).map { it.toInt() }
    val target = Rect(Vec(x1, y1), Vec(x2, y2))
    val radius = Math.max(
        Math.max(Math.abs(x1), Math.abs(x2)),
        Math.max(Math.abs(y1), Math.abs(y2))
    )
    var maxY = 0
    var hitCount = 0

    for (dy in -radius..radius) {
        for (dx in -radius..radius) {
            val results = simulate(Vec(dx, dy), target)
            if (results.hitTarget) {
                maxY = Math.max(maxY, results.maxY)
                hitCount++
            }
        }
    }

    println("Part 1: $maxY")
    println("Part 2: $hitCount")
}

Compiled from "Day17.kt"
public final class dev.fwcd.adventofcode2021.Day17Kt$main$input$1 {
  dev.fwcd.adventofcode2021.Day17Kt$main$input$1();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return
}

Compiled from "Day17.kt"
public final class dev.fwcd.adventofcode2021.Day17Kt {
  public static final dev.fwcd.adventofcode2021.SimulationResults simulate(dev.fwcd.adventofcode2021.Vec, dev.fwcd.adventofcode2021.Rect);
    Code:
       0: aload_0
       1: ldc           #9                  // String startVelocity
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String target
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #19                 // class dev/fwcd/adventofcode2021/Vec
      15: dup
      16: iconst_0
      17: iconst_0
      18: invokespecial #23                 // Method dev/fwcd/adventofcode2021/Vec."<init>":(II)V
      21: astore_2
      22: aload_0
      23: astore_3
      24: iconst_0
      25: istore        4
      27: aload_2
      28: invokevirtual #27                 // Method dev/fwcd/adventofcode2021/Vec.getX:()I
      31: aload_1
      32: invokevirtual #33                 // Method dev/fwcd/adventofcode2021/Rect.getMax:()Ldev/fwcd/adventofcode2021/Vec;
      35: invokevirtual #27                 // Method dev/fwcd/adventofcode2021/Vec.getX:()I
      38: if_icmpgt     120
      41: aload_2
      42: invokevirtual #36                 // Method dev/fwcd/adventofcode2021/Vec.getY:()I
      45: aload_1
      46: invokevirtual #39                 // Method dev/fwcd/adventofcode2021/Rect.getMin:()Ldev/fwcd/adventofcode2021/Vec;
      49: invokevirtual #36                 // Method dev/fwcd/adventofcode2021/Vec.getY:()I
      52: if_icmplt     120
      55: aload_1
      56: aload_2
      57: invokevirtual #43                 // Method dev/fwcd/adventofcode2021/Rect.contains:(Ldev/fwcd/adventofcode2021/Vec;)Z
      60: ifeq          74
      63: new           #45                 // class dev/fwcd/adventofcode2021/SimulationResults
      66: dup
      67: iconst_1
      68: iload         4
      70: invokespecial #48                 // Method dev/fwcd/adventofcode2021/SimulationResults."<init>":(ZI)V
      73: areturn
      74: aload_2
      75: aload_3
      76: invokevirtual #52                 // Method dev/fwcd/adventofcode2021/Vec.plus:(Ldev/fwcd/adventofcode2021/Vec;)Ldev/fwcd/adventofcode2021/Vec;
      79: astore_2
      80: aload_2
      81: invokevirtual #36                 // Method dev/fwcd/adventofcode2021/Vec.getY:()I
      84: iload         4
      86: invokestatic  #58                 // Method java/lang/Math.max:(II)I
      89: istore        4
      91: new           #19                 // class dev/fwcd/adventofcode2021/Vec
      94: dup
      95: aload_3
      96: invokevirtual #27                 // Method dev/fwcd/adventofcode2021/Vec.getX:()I
      99: aload_3
     100: invokevirtual #27                 // Method dev/fwcd/adventofcode2021/Vec.getX:()I
     103: invokestatic  #64                 // Method kotlin/math/MathKt.getSign:(I)I
     106: isub
     107: aload_3
     108: invokevirtual #36                 // Method dev/fwcd/adventofcode2021/Vec.getY:()I
     111: iconst_1
     112: isub
     113: invokespecial #23                 // Method dev/fwcd/adventofcode2021/Vec."<init>":(II)V
     116: astore_3
     117: goto          27
     120: new           #45                 // class dev/fwcd/adventofcode2021/SimulationResults
     123: dup
     124: iconst_0
     125: iload         4
     127: invokespecial #48                 // Method dev/fwcd/adventofcode2021/SimulationResults."<init>":(ZI)V
     130: areturn

  public static final void main();
    Code:
       0: new           #74                 // class dev/fwcd/adventofcode2021/Day17Kt$main$input$1
       3: dup
       4: invokespecial #76                 // Method dev/fwcd/adventofcode2021/Day17Kt$main$input$1."<init>":()V
       7: invokevirtual #80                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      10: ldc           #82                 // String /input.txt
      12: invokevirtual #88                 // Method java/lang/Class.getResource:(Ljava/lang/String;)Ljava/net/URL;
      15: dup
      16: ldc           #90                 // String getResource(...)
      18: invokestatic  #93                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      21: astore_1
      22: getstatic     #99                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      25: astore_2
      26: aload_1
      27: invokestatic  #105                // Method kotlin/io/TextStreamsKt.readBytes:(Ljava/net/URL;)[B
      30: astore_3
      31: new           #107                // class java/lang/String
      34: dup
      35: aload_3
      36: aload_2
      37: invokespecial #110                // Method java/lang/String."<init>":([BLjava/nio/charset/Charset;)V
      40: astore_0
      41: new           #112                // class kotlin/text/Regex
      44: dup
      45: ldc           #114                // String target area: x=(-?\\d+)..(-?\\d+), y=(-?\\d+)..(-?\\d+)
      47: invokespecial #117                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      50: astore_1
      51: aload_1
      52: aload_0
      53: checkcast     #119                // class java/lang/CharSequence
      56: iconst_0
      57: iconst_2
      58: aconst_null
      59: invokestatic  #123                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      62: dup
      63: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      66: invokeinterface #133,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      71: checkcast     #135                // class java/lang/Iterable
      74: iconst_1
      75: invokestatic  #141                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      78: checkcast     #135                // class java/lang/Iterable
      81: astore_3
      82: iconst_0
      83: istore        4
      85: aload_3
      86: astore        5
      88: new           #143                // class java/util/ArrayList
      91: dup
      92: aload_3
      93: bipush        10
      95: invokestatic  #147                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      98: invokespecial #150                // Method java/util/ArrayList."<init>":(I)V
     101: checkcast     #152                // class java/util/Collection
     104: astore        6
     106: iconst_0
     107: istore        7
     109: aload         5
     111: invokeinterface #156,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        8
     118: aload         8
     120: invokeinterface #162,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          172
     128: aload         8
     130: invokeinterface #166,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: astore        9
     137: aload         6
     139: aload         9
     141: checkcast     #107                // class java/lang/String
     144: astore        10
     146: astore        14
     148: iconst_0
     149: istore        11
     151: aload         10
     153: invokestatic  #172                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     156: nop
     157: invokestatic  #176                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     160: aload         14
     162: swap
     163: invokeinterface #180,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     168: pop
     169: goto          118
     172: aload         6
     174: checkcast     #182                // class java/util/List
     177: nop
     178: astore_2
     179: aload_2
     180: iconst_0
     181: invokeinterface #186,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: checkcast     #188                // class java/lang/Number
     189: invokevirtual #191                // Method java/lang/Number.intValue:()I
     192: istore_3
     193: aload_2
     194: iconst_1
     195: invokeinterface #186,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     200: checkcast     #188                // class java/lang/Number
     203: invokevirtual #191                // Method java/lang/Number.intValue:()I
     206: istore        4
     208: aload_2
     209: iconst_2
     210: invokeinterface #186,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     215: checkcast     #188                // class java/lang/Number
     218: invokevirtual #191                // Method java/lang/Number.intValue:()I
     221: istore        5
     223: aload_2
     224: iconst_3
     225: invokeinterface #186,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     230: checkcast     #188                // class java/lang/Number
     233: invokevirtual #191                // Method java/lang/Number.intValue:()I
     236: istore        6
     238: new           #29                 // class dev/fwcd/adventofcode2021/Rect
     241: dup
     242: new           #19                 // class dev/fwcd/adventofcode2021/Vec
     245: dup
     246: iload_3
     247: iload         5
     249: invokespecial #23                 // Method dev/fwcd/adventofcode2021/Vec."<init>":(II)V
     252: new           #19                 // class dev/fwcd/adventofcode2021/Vec
     255: dup
     256: iload         4
     258: iload         6
     260: invokespecial #23                 // Method dev/fwcd/adventofcode2021/Vec."<init>":(II)V
     263: invokespecial #194                // Method dev/fwcd/adventofcode2021/Rect."<init>":(Ldev/fwcd/adventofcode2021/Vec;Ldev/fwcd/adventofcode2021/Vec;)V
     266: astore        7
     268: iload_3
     269: invokestatic  #197                // Method java/lang/Math.abs:(I)I
     272: iload         4
     274: invokestatic  #197                // Method java/lang/Math.abs:(I)I
     277: invokestatic  #58                 // Method java/lang/Math.max:(II)I
     280: iload         5
     282: invokestatic  #197                // Method java/lang/Math.abs:(I)I
     285: iload         6
     287: invokestatic  #197                // Method java/lang/Math.abs:(I)I
     290: invokestatic  #58                 // Method java/lang/Math.max:(II)I
     293: invokestatic  #58                 // Method java/lang/Math.max:(II)I
     296: istore        8
     298: iconst_0
     299: istore        9
     301: iconst_0
     302: istore        10
     304: iload         8
     306: ineg
     307: istore        11
     309: iload         11
     311: iload         8
     313: if_icmpgt     395
     316: iload         8
     318: ineg
     319: istore        12
     321: iload         12
     323: iload         8
     325: if_icmpgt     382
     328: new           #19                 // class dev/fwcd/adventofcode2021/Vec
     331: dup
     332: iload         12
     334: iload         11
     336: invokespecial #23                 // Method dev/fwcd/adventofcode2021/Vec."<init>":(II)V
     339: aload         7
     341: invokestatic  #199                // Method simulate:(Ldev/fwcd/adventofcode2021/Vec;Ldev/fwcd/adventofcode2021/Rect;)Ldev/fwcd/adventofcode2021/SimulationResults;
     344: astore        13
     346: aload         13
     348: invokevirtual #202                // Method dev/fwcd/adventofcode2021/SimulationResults.getHitTarget:()Z
     351: ifeq          369
     354: iload         9
     356: aload         13
     358: invokevirtual #205                // Method dev/fwcd/adventofcode2021/SimulationResults.getMaxY:()I
     361: invokestatic  #58                 // Method java/lang/Math.max:(II)I
     364: istore        9
     366: iinc          10, 1
     369: iload         12
     371: iload         8
     373: if_icmpeq     382
     376: iinc          12, 1
     379: goto          328
     382: iload         11
     384: iload         8
     386: if_icmpeq     395
     389: iinc          11, 1
     392: goto          316
     395: new           #207                // class java/lang/StringBuilder
     398: dup
     399: invokespecial #208                // Method java/lang/StringBuilder."<init>":()V
     402: ldc           #210                // String Part 1:
     404: invokevirtual #214                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     407: iload         9
     409: invokevirtual #217                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     412: invokevirtual #221                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     415: getstatic     #227                // Field java/lang/System.out:Ljava/io/PrintStream;
     418: swap
     419: invokevirtual #232                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     422: new           #207                // class java/lang/StringBuilder
     425: dup
     426: invokespecial #208                // Method java/lang/StringBuilder."<init>":()V
     429: ldc           #234                // String Part 2:
     431: invokevirtual #214                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     434: iload         10
     436: invokevirtual #217                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     439: invokevirtual #221                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     442: getstatic     #227                // Field java/lang/System.out:Ljava/io/PrintStream;
     445: swap
     446: invokevirtual #232                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     449: return

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