package com.github.brpeterman.advent2022

import java.util.LinkedList
import java.util.SortedMap

typealias ArithmeticOperation = (Long, Long) -> Long
typealias MonkeyRule = (Long) -> KeepAway.ItemPass

class KeepAway(input: String, worryDecay: Int) {
    data class Monkey(val holding: LinkedList<Long>, val rule: MonkeyRule, val divisor: Int, var inspectionCount: Int = 0)
    data class ItemPass(val to: Int, val worryLevel: Long)
    enum class Operation(val function: ArithmeticOperation) {
        ADD({ a, b ->  a + b }),
        MULTIPLY({ a, b -> a * b })
    }

    val monkeys = parseInput(input, worryDecay)
    val commonMultiple = calculateCommonMultiple(monkeys.values)

    fun calculateMonkeyBusiness(): Long {
        return monkeys.values.map { it.inspectionCount.toLong() }
            .sorted()
            .reversed()
            .subList(0, 2)
            .reduce { product, count -> product * count }
    }

    fun simulate(rounds: Int) {
        (0 until rounds).forEach {
            monkeys.values
                .forEach { monkey -> takeTurn(monkey) }
        }
    }

    fun takeTurn(monkey: Monkey) {
        while (monkey.holding.isNotEmpty()) {
            val item = monkey.holding.pop()
            val result = monkey.rule.invoke(item)
            monkeys[result.to]!!.holding.add(result.worryLevel)
            monkey.inspectionCount++
        }
    }

    fun parseInput(input: String, worryDecay: Int): SortedMap<Int, Monkey> {
        return input.split("\n\n")
            .withIndex()
            .map { (index, monkeyDef) ->
                val lines = monkeyDef.split("\n")
                val startingItems = parseStartingItems(lines[1])
                val (divisorStr) = """divisible by (\d+)""".toRegex()
                        .find(lines[3])!!
                        .destructured
                val divisor = divisorStr.toInt()
                val rule = parseRule(divisor, lines[2], lines[4], lines[5], worryDecay)
                index to Monkey(startingItems, rule, divisor)
            }
            .toMap()
            .toSortedMap()
    }

    fun parseStartingItems(line: String): LinkedList<Long> {
        return LinkedList(""" (\d+),?""".toRegex().findAll(line)
            .map {
                val (num) = it.destructured
                num.toLong()
            }
            .toList())
    }

    fun calculateCommonMultiple(monkeys: Collection<Monkey>): Long {
        return monkeys.fold(1, { product, m -> product * m.divisor.toLong() })
    }

    fun parseRule(divisor: Int, operationLine: String, trueLine: String, falseLine: String, worryDecay: Int): MonkeyRule {
        val (operator, operandStr) = """new = old ([+*]) (\d+|old)""".toRegex()
            .find(operationLine)!!
            .destructured
        val operatorFunction = when (operator) {
            "+" -> Operation.ADD
            "*" -> Operation.MULTIPLY
            else -> throw IllegalStateException("Unexpected operator: ${operator}")
        }
        val (trueMonkeyStr) = """monkey (\d+)""".toRegex()
            .find(trueLine)!!
            .destructured
        val (falseMonkeyStr) = """monkey (\d+)""".toRegex()
            .find(falseLine)!!
            .destructured

        val trueMonkey = trueMonkeyStr.toInt()
        val falseMonkey = falseMonkeyStr.toInt()
        return constructRuleFunction(operatorFunction, operandStr, divisor, trueMonkey, falseMonkey, worryDecay)
    }

    fun constructRuleFunction(operatorFunction: Operation, operandStr: String, divisor: Int, trueMonkey: Int, falseMonkey: Int, worryDecay: Int): MonkeyRule {
        return { old ->
            val operand = if (operandStr == "old") {
                old
            } else {
                operandStr.toLong()
            }
            var new = operatorFunction.function.invoke(old, operand)
            new = if (worryDecay > 1) {
                new / worryDecay
            } else {
                new % commonMultiple
            }
            if (new % divisor == 0L) {
                ItemPass(trueMonkey, new)
            } else {
                ItemPass(falseMonkey, new)
            }
        }
    }
}

Compiled from "KeepAway.kt"
public final class com.github.brpeterman.advent2022.KeepAway$Operation extends java.lang.Enum<com.github.brpeterman.advent2022.KeepAway$Operation> {
  private final kotlin.jvm.functions.Function2<java.lang.Long, java.lang.Long, java.lang.Long> function;

  public static final com.github.brpeterman.advent2022.KeepAway$Operation ADD;

  public static final com.github.brpeterman.advent2022.KeepAway$Operation MULTIPLY;

