package day6

class Day6(val input: String) {

    private val listOfWindows = (0..input.length-4).map { input.substring(it, it+4) }
    private val messageMarkerWindows = (0..input.length-14).map { input.substring(it, it+14) }

    fun startOfPacket(): Int {
        return listOfWindows.indexOfFirst { !it.containsDuplicates() } + 4
    }

    fun startOfMessage(): Int {
        return messageMarkerWindows.indexOfFirst { !it.containsDuplicates() } + 14
    }

    override fun toString(): String {
        return input
    }
}

fun String.containsDuplicates(): Boolean {
    return this.toCharArray().distinct().size != this.toCharArray().size
}

fun main() {

    val test1 = Day6("mjqjpqmgbljsphdztnvjfqwrcgsmlb")
    val test2 = Day6("bvwbjplbgvbhsrlpgdmjqwftvncz")
    val test3 = Day6("nppdvjthqldpwncqszvftbrmjlhg")
    val test4 = Day6("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg")
    val test5 = Day6("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw")

    check(test1.startOfPacket() == 7)
    check(test2.startOfPacket() == 5)
    check(test3.startOfPacket() == 6)
    check(test4.startOfPacket() == 10)
    check(test5.startOfPacket() == 11)

    check(test1.startOfMessage() == 19)
    check(test2.startOfMessage() == 23)
    check(test3.startOfMessage() == 23)
    check(test4.startOfMessage() == 29)
    check(test5.startOfMessage() == 26)

    val input = Day6::class.java.getResourceAsStream("/day6_input.txt").bufferedReader().readLines().first()
    val day6 = Day6(input)
    println("Part1 = ${day6.startOfPacket()}")
    println("Part2 = ${day6.startOfMessage()}")
}

Compiled from "Day6.kt"
public final class day6.Day6 {
  private final java.lang.String input;

  private final java.util.List<java.lang.String> listOfWindows;

  private final java.util.List<java.lang.String> messageMarkerWindows;

  public day6.Day6(java.lang.String);
    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_1
      12: putfield      #21                 // Field input:Ljava/lang/String;
      15: aload_0
      16: new           #23                 // class kotlin/ranges/IntRange
      19: dup
      20: iconst_0
      21: aload_0
      22: getfield      #21                 // Field input:Ljava/lang/String;
      25: invokevirtual #29                 // Method java/lang/String.length:()I
      28: iconst_4
      29: isub
      30: invokespecial #32                 // Method kotlin/ranges/IntRange."<init>":(II)V
      33: checkcast     #34                 // class java/lang/Iterable
      36: astore_2
      37: astore        11
      39: iconst_0
      40: istore_3
      41: aload_2
      42: astore        4
      44: new           #36                 // class java/util/ArrayList
      47: dup
      48: aload_2
      49: bipush        10
      51: invokestatic  #42                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      54: invokespecial #45                 // Method java/util/ArrayList."<init>":(I)V
      57: checkcast     #47                 // class java/util/Collection
      60: astore        5
      62: iconst_0
      63: istore        6
      65: aload         4
      67: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      72: astore        7
      74: aload         7
      76: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      81: ifeq          137
      84: aload         7
      86: checkcast     #59                 // class kotlin/collections/IntIterator
      89: invokevirtual #62                 // Method kotlin/collections/IntIterator.nextInt:()I
      92: istore        8
      94: aload         5
      96: iload         8
      98: istore        9
     100: astore        12
     102: iconst_0
     103: istore        10
     105: aload_0
     106: getfield      #21                 // Field input:Ljava/lang/String;
     109: iload         9
     111: iload         9
     113: iconst_4
     114: iadd
     115: invokevirtual #66                 // Method java/lang/String.substring:(II)Ljava/lang/String;
     118: dup
     119: ldc           #68                 // String substring(...)
     121: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     124: nop
     125: aload         12
     127: swap
     128: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     133: pop
     134: goto          74
     137: aload         5
     139: checkcast     #77                 // class java/util/List
     142: nop
     143: aload         11
     145: swap
     146: putfield      #81                 // Field listOfWindows:Ljava/util/List;
     149: aload_0
     150: new           #23                 // class kotlin/ranges/IntRange
     153: dup
     154: iconst_0
     155: aload_0
     156: getfield      #21                 // Field input:Ljava/lang/String;
     159: invokevirtual #29                 // Method java/lang/String.length:()I
     162: bipush        14
     164: isub
     165: invokespecial #32                 // Method kotlin/ranges/IntRange."<init>":(II)V
     168: checkcast     #34                 // class java/lang/Iterable
     171: astore_2
     172: astore        11
     174: iconst_0
     175: istore_3
     176: aload_2
     177: astore        4
     179: new           #36                 // class java/util/ArrayList
     182: dup
     183: aload_2
     184: bipush        10
     186: invokestatic  #42                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     189: invokespecial #45                 // Method java/util/ArrayList."<init>":(I)V
     192: checkcast     #47                 // class java/util/Collection
     195: astore        5
     197: iconst_0
     198: istore        6
     200: aload         4
     202: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     207: astore        7
     209: aload         7
     211: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     216: ifeq          273
     219: aload         7
     221: checkcast     #59                 // class kotlin/collections/IntIterator
     224: invokevirtual #62                 // Method kotlin/collections/IntIterator.nextInt:()I
     227: istore        8
     229: aload         5
     231: iload         8
     233: istore        9
     235: astore        12
     237: iconst_0
     238: istore        10
     240: aload_0
     241: getfield      #21                 // Field input:Ljava/lang/String;
     244: iload         9
     246: iload         9
     248: bipush        14
     250: iadd
     251: invokevirtual #66                 // Method java/lang/String.substring:(II)Ljava/lang/String;
     254: dup
     255: ldc           #68                 // String substring(...)
     257: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     260: nop
     261: aload         12
     263: swap
     264: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     269: pop
     270: goto          209
     273: aload         5
     275: checkcast     #77                 // class java/util/List
     278: nop
     279: aload         11
     281: swap
     282: putfield      #84                 // Field messageMarkerWindows:Ljava/util/List;
     285: return