  private static final com.github.brpeterman.advent2022.KeepAway$Operation[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private com.github.brpeterman.advent2022.KeepAway$Operation(kotlin.jvm.functions.Function2<? super java.lang.Long, ? super java.lang.Long, java.lang.Long>);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #11                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: aload_0
       7: aload_3
       8: putfield      #15                 // Field function:Lkotlin/jvm/functions/Function2;
      11: return

  public final kotlin.jvm.functions.Function2<java.lang.Long, java.lang.Long, java.lang.Long> getFunction();
    Code:
       0: aload_0
       1: getfield      #15                 // Field function:Lkotlin/jvm/functions/Function2;
       4: areturn

  public static com.github.brpeterman.advent2022.KeepAway$Operation[] values();
    Code:
       0: getstatic     #31                 // Field $VALUES:[Lcom/github/brpeterman/advent2022/KeepAway$Operation;
       3: invokevirtual #37                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #38                 // class "[Lcom/github/brpeterman/advent2022/KeepAway$Operation;"
       9: areturn

  public static com.github.brpeterman.advent2022.KeepAway$Operation valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class com/github/brpeterman/advent2022/KeepAway$Operation
       2: aload_0
       3: invokestatic  #43                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class com/github/brpeterman/advent2022/KeepAway$Operation
       9: areturn

  public static kotlin.enums.EnumEntries<com.github.brpeterman.advent2022.KeepAway$Operation> getEntries();
    Code:
       0: getstatic     #51                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final long _init_$lambda$0(long, long);
    Code:
       0: lload_0
       1: lload_2
       2: ladd
       3: lreturn

  private static final long _init_$lambda$1(long, long);
    Code:
       0: lload_0
       1: lload_2
       2: lmul
       3: lreturn

  private static final com.github.brpeterman.advent2022.KeepAway$Operation[] $values();
    Code:
       0: iconst_2
       1: anewarray     #2                  // class com/github/brpeterman/advent2022/KeepAway$Operation
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #61                 // Field ADD:Lcom/github/brpeterman/advent2022/KeepAway$Operation;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #64                 // Field MULTIPLY:Lcom/github/brpeterman/advent2022/KeepAway$Operation;
      16: aastore
      17: aload_0
      18: areturn

  static {};
    Code:
       0: new           #2                  // class com/github/brpeterman/advent2022/KeepAway$Operation
       3: dup
       4: ldc           #67                 // String ADD
       6: iconst_0
       7: invokedynamic #84,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
      12: invokespecial #86                 // Method "<init>":(Ljava/lang/String;ILkotlin/jvm/functions/Function2;)V
      15: putstatic     #61                 // Field ADD:Lcom/github/brpeterman/advent2022/KeepAway$Operation;
      18: new           #2                  // class com/github/brpeterman/advent2022/KeepAway$Operation
      21: dup
      22: ldc           #87                 // String MULTIPLY
      24: iconst_1
      25: invokedynamic #91,  0             // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function2;
      30: invokespecial #86                 // Method "<init>":(Ljava/lang/String;ILkotlin/jvm/functions/Function2;)V
      33: putstatic     #64                 // Field MULTIPLY:Lcom/github/brpeterman/advent2022/KeepAway$Operation;
      36: invokestatic  #93                 // Method $values:()[Lcom/github/brpeterman/advent2022/KeepAway$Operation;
      39: putstatic     #31                 // Field $VALUES:[Lcom/github/brpeterman/advent2022/KeepAway$Operation;
      42: getstatic     #31                 // Field $VALUES:[Lcom/github/brpeterman/advent2022/KeepAway$Operation;
      45: checkcast     #95                 // class "[Ljava/lang/Enum;"
      48: invokestatic  #101                // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      51: putstatic     #51                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      54: return
}

Compiled from "KeepAway.kt"
public final class com.github.brpeterman.advent2022.KeepAway {
  private final java.util.SortedMap<java.lang.Integer, com.github.brpeterman.advent2022.KeepAway$Monkey> monkeys;

  private final long commonMultiple;

  public com.github.brpeterman.advent2022.KeepAway(java.lang.String, int);
    Code:
       0: aload_1
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_0
      12: aload_1
      13: iload_2
      14: invokevirtual #22                 // Method parseInput:(Ljava/lang/String;I)Ljava/util/SortedMap;
      17: putfield      #26                 // Field monkeys:Ljava/util/SortedMap;
      20: aload_0
      21: aload_0
      22: aload_0
      23: getfield      #26                 // Field monkeys:Ljava/util/SortedMap;
      26: invokeinterface #32,  1           // InterfaceMethod java/util/SortedMap.values:()Ljava/util/Collection;
      31: dup
      32: ldc           #34                 // String <get-values>(...)
      34: invokestatic  #37                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      37: invokevirtual #41                 // Method calculateCommonMultiple:(Ljava/util/Collection;)J
      40: putfield      #45                 // Field commonMultiple:J
      43: return

  public final java.util.SortedMap<java.lang.Integer, com.github.brpeterman.advent2022.KeepAway$Monkey> getMonkeys();
    Code:
       0: aload_0
       1: getfield      #26                 // Field monkeys:Ljava/util/SortedMap;
       4: areturn

  public final long getCommonMultiple();
    Code:
       0: aload_0
       1: getfield      #45                 // Field commonMultiple:J
       4: lreturn

  public final long calculateMonkeyBusiness();
    Code:
       0: aload_0
       1: getfield      #26                 // Field monkeys:Ljava/util/SortedMap;
       4: invokeinterface #32,  1           // InterfaceMethod java/util/SortedMap.values:()Ljava/util/Collection;
       9: dup
      10: ldc           #34                 // String <get-values>(...)
      12: invokestatic  #37                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      15: checkcast     #58                 // class java/lang/Iterable
      18: astore_1
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #60                 // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #69                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #71                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          106
      62: aload         6
      64: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         4
      73: aload         7
      75: checkcast     #87                 // class com/github/brpeterman/advent2022/KeepAway$Monkey
      78: astore        8
      80: astore        10
      82: iconst_0
      83: istore        9
      85: aload         8
      87: invokevirtual #91                 // Method com/github/brpeterman/advent2022/KeepAway$Monkey.getInspectionCount:()I
      90: i2l
      91: invokestatic  #97                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      94: aload         10
      96: swap
      97: invokeinterface #101,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     102: pop
     103: goto          52
     106: aload         4
     108: checkcast     #103                // class java/util/List
     111: nop
     112: checkcast     #58                 // class java/lang/Iterable
     115: invokestatic  #107                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     118: checkcast     #58                 // class java/lang/Iterable
     121: invokestatic  #110                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     124: iconst_0
     125: iconst_2
     126: invokeinterface #114,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     131: checkcast     #58                 // class java/lang/Iterable
     134: astore_1
     135: nop
     136: iconst_0
     137: istore_2
     138: aload_1
     139: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     144: astore_3
     145: aload_3
     146: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     151: ifne          164
     154: new           #116                // class java/lang/UnsupportedOperationException
     157: dup
     158: ldc           #118                // String Empty collection can\'t be reduced.
     160: invokespecial #121                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     163: athrow
     164: aload_3
     165: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     170: astore        4
     172: aload_3
     173: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     178: ifeq          221
     181: aload         4
     183: aload_3
     184: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     189: checkcast     #123                // class java/lang/Number
     192: invokevirtual #126                // Method java/lang/Number.longValue:()J
     195: lstore        5
     197: checkcast     #123                // class java/lang/Number
     200: invokevirtual #126                // Method java/lang/Number.longValue:()J
     203: lstore        7
     205: iconst_0
     206: istore        9
     208: lload         7
     210: lload         5
     212: lmul
     213: invokestatic  #97                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     216: astore        4
     218: goto          172
     221: aload         4
     223: checkcast     #123                // class java/lang/Number
     226: invokevirtual #126                // Method java/lang/Number.longValue:()J
     229: lreturn

  public final void simulate(int);
    Code:
       0: iconst_0
       1: iload_1
       2: invokestatic  #153                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       5: checkcast     #58                 // class java/lang/Iterable
       8: astore_2
       9: iconst_0
      10: istore_3
      11: aload_2
      12: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      17: astore        4
      19: aload         4
      21: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifeq          129
      29: aload         4
      31: checkcast     #155                // class kotlin/collections/IntIterator
      34: invokevirtual #158                // Method kotlin/collections/IntIterator.nextInt:()I
      37: istore        5
      39: iload         5
      41: istore        6
      43: iconst_0
      44: istore        7
      46: aload_0
      47: getfield      #26                 // Field monkeys:Ljava/util/SortedMap;
      50: invokeinterface #32,  1           // InterfaceMethod java/util/SortedMap.values:()Ljava/util/Collection;
      55: dup
      56: ldc           #34                 // String <get-values>(...)
      58: invokestatic  #37                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      61: checkcast     #58                 // class java/lang/Iterable
      64: astore        8
      66: nop
      67: iconst_0
      68: istore        9
      70: aload         8
      72: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      77: astore        10
      79: aload         10
      81: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      86: ifeq          123
      89: aload         10
      91: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      96: astore        11
      98: aload         11
     100: checkcast     #87                 // class com/github/brpeterman/advent2022/KeepAway$Monkey
     103: astore        12
     105: iconst_0
     106: istore        13
     108: aload_0
     109: aload         12
     111: invokestatic  #162                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     114: aload         12
     116: invokevirtual #166                // Method takeTurn:(Lcom/github/brpeterman/advent2022/KeepAway$Monkey;)V
     119: nop
     120: goto          79
     123: nop
     124: nop
     125: nop
     126: goto          19
     129: nop
     130: return