  public final java.lang.String getInput();
    Code:
       0: aload_0
       1: getfield      #21                 // Field input:Ljava/lang/String;
       4: areturn

  public final int startOfPacket();
    Code:
       0: aload_0
       1: getfield      #81                 // Field listOfWindows:Ljava/util/List;
       4: astore_1
       5: iconst_0
       6: istore_2
       7: iconst_0
       8: istore_3
       9: aload_1
      10: invokeinterface #102,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      15: astore        4
      17: aload         4
      19: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          72
      27: aload         4
      29: invokeinterface #106,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: astore        5
      36: aload         5
      38: checkcast     #25                 // class java/lang/String
      41: astore        6
      43: iconst_0
      44: istore        7
      46: aload         6
      48: invokestatic  #112                // Method day6/Day6Kt.containsDuplicates:(Ljava/lang/String;)Z
      51: ifne          58
      54: iconst_1
      55: goto          59
      58: iconst_0
      59: ifeq          66
      62: iload_3
      63: goto          73
      66: iinc          3, 1
      69: goto          17
      72: iconst_m1
      73: iconst_4
      74: iadd
      75: ireturn

  public final int startOfMessage();
    Code:
       0: aload_0
       1: getfield      #84                 // Field messageMarkerWindows:Ljava/util/List;
       4: astore_1
       5: iconst_0
       6: istore_2
       7: iconst_0
       8: istore_3
       9: aload_1
      10: invokeinterface #102,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      15: astore        4
      17: aload         4
      19: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          72
      27: aload         4
      29: invokeinterface #106,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: astore        5
      36: aload         5
      38: checkcast     #25                 // class java/lang/String
      41: astore        6
      43: iconst_0
      44: istore        7
      46: aload         6
      48: invokestatic  #112                // Method day6/Day6Kt.containsDuplicates:(Ljava/lang/String;)Z
      51: ifne          58
      54: iconst_1
      55: goto          59
      58: iconst_0
      59: ifeq          66
      62: iload_3
      63: goto          73
      66: iinc          3, 1
      69: goto          17
      72: iconst_m1
      73: bipush        14
      75: iadd
      76: ireturn

  public java.lang.String toString();
    Code:
       0: aload_0
       1: getfield      #21                 // Field input:Ljava/lang/String;
       4: areturn
}