  public final void takeTurn(com.github.brpeterman.advent2022.KeepAway$Monkey);
    Code:
       0: aload_1
       1: ldc           #174                // String monkey
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokevirtual #178                // Method com/github/brpeterman/advent2022/KeepAway$Monkey.getHolding:()Ljava/util/LinkedList;
      10: checkcast     #71                 // class java/util/Collection
      13: invokeinterface #181,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      18: ifne          25
      21: iconst_1
      22: goto          26
      25: iconst_0
      26: ifeq          112
      29: aload_1
      30: invokevirtual #178                // Method com/github/brpeterman/advent2022/KeepAway$Monkey.getHolding:()Ljava/util/LinkedList;
      33: invokevirtual #186                // Method java/util/LinkedList.pop:()Ljava/lang/Object;
      36: checkcast     #93                 // class java/lang/Long
      39: astore_2
      40: aload_1
      41: invokevirtual #190                // Method com/github/brpeterman/advent2022/KeepAway$Monkey.getRule:()Lkotlin/jvm/functions/Function1;
      44: aload_2
      45: invokestatic  #162                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      48: aload_2
      49: invokeinterface #196,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      54: checkcast     #198                // class com/github/brpeterman/advent2022/KeepAway$ItemPass
      57: astore_3
      58: aload_0
      59: getfield      #26                 // Field monkeys:Ljava/util/SortedMap;
      62: aload_3
      63: invokevirtual #201                // Method com/github/brpeterman/advent2022/KeepAway$ItemPass.getTo:()I
      66: invokestatic  #206                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      69: invokeinterface #209,  2          // InterfaceMethod java/util/SortedMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      74: dup
      75: invokestatic  #162                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      78: checkcast     #87                 // class com/github/brpeterman/advent2022/KeepAway$Monkey
      81: invokevirtual #178                // Method com/github/brpeterman/advent2022/KeepAway$Monkey.getHolding:()Ljava/util/LinkedList;
      84: aload_3
      85: invokevirtual #212                // Method com/github/brpeterman/advent2022/KeepAway$ItemPass.getWorryLevel:()J
      88: invokestatic  #97                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      91: invokevirtual #213                // Method java/util/LinkedList.add:(Ljava/lang/Object;)Z
      94: pop
      95: aload_1
      96: invokevirtual #91                 // Method com/github/brpeterman/advent2022/KeepAway$Monkey.getInspectionCount:()I
      99: istore        4
     101: aload_1
     102: iload         4
     104: iconst_1
     105: iadd
     106: invokevirtual #216                // Method com/github/brpeterman/advent2022/KeepAway$Monkey.setInspectionCount:(I)V
     109: goto          6
     112: return

  public final java.util.SortedMap<java.lang.Integer, com.github.brpeterman.advent2022.KeepAway$Monkey> parseInput(java.lang.String, int);
    Code:
       0: aload_1
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #223                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #225                // class java/lang/String
      14: astore_3
      15: aload_3
      16: iconst_0
      17: ldc           #227                // String \n\n
      19: aastore
      20: aload_3
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #233                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #58                 // class java/lang/Iterable
      32: invokestatic  #237                // Method kotlin/collections/CollectionsKt.withIndex:(Ljava/lang/Iterable;)Ljava/lang/Iterable;
      35: astore_3
      36: nop
      37: iconst_0
      38: istore        4
      40: aload_3
      41: astore        5
      43: new           #60                 // class java/util/ArrayList
      46: dup
      47: aload_3
      48: bipush        10
      50: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      53: invokespecial #69                 // Method java/util/ArrayList."<init>":(I)V
      56: checkcast     #71                 // class java/util/Collection
      59: astore        6
      61: iconst_0
      62: istore        7
      64: aload         5
      66: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      71: astore        8
      73: aload         8
      75: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      80: ifeq          310
      83: aload         8
      85: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      90: astore        9
      92: aload         6
      94: aload         9
      96: checkcast     #239                // class kotlin/collections/IndexedValue
      99: astore        10
     101: astore        19
     103: iconst_0
     104: istore        11
     106: aload         10
     108: invokevirtual #242                // Method kotlin/collections/IndexedValue.component1:()I
     111: istore        12
     113: aload         10
     115: invokevirtual #245                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     118: checkcast     #225                // class java/lang/String
     121: astore        13
     123: aload         13
     125: checkcast     #223                // class java/lang/CharSequence
     128: iconst_1
     129: anewarray     #225                // class java/lang/String
     132: astore        14
     134: aload         14
     136: iconst_0
     137: ldc           #247                // String \n
     139: aastore
     140: aload         14
     142: iconst_0
     143: iconst_0
     144: bipush        6
     146: aconst_null
     147: invokestatic  #233                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     150: astore        15
     152: aload_0
     153: aload         15
     155: iconst_1
     156: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     161: checkcast     #225                // class java/lang/String
     164: invokevirtual #254                // Method parseStartingItems:(Ljava/lang/String;)Ljava/util/LinkedList;
     167: astore        14
     169: new           #256                // class kotlin/text/Regex
     172: dup
     173: ldc_w         #258                // String divisible by (\\d+)
     176: invokespecial #259                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     179: aload         15
     181: iconst_3
     182: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     187: checkcast     #223                // class java/lang/CharSequence
     190: iconst_0
     191: iconst_2
     192: aconst_null
     193: invokestatic  #263                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     196: dup
     197: invokestatic  #162                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     200: invokeinterface #269,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     205: invokevirtual #275                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     208: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     213: iconst_1
     214: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     219: checkcast     #225                // class java/lang/String
     222: astore        16
     224: aload         16
     226: invokestatic  #283                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     229: istore        17
     231: aload_0
     232: iload         17
     234: aload         15
     236: iconst_2
     237: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     242: checkcast     #225                // class java/lang/String
     245: aload         15
     247: iconst_4
     248: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     253: checkcast     #225                // class java/lang/String
     256: aload         15
     258: iconst_5
     259: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     264: checkcast     #225                // class java/lang/String
     267: iload_2
     268: invokevirtual #287                // Method parseRule:(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Lkotlin/jvm/functions/Function1;
     271: astore        18
     273: iload         12
     275: invokestatic  #206                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     278: new           #87                 // class com/github/brpeterman/advent2022/KeepAway$Monkey
     281: dup
     282: aload         14
     284: aload         18
     286: iload         17
     288: iconst_0
     289: bipush        8
     291: aconst_null
     292: invokespecial #290                // Method com/github/brpeterman/advent2022/KeepAway$Monkey."<init>":(Ljava/util/LinkedList;Lkotlin/jvm/functions/Function1;IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     295: invokestatic  #296                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     298: aload         19
     300: swap
     301: invokeinterface #101,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     306: pop
     307: goto          73
     310: aload         6
     312: checkcast     #103                // class java/util/List
     315: nop
     316: checkcast     #58                 // class java/lang/Iterable
     319: invokestatic  #302                // Method kotlin/collections/MapsKt.toMap:(Ljava/lang/Iterable;)Ljava/util/Map;
     322: invokestatic  #306                // Method kotlin/collections/MapsKt.toSortedMap:(Ljava/util/Map;)Ljava/util/SortedMap;
     325: areturn

  public final java.util.LinkedList<java.lang.Long> parseStartingItems(java.lang.String);
    Code:
       0: aload_1
       1: ldc_w         #320                // String line
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #183                // class java/util/LinkedList
      10: dup
      11: new           #256                // class kotlin/text/Regex
      14: dup
      15: ldc_w         #322                // String  (\\d+),?
      18: invokespecial #259                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      21: aload_1
      22: checkcast     #223                // class java/lang/CharSequence
      25: iconst_0
      26: iconst_2
      27: aconst_null
      28: invokestatic  #326                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      31: invokedynamic #343,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      36: invokestatic  #349                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      39: invokestatic  #353                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      42: checkcast     #71                 // class java/util/Collection
      45: invokespecial #356                // Method java/util/LinkedList."<init>":(Ljava/util/Collection;)V
      48: areturn

  public final long calculateCommonMultiple(java.util.Collection<com.github.brpeterman.advent2022.KeepAway$Monkey>);
    Code:
       0: aload_1
       1: ldc_w         #358                // String monkeys
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: checkcast     #58                 // class java/lang/Iterable
      11: astore_2
      12: lconst_1
      13: lstore_3
      14: iconst_0
      15: istore        5
      17: lload_3
      18: lstore        6
      20: aload_2
      21: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      26: astore        8
      28: aload         8
      30: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      35: ifeq          75
      38: aload         8
      40: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      45: astore        9
      47: lload         6
      49: aload         9
      51: checkcast     #87                 // class com/github/brpeterman/advent2022/KeepAway$Monkey
      54: astore        10
      56: lstore        11
      58: iconst_0
      59: istore        13
      61: lload         11
      63: aload         10
      65: invokevirtual #361                // Method com/github/brpeterman/advent2022/KeepAway$Monkey.getDivisor:()I
      68: i2l
      69: lmul
      70: lstore        6
      72: goto          28
      75: lload         6
      77: lreturn

  public final kotlin.jvm.functions.Function1<java.lang.Long, com.github.brpeterman.advent2022.KeepAway$ItemPass> parseRule(int, java.lang.String, java.lang.String, java.lang.String, int);
    Code:
       0: aload_2
       1: ldc_w         #369                // String operationLine
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_3
       8: ldc_w         #371                // String trueLine
      11: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload         4
      16: ldc_w         #373                // String falseLine
      19: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      22: new           #256                // class kotlin/text/Regex
      25: dup
      26: ldc_w         #375                // String new = old ([+*]) (\\d+|old)
      29: invokespecial #259                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      32: aload_2
      33: checkcast     #223                // class java/lang/CharSequence
      36: iconst_0
      37: iconst_2
      38: aconst_null
      39: invokestatic  #263                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      42: dup
      43: invokestatic  #162                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      46: invokeinterface #269,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      51: astore        6
      53: aload         6
      55: invokevirtual #275                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      58: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      63: iconst_1
      64: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      69: checkcast     #225                // class java/lang/String
      72: astore        7
      74: aload         6
      76: invokevirtual #275                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      79: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      84: iconst_2
      85: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      90: checkcast     #225                // class java/lang/String
      93: astore        8
      95: aload         7
      97: astore        10
      99: aload         10
     101: ldc_w         #377                // String +
     104: invokestatic  #381                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     107: ifeq          116
     110: getstatic     #387                // Field com/github/brpeterman/advent2022/KeepAway$Operation.ADD:Lcom/github/brpeterman/advent2022/KeepAway$Operation;
     113: goto          162
     116: aload         10
     118: ldc_w         #389                // String *
     121: invokestatic  #381                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     124: ifeq          133
     127: getstatic     #392                // Field com/github/brpeterman/advent2022/KeepAway$Operation.MULTIPLY:Lcom/github/brpeterman/advent2022/KeepAway$Operation;
     130: goto          162
     133: new           #394                // class java/lang/IllegalStateException
     136: dup
     137: new           #396                // class java/lang/StringBuilder
     140: dup
     141: invokespecial #397                // Method java/lang/StringBuilder."<init>":()V
     144: ldc_w         #399                // String Unexpected operator:
     147: invokevirtual #403                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     150: aload         7
     152: invokevirtual #403                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     155: invokevirtual #407                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     158: invokespecial #408                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     161: athrow
     162: astore        9
     164: new           #256                // class kotlin/text/Regex
     167: dup
     168: ldc_w         #410                // String monkey (\\d+)
     171: invokespecial #259                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     174: aload_3
     175: checkcast     #223                // class java/lang/CharSequence
     178: iconst_0
     179: iconst_2
     180: aconst_null
     181: invokestatic  #263                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     184: dup
     185: invokestatic  #162                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     188: invokeinterface #269,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     193: invokevirtual #275                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     196: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     201: iconst_1
     202: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     207: checkcast     #225                // class java/lang/String
     210: astore        11
     212: new           #256                // class kotlin/text/Regex
     215: dup
     216: ldc_w         #410                // String monkey (\\d+)
     219: invokespecial #259                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     222: aload         4
     224: checkcast     #223                // class java/lang/CharSequence
     227: iconst_0
     228: iconst_2
     229: aconst_null
     230: invokestatic  #263                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     233: dup
     234: invokestatic  #162                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     237: invokeinterface #269,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     242: invokevirtual #275                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     245: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     250: iconst_1
     251: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     256: checkcast     #225                // class java/lang/String
     259: astore        12
     261: aload         11
     263: invokestatic  #283                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     266: istore        13
     268: aload         12
     270: invokestatic  #283                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     273: istore        14
     275: aload_0
     276: aload         9
     278: aload         8
     280: iload_1
     281: iload         13
     283: iload         14
     285: iload         5
     287: invokevirtual #414                // Method constructRuleFunction:(Lcom/github/brpeterman/advent2022/KeepAway$Operation;Ljava/lang/String;IIII)Lkotlin/jvm/functions/Function1;
     290: areturn