Compiled from "Day6.kt"
public final class day6.Day6Kt {
  public static final boolean containsDuplicates(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #21                 // Method java/lang/String.toCharArray:()[C
      10: dup
      11: ldc           #23                 // String toCharArray(...)
      13: invokestatic  #26                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      16: invokestatic  #32                 // Method kotlin/collections/ArraysKt.distinct:([C)Ljava/util/List;
      19: invokeinterface #38,  1           // InterfaceMethod java/util/List.size:()I
      24: aload_0
      25: invokevirtual #21                 // Method java/lang/String.toCharArray:()[C
      28: dup
      29: ldc           #23                 // String toCharArray(...)
      31: invokestatic  #26                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      34: arraylength
      35: if_icmpeq     42
      38: iconst_1
      39: goto          43
      42: iconst_0
      43: ireturn

  public static final void main();
    Code:
       0: new           #44                 // class day6/Day6
       3: dup
       4: ldc           #46                 // String mjqjpqmgbljsphdztnvjfqwrcgsmlb
       6: invokespecial #50                 // Method day6/Day6."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: new           #44                 // class day6/Day6
      13: dup
      14: ldc           #52                 // String bvwbjplbgvbhsrlpgdmjqwftvncz
      16: invokespecial #50                 // Method day6/Day6."<init>":(Ljava/lang/String;)V
      19: astore_1
      20: new           #44                 // class day6/Day6
      23: dup
      24: ldc           #54                 // String nppdvjthqldpwncqszvftbrmjlhg
      26: invokespecial #50                 // Method day6/Day6."<init>":(Ljava/lang/String;)V
      29: astore_2
      30: new           #44                 // class day6/Day6
      33: dup
      34: ldc           #56                 // String nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg
      36: invokespecial #50                 // Method day6/Day6."<init>":(Ljava/lang/String;)V
      39: astore_3
      40: new           #44                 // class day6/Day6
      43: dup
      44: ldc           #58                 // String zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw
      46: invokespecial #50                 // Method day6/Day6."<init>":(Ljava/lang/String;)V
      49: astore        4
      51: aload_0
      52: invokevirtual #61                 // Method day6/Day6.startOfPacket:()I
      55: bipush        7
      57: if_icmpne     64
      60: iconst_1
      61: goto          65
      64: iconst_0
      65: ifne          78
      68: new           #63                 // class java/lang/IllegalStateException
      71: dup
      72: ldc           #65                 // String Check failed.
      74: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      77: athrow
      78: aload_1
      79: invokevirtual #61                 // Method day6/Day6.startOfPacket:()I
      82: iconst_5
      83: if_icmpne     90
      86: iconst_1
      87: goto          91
      90: iconst_0
      91: ifne          104
      94: new           #63                 // class java/lang/IllegalStateException
      97: dup
      98: ldc           #65                 // String Check failed.
     100: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     103: athrow
     104: aload_2
     105: invokevirtual #61                 // Method day6/Day6.startOfPacket:()I
     108: bipush        6
     110: if_icmpne     117
     113: iconst_1
     114: goto          118
     117: iconst_0
     118: ifne          131
     121: new           #63                 // class java/lang/IllegalStateException
     124: dup
     125: ldc           #65                 // String Check failed.
     127: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     130: athrow
     131: aload_3
     132: invokevirtual #61                 // Method day6/Day6.startOfPacket:()I
     135: bipush        10
     137: if_icmpne     144
     140: iconst_1
     141: goto          145
     144: iconst_0
     145: ifne          158
     148: new           #63                 // class java/lang/IllegalStateException
     151: dup
     152: ldc           #65                 // String Check failed.
     154: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     157: athrow
     158: aload         4
     160: invokevirtual #61                 // Method day6/Day6.startOfPacket:()I
     163: bipush        11
     165: if_icmpne     172
     168: iconst_1
     169: goto          173
     172: iconst_0
     173: ifne          186
     176: new           #63                 // class java/lang/IllegalStateException
     179: dup
     180: ldc           #65                 // String Check failed.
     182: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     185: athrow
     186: aload_0
     187: invokevirtual #69                 // Method day6/Day6.startOfMessage:()I
     190: bipush        19
     192: if_icmpne     199
     195: iconst_1
     196: goto          200
     199: iconst_0
     200: ifne          213
     203: new           #63                 // class java/lang/IllegalStateException
     206: dup
     207: ldc           #65                 // String Check failed.
     209: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     212: athrow
     213: aload_1
     214: invokevirtual #69                 // Method day6/Day6.startOfMessage:()I
     217: bipush        23
     219: if_icmpne     226
     222: iconst_1
     223: goto          227
     226: iconst_0
     227: ifne          240
     230: new           #63                 // class java/lang/IllegalStateException
     233: dup
     234: ldc           #65                 // String Check failed.
     236: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     239: athrow
     240: aload_2
     241: invokevirtual #69                 // Method day6/Day6.startOfMessage:()I
     244: bipush        23
     246: if_icmpne     253
     249: iconst_1
     250: goto          254
     253: iconst_0
     254: ifne          267
     257: new           #63                 // class java/lang/IllegalStateException
     260: dup
     261: ldc           #65                 // String Check failed.
     263: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     266: athrow
     267: aload_3
     268: invokevirtual #69                 // Method day6/Day6.startOfMessage:()I
     271: bipush        29
     273: if_icmpne     280
     276: iconst_1
     277: goto          281
     280: iconst_0
     281: ifne          294
     284: new           #63                 // class java/lang/IllegalStateException
     287: dup
     288: ldc           #65                 // String Check failed.
     290: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     293: athrow
     294: aload         4
     296: invokevirtual #69                 // Method day6/Day6.startOfMessage:()I
     299: bipush        26
     301: if_icmpne     308
     304: iconst_1
     305: goto          309
     308: iconst_0
     309: ifne          322
     312: new           #63                 // class java/lang/IllegalStateException
     315: dup
     316: ldc           #65                 // String Check failed.
     318: invokespecial #66                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     321: athrow
     322: ldc           #44                 // class day6/Day6
     324: ldc           #71                 // String /day6_input.txt
     326: invokevirtual #77                 // Method java/lang/Class.getResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
     329: dup
     330: ldc           #79                 // String getResourceAsStream(...)
     332: invokestatic  #26                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     335: astore        6
     337: getstatic     #85                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
     340: astore        7
     342: new           #87                 // class java/io/InputStreamReader
     345: dup
     346: aload         6
     348: aload         7
     350: invokespecial #90                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
     353: checkcast     #92                 // class java/io/Reader
     356: astore        8
     358: sipush        8192
     361: istore        9
     363: aload         8
     365: instanceof    #94                 // class java/io/BufferedReader
     368: ifeq          379
     371: aload         8
     373: checkcast     #94                 // class java/io/BufferedReader
     376: goto          390
     379: new           #94                 // class java/io/BufferedReader
     382: dup
     383: aload         8
     385: iload         9
     387: invokespecial #97                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
     390: checkcast     #92                 // class java/io/Reader
     393: invokestatic  #103                // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
     396: invokestatic  #109                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     399: checkcast     #17                 // class java/lang/String
     402: astore        5
     404: new           #44                 // class day6/Day6
     407: dup
     408: aload         5
     410: invokespecial #50                 // Method day6/Day6."<init>":(Ljava/lang/String;)V
     413: astore        6
     415: new           #111                // class java/lang/StringBuilder
     418: dup
     419: invokespecial #113                // Method java/lang/StringBuilder."<init>":()V
     422: ldc           #115                // String Part1 =
     424: invokevirtual #119                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     427: aload         6
     429: invokevirtual #61                 // Method day6/Day6.startOfPacket:()I
     432: invokevirtual #122                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     435: invokevirtual #126                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     438: getstatic     #132                // Field java/lang/System.out:Ljava/io/PrintStream;
     441: swap
     442: invokevirtual #138                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     445: new           #111                // class java/lang/StringBuilder
     448: dup
     449: invokespecial #113                // Method java/lang/StringBuilder."<init>":()V
     452: ldc           #140                // String Part2 =
     454: invokevirtual #119                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     457: aload         6
     459: invokevirtual #69                 // Method day6/Day6.startOfMessage:()I
     462: invokevirtual #122                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     465: invokevirtual #126                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     468: getstatic     #132                // Field java/lang/System.out:Ljava/io/PrintStream;
     471: swap
     472: invokevirtual #138                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     475: return

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


package day11

import java.lang.IllegalArgumentException

class Day11(val input: List<String>) {

    fun part1(): Long {
        val monkies = parseInput(input, true)
        println(monkies)
        val game = Game(monkies)
        (0 until 20).forEach { _ ->
            game.performRound(1)
        }

        println(game.monkies)

        return monkies.map { it.inspectCounter }.sortedDescending().take(2).reduce {a, b -> a*b}
    }

    fun part2(): Long {
        val monkies = parseInput(input, false)

        val lcm = monkies.map { it.divisor }.reduce { acc, i -> acc * i }.toLong()

        val game = Game(monkies)
        (0 until 10000).forEach { it ->
            game.performRound(lcm)
        }
        println(game.monkies)

        // 2147483647
        // 2713310158
        return monkies.map { it.inspectCounter }.sortedDescending().take(2).reduce {a, b -> a*b}
    }

    fun parseInput(input: List<String>, worryDivisor: Boolean): List<Monkey> {
        return input.chunked(7).map { toMonkey(it, worryDivisor) }
    }

    fun toMonkey(input: List<String>, worryDivisor: Boolean): Monkey {
        val id = Regex("""Monkey (\d+):""").find(input[0])!!.destructured.toList()[0].toInt()
        val startingItems = input[1].split(":")[1].trim().split(",").map { it.trim().toLong() }.toMutableList()
        val operationValues = "Operation: new = old ([*+]) ([a-zA-Z0-9]+)".toRegex().find(input[2])!!.destructured.toList()
        val operation = Operation.create(operationValues)
        val divisor = "Test: divisible by ([0-9]+)".toRegex().find(input[3])!!.destructured.toList()[0].toInt()
        val trueMonkey = "If true: throw to monkey ([0-9]+)".toRegex().find(input[4])!!.destructured.toList()[0].toInt()
        val falseMonkey = "If false: throw to monkey ([0-9]+)".toRegex().find(input[5])!!.destructured.toList()[0].toInt()

        return Monkey(id, startingItems, divisor, worryDivisor, operation::calculate) { input ->
            if (input) {
                trueMonkey
            } else {
                falseMonkey
            }
        }
    }
}

sealed class Operation {
    abstract fun calculate(old: Long): Long
    data class MultiplyWithNumber(val number: Long): Operation() {
        override fun calculate(old: Long): Long {
            return old * number
        }
    }

    object MultiplyWithOld: Operation() {
        override fun calculate(old: Long): Long {
            return old * old
        }
    }

    data class PlusWithNumber(val number: Long): Operation() {
        override fun calculate(old: Long): Long {
            return old + number
        }
    }

    object PlusWithOld: Operation() {
        override fun calculate(old: Long): Long {
            return old + old
        }
    }

    companion object {
        fun create(operationValues: List<String>): Operation {
            val operand = operationValues[0]
            val factor = operationValues[1]
            return when (operand) {
                "*" -> if (factor == "old") {
                    MultiplyWithOld
                } else {
                    MultiplyWithNumber(factor.toLong())
                }

                "+" -> if (factor == "old") {
                    PlusWithOld
                } else {
                    PlusWithNumber(factor.toLong())
                }

                else -> throw IllegalArgumentException("could not parse operation: $operationValues")
            }
        }
    }
}

class Game(val monkies: List<Monkey>) {
    fun performRound(lcm: Long) {
        monkies.forEach {
            it.performAction(monkies, lcm)
        }
    }
}

class Monkey(
    val id: Int,
    val items: MutableList<Long>,
    val divisor: Int,
    val worryDivisor: Boolean,
    val operation: (Long) -> Long,
    val monkeyChooser: (Boolean) -> Int
) {
    var inspectCounter = 0L

    fun performAction(monkies: List<Monkey>, lcm: Long) {
        val iterator = items.iterator()
        while (iterator.hasNext()) {
            inspectCounter++
            val item = iterator.next()
            val newWorryLevel = operation.invoke(item)
            val boredWorryLevel = if (worryDivisor) {
                newWorryLevel / 3
            } else {
                newWorryLevel % lcm
            }
            val monkeyReceiverId = monkeyChooser.invoke(boredWorryLevel % divisor == 0L)
            monkies[monkeyReceiverId].receive(boredWorryLevel)
            iterator.remove()
        }
    }

    fun receive(value: Long) {
        items.add(value)
    }

    override fun toString(): String {
        return "Monkey$id: inpsectCounter=$inspectCounter. '${items}'"
    }
}

fun main() {
    val testInput = Day11::class.java.getResourceAsStream("/day11_test.txt").bufferedReader().readLines()
    val input = Day11::class.java.getResourceAsStream("/day11_input.txt").bufferedReader().readLines()

    val day11test = Day11(testInput)
    val day11input = Day11(input)

    println("Day11 part 1 test result: ${day11test.part1()}")
    println("Day11 part 1 result: ${day11input.part1()}")
    println("Day11 part 2 test result: ${day11test.part2()}")
    println("Day11 part 2 result: ${day11input.part2()}")
}

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

  public day11.Day11(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #22                 // Field input:Ljava/util/List;
      15: return

  public final java.util.List<java.lang.String> getInput();
    Code:
       0: aload_0
       1: getfield      #22                 // Field input:Ljava/util/List;
       4: areturn

  public final long part1();
    Code:
       0: aload_0
       1: aload_0
       2: getfield      #22                 // Field input:Ljava/util/List;
       5: iconst_1
       6: invokevirtual #33                 // Method parseInput:(Ljava/util/List;Z)Ljava/util/List;
       9: astore_1
      10: getstatic     #39                 // Field java/lang/System.out:Ljava/io/PrintStream;
      13: aload_1
      14: invokevirtual #45                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      17: new           #47                 // class day11/Game
      20: dup
      21: aload_1
      22: invokespecial #49                 // Method day11/Game."<init>":(Ljava/util/List;)V
      25: astore_2
      26: iconst_0
      27: bipush        20
      29: invokestatic  #55                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      32: checkcast     #57                 // class java/lang/Iterable
      35: astore_3
      36: iconst_0
      37: istore        4
      39: aload_3
      40: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        5
      47: aload         5
      49: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          80
      57: aload         5
      59: checkcast     #69                 // class kotlin/collections/IntIterator
      62: invokevirtual #73                 // Method kotlin/collections/IntIterator.nextInt:()I
      65: istore        6
      67: iconst_0
      68: istore        8
      70: aload_2
      71: lconst_1
      72: invokevirtual #77                 // Method day11/Game.performRound:(J)V
      75: nop
      76: nop
      77: goto          47
      80: nop
      81: aload_2
      82: invokevirtual #80                 // Method day11/Game.getMonkies:()Ljava/util/List;
      85: getstatic     #39                 // Field java/lang/System.out:Ljava/io/PrintStream;
      88: swap
      89: invokevirtual #45                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      92: aload_1
      93: checkcast     #57                 // class java/lang/Iterable
      96: astore_3
      97: iconst_0
      98: istore        4
     100: aload_3
     101: astore        5
     103: new           #82                 // class java/util/ArrayList
     106: dup
     107: aload_3
     108: bipush        10
     110: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     113: invokespecial #91                 // Method java/util/ArrayList."<init>":(I)V
     116: checkcast     #93                 // class java/util/Collection
     119: astore        6
     121: iconst_0
     122: istore        7
     124: aload         5
     126: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     131: astore        8
     133: aload         8
     135: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     140: ifeq          186
     143: aload         8
     145: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     150: astore        9
     152: aload         6
     154: aload         9
     156: checkcast     #99                 // class day11/Monkey
     159: astore        10
     161: astore        12
     163: iconst_0
     164: istore        11
     166: aload         10
     168: invokevirtual #102                // Method day11/Monkey.getInspectCounter:()J
     171: invokestatic  #108                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     174: aload         12
     176: swap
     177: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     182: pop
     183: goto          133
     186: aload         6
     188: checkcast     #114                // class java/util/List
     191: nop
     192: checkcast     #57                 // class java/lang/Iterable
     195: invokestatic  #118                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     198: checkcast     #57                 // class java/lang/Iterable
     201: iconst_2
     202: invokestatic  #122                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     205: checkcast     #57                 // class java/lang/Iterable
     208: astore_3
     209: iconst_0
     210: istore        4
     212: aload_3
     213: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     218: astore        5
     220: aload         5
     222: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     227: ifne          240
     230: new           #124                // class java/lang/UnsupportedOperationException
     233: dup
     234: ldc           #126                // String Empty collection can\'t be reduced.
     236: invokespecial #129                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     239: athrow
     240: aload         5
     242: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     247: astore        6
     249: aload         5
     251: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     256: ifeq          300
     259: aload         6
     261: aload         5
     263: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     268: checkcast     #131                // class java/lang/Number
     271: invokevirtual #134                // Method java/lang/Number.longValue:()J
     274: lstore        7
     276: checkcast     #131                // class java/lang/Number
     279: invokevirtual #134                // Method java/lang/Number.longValue:()J
     282: lstore        9
     284: iconst_0
     285: istore        11
     287: lload         9
     289: lload         7
     291: lmul
     292: invokestatic  #108                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     295: astore        6
     297: goto          249
     300: aload         6
     302: checkcast     #131                // class java/lang/Number
     305: invokevirtual #134                // Method java/lang/Number.longValue:()J
     308: lreturn

  public final long part2();
    Code:
       0: aload_0
       1: aload_0
       2: getfield      #22                 // Field input:Ljava/util/List;
       5: iconst_0
       6: invokevirtual #33                 // Method parseInput:(Ljava/util/List;Z)Ljava/util/List;
       9: astore_1
      10: aload_1
      11: checkcast     #57                 // class java/lang/Iterable
      14: astore        4
      16: iconst_0
      17: istore        5
      19: aload         4
      21: astore        6
      23: new           #82                 // class java/util/ArrayList
      26: dup
      27: aload         4
      29: bipush        10
      31: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #91                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #93                 // class java/util/Collection
      40: astore        7
      42: iconst_0
      43: istore        8
      45: aload         6
      47: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        9
      54: aload         9
      56: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          107
      64: aload         9
      66: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: astore        10
      73: aload         7
      75: aload         10
      77: checkcast     #99                 // class day11/Monkey
      80: astore        11
      82: astore        14
      84: iconst_0
      85: istore        12
      87: aload         11
      89: invokevirtual #167                // Method day11/Monkey.getDivisor:()I
      92: invokestatic  #172                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      95: aload         14
      97: swap
      98: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     103: pop
     104: goto          54
     107: aload         7
     109: checkcast     #114                // class java/util/List
     112: nop
     113: checkcast     #57                 // class java/lang/Iterable
     116: astore        4
     118: nop
     119: iconst_0
     120: istore        5
     122: aload         4
     124: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     129: astore        6
     131: aload         6
     133: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     138: ifne          151
     141: new           #124                // class java/lang/UnsupportedOperationException
     144: dup
     145: ldc           #126                // String Empty collection can\'t be reduced.
     147: invokespecial #129                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     150: athrow
     151: aload         6
     153: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     158: astore        7
     160: aload         6
     162: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     167: ifeq          211
     170: aload         7
     172: aload         6
     174: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     179: checkcast     #131                // class java/lang/Number
     182: invokevirtual #175                // Method java/lang/Number.intValue:()I
     185: istore        8
     187: checkcast     #131                // class java/lang/Number
     190: invokevirtual #175                // Method java/lang/Number.intValue:()I
     193: istore        9
     195: iconst_0
     196: istore        10
     198: iload         9
     200: iload         8
     202: imul
     203: invokestatic  #172                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     206: astore        7
     208: goto          160
     211: aload         7
     213: checkcast     #131                // class java/lang/Number
     216: invokevirtual #175                // Method java/lang/Number.intValue:()I
     219: i2l
     220: lstore_2
     221: new           #47                 // class day11/Game
     224: dup
     225: aload_1
     226: invokespecial #49                 // Method day11/Game."<init>":(Ljava/util/List;)V
     229: astore        4
     231: iconst_0
     232: sipush        10000
     235: invokestatic  #55                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     238: checkcast     #57                 // class java/lang/Iterable
     241: astore        5
     243: iconst_0
     244: istore        6
     246: aload         5
     248: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     253: astore        7
     255: aload         7
     257: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     262: ifeq          293
     265: aload         7
     267: checkcast     #69                 // class kotlin/collections/IntIterator
     270: invokevirtual #73                 // Method kotlin/collections/IntIterator.nextInt:()I
     273: istore        8
     275: iload         8
     277: istore        9
     279: iconst_0
     280: istore        10
     282: aload         4
     284: lload_2
     285: invokevirtual #77                 // Method day11/Game.performRound:(J)V
     288: nop
     289: nop
     290: goto          255
     293: nop
     294: aload         4
     296: invokevirtual #80                 // Method day11/Game.getMonkies:()Ljava/util/List;
     299: getstatic     #39                 // Field java/lang/System.out:Ljava/io/PrintStream;
     302: swap
     303: invokevirtual #45                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     306: aload_1
     307: checkcast     #57                 // class java/lang/Iterable
     310: astore        5
     312: iconst_0
     313: istore        6
     315: aload         5
     317: astore        7
     319: new           #82                 // class java/util/ArrayList
     322: dup
     323: aload         5
     325: bipush        10
     327: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     330: invokespecial #91                 // Method java/util/ArrayList."<init>":(I)V
     333: checkcast     #93                 // class java/util/Collection
     336: astore        8
     338: iconst_0
     339: istore        9
     341: aload         7
     343: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     348: astore        10
     350: aload         10
     352: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     357: ifeq          403
     360: aload         10
     362: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     367: astore        11
     369: aload         8
     371: aload         11
     373: checkcast     #99                 // class day11/Monkey
     376: astore        12
     378: astore        14
     380: iconst_0
     381: istore        13
     383: aload         12
     385: invokevirtual #102                // Method day11/Monkey.getInspectCounter:()J
     388: invokestatic  #108                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     391: aload         14
     393: swap
     394: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     399: pop
     400: goto          350
     403: aload         8
     405: checkcast     #114                // class java/util/List
     408: nop
     409: checkcast     #57                 // class java/lang/Iterable
     412: invokestatic  #118                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     415: checkcast     #57                 // class java/lang/Iterable
     418: iconst_2
     419: invokestatic  #122                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     422: checkcast     #57                 // class java/lang/Iterable
     425: astore        5
     427: iconst_0
     428: istore        6
     430: aload         5
     432: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     437: astore        7
     439: aload         7
     441: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     446: ifne          459
     449: new           #124                // class java/lang/UnsupportedOperationException
     452: dup
     453: ldc           #126                // String Empty collection can\'t be reduced.
     455: invokespecial #129                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     458: athrow
     459: aload         7
     461: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     466: astore        8
     468: aload         7
     470: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     475: ifeq          519
     478: aload         8
     480: aload         7
     482: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     487: checkcast     #131                // class java/lang/Number
     490: invokevirtual #134                // Method java/lang/Number.longValue:()J
     493: lstore        9
     495: checkcast     #131                // class java/lang/Number
     498: invokevirtual #134                // Method java/lang/Number.longValue:()J
     501: lstore        11
     503: iconst_0
     504: istore        13
     506: lload         11
     508: lload         9
     510: lmul
     511: invokestatic  #108                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     514: astore        8
     516: goto          468
     519: aload         8
     521: checkcast     #131                // class java/lang/Number
     524: invokevirtual #134                // Method java/lang/Number.longValue:()J
     527: lreturn

  public final java.util.List<day11.Monkey> parseInput(java.util.List<java.lang.String>, boolean);
    Code:
       0: aload_1
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #57                 // class java/lang/Iterable
      10: bipush        7
      12: invokestatic  #187                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
      15: checkcast     #57                 // class java/lang/Iterable
      18: astore_3
      19: iconst_0
      20: istore        4
      22: aload_3
      23: astore        5
      25: new           #82                 // class java/util/ArrayList
      28: dup
      29: aload_3
      30: bipush        10
      32: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      35: invokespecial #91                 // Method java/util/ArrayList."<init>":(I)V
      38: checkcast     #93                 // class java/util/Collection
      41: astore        6
      43: iconst_0
      44: istore        7
      46: aload         5
      48: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        8
      55: aload         8
      57: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          107
      65: aload         8
      67: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: astore        9
      74: aload         6
      76: aload         9
      78: checkcast     #114                // class java/util/List
      81: astore        10
      83: astore        12
      85: iconst_0
      86: istore        11
      88: aload_0
      89: aload         10
      91: iload_2
      92: invokevirtual #191                // Method toMonkey:(Ljava/util/List;Z)Lday11/Monkey;
      95: aload         12
      97: swap
      98: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     103: pop
     104: goto          55
     107: aload         6
     109: checkcast     #114                // class java/util/List
     112: nop
     113: areturn

  public final day11.Monkey toMonkey(java.util.List<java.lang.String>, boolean);
    Code:
       0: aload_1
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #197                // class kotlin/text/Regex
       9: dup
      10: ldc           #199                // String Monkey (\\d+):
      12: invokespecial #200                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: aload_1
      16: iconst_0
      17: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      22: checkcast     #206                // class java/lang/CharSequence
      25: iconst_0
      26: iconst_2
      27: aconst_null
      28: invokestatic  #210                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      31: dup
      32: invokestatic  #213                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      35: invokeinterface #219,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      40: invokevirtual #224                // Method kotlin/text/MatchResult$Destructured.toList:()Ljava/util/List;
      43: iconst_0
      44: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      49: checkcast     #226                // class java/lang/String
      52: invokestatic  #230                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      55: istore_3
      56: aload_1
      57: iconst_1
      58: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      63: checkcast     #206                // class java/lang/CharSequence
      66: iconst_1
      67: anewarray     #226                // class java/lang/String
      70: astore        5
      72: aload         5
      74: iconst_0
      75: ldc           #232                // String :
      77: aastore
      78: aload         5
      80: iconst_0
      81: iconst_0
      82: bipush        6
      84: aconst_null
      85: invokestatic  #238                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      88: iconst_1
      89: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      94: checkcast     #226                // class java/lang/String
      97: checkcast     #206                // class java/lang/CharSequence
     100: invokestatic  #242                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     103: invokevirtual #246                // Method java/lang/Object.toString:()Ljava/lang/String;
     106: checkcast     #206                // class java/lang/CharSequence
     109: iconst_1
     110: anewarray     #226                // class java/lang/String
     113: astore        5
     115: aload         5
     117: iconst_0
     118: ldc           #248                // String ,
     120: aastore
     121: aload         5
     123: iconst_0
     124: iconst_0
     125: bipush        6
     127: aconst_null
     128: invokestatic  #238                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     131: checkcast     #57                 // class java/lang/Iterable
     134: astore        5
     136: iconst_0
     137: istore        6
     139: aload         5
     141: astore        7
     143: new           #82                 // class java/util/ArrayList
     146: dup
     147: aload         5
     149: bipush        10
     151: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     154: invokespecial #91                 // Method java/util/ArrayList."<init>":(I)V
     157: checkcast     #93                 // class java/util/Collection
     160: astore        8
     162: iconst_0
     163: istore        9
     165: aload         7
     167: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     172: astore        10
     174: aload         10
     176: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     181: ifeq          238
     184: aload         10
     186: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     191: astore        11
     193: aload         8
     195: aload         11
     197: checkcast     #226                // class java/lang/String
     200: astore        12
     202: astore        14
     204: iconst_0
     205: istore        13
     207: nop
     208: aload         12
     210: checkcast     #206                // class java/lang/CharSequence
     213: invokestatic  #242                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     216: invokevirtual #246                // Method java/lang/Object.toString:()Ljava/lang/String;
     219: invokestatic  #252                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     222: nop
     223: invokestatic  #108                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     226: aload         14
     228: swap
     229: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     234: pop
     235: goto          174
     238: aload         8
     240: checkcast     #114                // class java/util/List
     243: nop
     244: checkcast     #93                 // class java/util/Collection
     247: invokestatic  #256                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     250: astore        4
     252: new           #197                // class kotlin/text/Regex
     255: dup
     256: ldc_w         #258                // String Operation: new = old ([*+]) ([a-zA-Z0-9]+)
     259: invokespecial #200                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     262: aload_1
     263: iconst_2
     264: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     269: checkcast     #206                // class java/lang/CharSequence
     272: iconst_0
     273: iconst_2
     274: aconst_null
     275: invokestatic  #210                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     278: dup
     279: invokestatic  #213                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     282: invokeinterface #219,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     287: invokevirtual #224                // Method kotlin/text/MatchResult$Destructured.toList:()Ljava/util/List;
     290: astore        5
     292: getstatic     #264                // Field day11/Operation.Companion:Lday11/Operation$Companion;
     295: aload         5
     297: invokevirtual #270                // Method day11/Operation$Companion.create:(Ljava/util/List;)Lday11/Operation;
     300: astore        6
     302: new           #197                // class kotlin/text/Regex
     305: dup
     306: ldc_w         #272                // String Test: divisible by ([0-9]+)
     309: invokespecial #200                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     312: aload_1
     313: iconst_3
     314: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     319: checkcast     #206                // class java/lang/CharSequence
     322: iconst_0
     323: iconst_2
     324: aconst_null
     325: invokestatic  #210                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     328: dup
     329: invokestatic  #213                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     332: invokeinterface #219,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     337: invokevirtual #224                // Method kotlin/text/MatchResult$Destructured.toList:()Ljava/util/List;
     340: iconst_0
     341: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     346: checkcast     #226                // class java/lang/String
     349: invokestatic  #230                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     352: istore        7
     354: new           #197                // class kotlin/text/Regex
     357: dup
     358: ldc_w         #274                // String If true: throw to monkey ([0-9]+)
     361: invokespecial #200                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     364: aload_1
     365: iconst_4
     366: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     371: checkcast     #206                // class java/lang/CharSequence
     374: iconst_0
     375: iconst_2
     376: aconst_null
     377: invokestatic  #210                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     380: dup
     381: invokestatic  #213                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     384: invokeinterface #219,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     389: invokevirtual #224                // Method kotlin/text/MatchResult$Destructured.toList:()Ljava/util/List;
     392: iconst_0
     393: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     398: checkcast     #226                // class java/lang/String
     401: invokestatic  #230                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     404: istore        8
     406: new           #197                // class kotlin/text/Regex
     409: dup
     410: ldc_w         #276                // String If false: throw to monkey ([0-9]+)
     413: invokespecial #200                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     416: aload_1
     417: iconst_5
     418: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     423: checkcast     #206                // class java/lang/CharSequence
     426: iconst_0
     427: iconst_2
     428: aconst_null
     429: invokestatic  #210                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     432: dup
     433: invokestatic  #213                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     436: invokeinterface #219,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     441: invokevirtual #224                // Method kotlin/text/MatchResult$Destructured.toList:()Ljava/util/List;
     444: iconst_0
     445: invokeinterface #204,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     450: checkcast     #226                // class java/lang/String
     453: invokestatic  #230                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     456: istore        9
     458: new           #99                 // class day11/Monkey
     461: dup
     462: iload_3
     463: aload         4
     465: iload         7
     467: iload_2
     468: new           #278                // class day11/Day11$toMonkey$1
     471: dup
     472: aload         6
     474: invokespecial #280                // Method day11/Day11$toMonkey$1."<init>":(Ljava/lang/Object;)V
     477: checkcast     #282                // class kotlin/jvm/functions/Function1
     480: iload         8
     482: iload         9
     484: invokedynamic #302,  0            // InvokeDynamic #0:invoke:(II)Lkotlin/jvm/functions/Function1;
     489: invokespecial #305                // Method day11/Monkey."<init>":(ILjava/util/List;IZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
     492: areturn

  private static final int toMonkey$lambda$10(int, int, boolean);
    Code:
       0: iload_2
       1: ifeq          8
       4: iload_0
       5: goto          9
       8: iload_1
       9: ireturn
}

Compiled from "Day11.kt"
final class day11.Day11$toMonkey$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.Long, java.lang.Long> {
  day11.Day11$toMonkey$1(java.lang.Object);
    Code:
       0: aload_0
       1: iconst_1
       2: aload_1
       3: ldc           #11                 // class day11/Operation
       5: ldc           #13                 // String calculate
       7: ldc           #15                 // String calculate(J)J
       9: iconst_0
      10: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Long invoke(long);
    Code:
       0: aload_0
       1: getfield      #26                 // Field receiver:Ljava/lang/Object;
       4: checkcast     #11                 // class day11/Operation
       7: lload_1
       8: invokevirtual #29                 // Method day11/Operation.calculate:(J)J
      11: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      14: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #39                 // class java/lang/Number
       5: invokevirtual #43                 // Method java/lang/Number.longValue:()J
       8: invokevirtual #45                 // Method invoke:(J)Ljava/lang/Long;
      11: areturn
}

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

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