  public final kotlin.jvm.functions.Function1<java.lang.Long, com.github.brpeterman.advent2022.KeepAway$ItemPass> constructRuleFunction(com.github.brpeterman.advent2022.KeepAway$Operation, java.lang.String, int, int, int, int);
    Code:
       0: aload_1
       1: ldc_w         #423                // String operatorFunction
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_2
       8: ldc_w         #424                // String operandStr
      11: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_2
      15: aload_1
      16: iload         6
      18: aload_0
      19: iload_3
      20: iload         4
      22: iload         5
      24: invokedynamic #434,  0            // InvokeDynamic #1:invoke:(Ljava/lang/String;Lcom/github/brpeterman/advent2022/KeepAway$Operation;ILcom/github/brpeterman/advent2022/KeepAway;III)Lkotlin/jvm/functions/Function1;
      29: areturn

  private static final long parseStartingItems$lambda$5(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc_w         #435                // String it
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokeinterface #269,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      13: invokevirtual #275                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      16: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      21: iconst_1
      22: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      27: checkcast     #225                // class java/lang/String
      30: astore_1
      31: aload_1
      32: invokestatic  #439                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      35: lreturn

  private static final com.github.brpeterman.advent2022.KeepAway$ItemPass constructRuleFunction$lambda$7(java.lang.String, com.github.brpeterman.advent2022.KeepAway$Operation, int, com.github.brpeterman.advent2022.KeepAway, int, int, int, long);
    Code:
       0: aload_0
       1: ldc_w         #443                // String old
       4: invokestatic  #381                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       7: ifeq          15
      10: lload         7
      12: goto          19
      15: aload_0
      16: invokestatic  #439                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      19: lstore        9
      21: aload_1
      22: invokevirtual #447                // Method com/github/brpeterman/advent2022/KeepAway$Operation.getFunction:()Lkotlin/jvm/functions/Function2;
      25: lload         7
      27: invokestatic  #97                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      30: lload         9
      32: invokestatic  #97                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      35: invokeinterface #452,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      40: checkcast     #123                // class java/lang/Number
      43: invokevirtual #126                // Method java/lang/Number.longValue:()J
      46: lstore        11
      48: iload_2
      49: iconst_1
      50: if_icmple     61
      53: lload         11
      55: iload_2
      56: i2l
      57: ldiv
      58: goto          68
      61: lload         11
      63: aload_3
      64: getfield      #45                 // Field commonMultiple:J
      67: lrem
      68: lstore        11
      70: lload         11
      72: iload         4
      74: i2l
      75: lrem
      76: lconst_0
      77: lcmp
      78: ifne          95
      81: new           #198                // class com/github/brpeterman/advent2022/KeepAway$ItemPass
      84: dup
      85: iload         5
      87: lload         11
      89: invokespecial #455                // Method com/github/brpeterman/advent2022/KeepAway$ItemPass."<init>":(IJ)V
      92: goto          106
      95: new           #198                // class com/github/brpeterman/advent2022/KeepAway$ItemPass
      98: dup
      99: iload         6
     101: lload         11
     103: invokespecial #455                // Method com/github/brpeterman/advent2022/KeepAway$ItemPass."<init>":(IJ)V
     106: areturn
}

Compiled from "KeepAway.kt"
public final class com.github.brpeterman.advent2022.KeepAway$Monkey {
  private final java.util.LinkedList<java.lang.Long> holding;

  private final kotlin.jvm.functions.Function1<java.lang.Long, com.github.brpeterman.advent2022.KeepAway$ItemPass> rule;

  private final int divisor;

  private int inspectionCount;

  public com.github.brpeterman.advent2022.KeepAway$Monkey(java.util.LinkedList<java.lang.Long>, kotlin.jvm.functions.Function1<? super java.lang.Long, com.github.brpeterman.advent2022.KeepAway$ItemPass>, int, int);
    Code:
       0: aload_1
       1: ldc           #10                 // String holding
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String rule
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #21                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #24                 // Field holding:Ljava/util/LinkedList;
      21: aload_0
      22: aload_2
      23: putfield      #27                 // Field rule:Lkotlin/jvm/functions/Function1;
      26: aload_0
      27: iload_3
      28: putfield      #31                 // Field divisor:I
      31: aload_0
      32: iload         4
      34: putfield      #34                 // Field inspectionCount:I
      37: return

  public com.github.brpeterman.advent2022.KeepAway$Monkey(java.util.LinkedList, kotlin.jvm.functions.Function1, int, int, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         5
       2: bipush        8
       4: iand
       5: ifeq          11
       8: iconst_0
       9: istore        4
      11: aload_0
      12: aload_1
      13: aload_2
      14: iload_3
      15: iload         4
      17: invokespecial #39                 // Method "<init>":(Ljava/util/LinkedList;Lkotlin/jvm/functions/Function1;II)V
      20: return

  public final java.util.LinkedList<java.lang.Long> getHolding();
    Code:
       0: aload_0
       1: getfield      #24                 // Field holding:Ljava/util/LinkedList;
       4: areturn

  public final kotlin.jvm.functions.Function1<java.lang.Long, com.github.brpeterman.advent2022.KeepAway$ItemPass> getRule();
    Code:
       0: aload_0
       1: getfield      #27                 // Field rule:Lkotlin/jvm/functions/Function1;
       4: areturn

  public final int getDivisor();
    Code:
       0: aload_0
       1: getfield      #31                 // Field divisor:I
       4: ireturn

  public final int getInspectionCount();
    Code:
       0: aload_0
       1: getfield      #34                 // Field inspectionCount:I
       4: ireturn

  public final void setInspectionCount(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #34                 // Field inspectionCount:I
       5: return

  public final java.util.LinkedList<java.lang.Long> component1();
    Code:
       0: aload_0
       1: getfield      #24                 // Field holding:Ljava/util/LinkedList;
       4: areturn

  public final kotlin.jvm.functions.Function1<java.lang.Long, com.github.brpeterman.advent2022.KeepAway$ItemPass> component2();
    Code:
       0: aload_0
       1: getfield      #27                 // Field rule:Lkotlin/jvm/functions/Function1;
       4: areturn

  public final int component3();
    Code:
       0: aload_0
       1: getfield      #31                 // Field divisor:I
       4: ireturn

  public final int component4();
    Code:
       0: aload_0
       1: getfield      #34                 // Field inspectionCount:I
       4: ireturn

  public final com.github.brpeterman.advent2022.KeepAway$Monkey copy(java.util.LinkedList<java.lang.Long>, kotlin.jvm.functions.Function1<? super java.lang.Long, com.github.brpeterman.advent2022.KeepAway$ItemPass>, int, int);
    Code:
       0: aload_1
       1: ldc           #10                 // String holding
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String rule
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class com/github/brpeterman/advent2022/KeepAway$Monkey
      15: dup
      16: aload_1
      17: aload_2
      18: iload_3
      19: iload         4
      21: invokespecial #39                 // Method "<init>":(Ljava/util/LinkedList;Lkotlin/jvm/functions/Function1;II)V
      24: areturn

  public static com.github.brpeterman.advent2022.KeepAway$Monkey copy$default(com.github.brpeterman.advent2022.KeepAway$Monkey, java.util.LinkedList, kotlin.jvm.functions.Function1, int, int, int, java.lang.Object);
    Code:
       0: iload         5
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #24                 // Field holding:Ljava/util/LinkedList;
      11: astore_1
      12: iload         5
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #27                 // Field rule:Lkotlin/jvm/functions/Function1;
      23: astore_2
      24: iload         5
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #31                 // Field divisor:I
      35: istore_3
      36: iload         5
      38: bipush        8
      40: iand
      41: ifeq          50
      44: aload_0
      45: getfield      #34                 // Field inspectionCount:I
      48: istore        4
      50: aload_0
      51: aload_1
      52: aload_2
      53: iload_3
      54: iload         4
      56: invokevirtual #62                 // Method copy:(Ljava/util/LinkedList;Lkotlin/jvm/functions/Function1;II)Lcom/github/brpeterman/advent2022/KeepAway$Monkey;
      59: areturn

  public java.lang.String toString();
    Code:
       0: new           #66                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #67                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #69                 // String Monkey(holding=
       9: invokevirtual #73                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #24                 // Field holding:Ljava/util/LinkedList;
      16: invokevirtual #76                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: ldc           #78                 // String , rule=
      21: invokevirtual #73                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #27                 // Field rule:Lkotlin/jvm/functions/Function1;
      28: invokevirtual #76                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: ldc           #80                 // String , divisor=
      33: invokevirtual #73                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #31                 // Field divisor:I
      40: invokevirtual #83                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      43: ldc           #85                 // String , inspectionCount=
      45: invokevirtual #73                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      48: aload_0
      49: getfield      #34                 // Field inspectionCount:I
      52: invokevirtual #83                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      55: bipush        41
      57: invokevirtual #88                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      60: invokevirtual #90                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      63: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #24                 // Field holding:Ljava/util/LinkedList;
       4: invokevirtual #95                 // Method java/util/LinkedList.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #27                 // Field rule:Lkotlin/jvm/functions/Function1;
      16: invokevirtual #96                 // Method java/lang/Object.hashCode:()I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #31                 // Field divisor:I
      29: invokestatic  #101                // Method java/lang/Integer.hashCode:(I)I
      32: iadd
      33: istore_1
      34: iload_1
      35: bipush        31
      37: imul
      38: aload_0
      39: getfield      #34                 // Field inspectionCount:I
      42: invokestatic  #101                // Method java/lang/Integer.hashCode:(I)I
      45: iadd
      46: istore_1
      47: iload_1
      48: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class com/github/brpeterman/advent2022/KeepAway$Monkey
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class com/github/brpeterman/advent2022/KeepAway$Monkey
      20: astore_2
      21: aload_0
      22: getfield      #24                 // Field holding:Ljava/util/LinkedList;
      25: aload_2
      26: getfield      #24                 // Field holding:Ljava/util/LinkedList;
      29: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #27                 // Field rule:Lkotlin/jvm/functions/Function1;
      41: aload_2
      42: getfield      #27                 // Field rule:Lkotlin/jvm/functions/Function1;
      45: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      48: ifne          53
      51: iconst_0
      52: ireturn
      53: aload_0
      54: getfield      #31                 // Field divisor:I
      57: aload_2
      58: getfield      #31                 // Field divisor:I
      61: if_icmpeq     66
      64: iconst_0
      65: ireturn
      66: aload_0
      67: getfield      #34                 // Field inspectionCount:I
      70: aload_2
      71: getfield      #34                 // Field inspectionCount:I
      74: if_icmpeq     79
      77: iconst_0
      78: ireturn
      79: iconst_1
      80: ireturn
}

Compiled from "KeepAway.kt"
public final class com.github.brpeterman.advent2022.KeepAwayKt {
}

Compiled from "KeepAway.kt"
public final class com.github.brpeterman.advent2022.KeepAway$ItemPass {
  private final int to;

  private final long worryLevel;

  public com.github.brpeterman.advent2022.KeepAway$ItemPass(int, long);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field to:I
       9: aload_0
      10: lload_2
      11: putfield      #17                 // Field worryLevel:J
      14: return

  public final int getTo();
    Code:
       0: aload_0
       1: getfield      #13                 // Field to:I
       4: ireturn

  public final long getWorryLevel();
    Code:
       0: aload_0
       1: getfield      #17                 // Field worryLevel:J
       4: lreturn

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field to:I
       4: ireturn

  public final long component2();
    Code:
       0: aload_0
       1: getfield      #17                 // Field worryLevel:J
       4: lreturn

  public final com.github.brpeterman.advent2022.KeepAway$ItemPass copy(int, long);
    Code:
       0: new           #2                  // class com/github/brpeterman/advent2022/KeepAway$ItemPass
       3: dup
       4: iload_1
       5: lload_2
       6: invokespecial #30                 // Method "<init>":(IJ)V
       9: areturn

  public static com.github.brpeterman.advent2022.KeepAway$ItemPass copy$default(com.github.brpeterman.advent2022.KeepAway$ItemPass, int, long, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #13                 // Field to:I
      11: istore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #17                 // Field worryLevel:J
      23: lstore_2
      24: aload_0
      25: iload_1
      26: lload_2
      27: invokevirtual #34                 // Method copy:(IJ)Lcom/github/brpeterman/advent2022/KeepAway$ItemPass;
      30: areturn

  public java.lang.String toString();
    Code:
       0: new           #38                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #39                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #41                 // String ItemPass(to=
       9: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field to:I
      16: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #50                 // String , worryLevel=
      21: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #17                 // Field worryLevel:J
      28: invokevirtual #53                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #56                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #58                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field to:I
       4: invokestatic  #64                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #17                 // Field worryLevel:J
      16: invokestatic  #69                 // Method java/lang/Long.hashCode:(J)I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class com/github/brpeterman/advent2022/KeepAway$ItemPass
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class com/github/brpeterman/advent2022/KeepAway$ItemPass
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field to:I
      25: aload_2
      26: getfield      #13                 // Field to:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #17                 // Field worryLevel:J
      38: aload_2
      39: getfield      #17                 // Field worryLevel:J
      42: lcmp
      43: ifeq          48
      46: iconst_0
      47: ireturn
      48: iconst_1
      49: ireturn
}