package day17

import Point
import day17.Direction.DOWN
import day17.Direction.LEFT
import day17.Direction.RIGHT
import findPattern
import readInput
import second

const val leftWall = 0
const val rightWall = 6

typealias TetrisCave = MutableSet<Point>
typealias TetrisRock = Set<Point>

data class Jets(val jets: List<Direction>) {
    private var index = 0
    fun next() = jets[index++ % jets.size]
}

enum class Direction {
    DOWN, LEFT, RIGHT
}

val fallingRocks = listOf(
    setOf(Point(0, 0), Point(1, 0), Point(2, 0), Point(3, 0)),
    setOf(Point(1, 0), Point(0, 1), Point(1, 1), Point(2, 1), Point(1, 2)),
    setOf(Point(0, 0), Point(1, 0), Point(2, 0), Point(2, 1), Point(2, 2)),
    setOf(Point(0, 0), Point(0, 1), Point(0, 2), Point(0, 3)),
    setOf(Point(0, 0), Point(1, 0), Point(0, 1), Point(1, 1))
)

fun main() {
    val input = readInput("main/day17/Day17")
    val heightDiffs = heightDiffs(input)
    val (rocksBeforePattern, patternSize) = heightDiffs.findPattern(1650)
    println("$rocksBeforePattern, $patternSize")

    println("Part1: ${solve(heightDiffs, rocksBeforePattern, patternSize, 2022)}")
    println("Part1: ${solve(heightDiffs, rocksBeforePattern, patternSize, 1000000000000L)}")
}

private fun solve(heightDiffs: List<Int>, rocksBeforePattern: Int, patternSize: Int, numberOfRocks: Long): Long {
    val rocksLeft = numberOfRocks - rocksBeforePattern

    val pattern = heightDiffs.drop(rocksBeforePattern - 1).take(patternSize)
    val patternSum = pattern.sum()

    return heightDiffs.take(rocksBeforePattern).sum() +
            (rocksLeft / patternSize * patternSum +
                    pattern.take((rocksLeft - rocksLeft / patternSize * patternSize).toInt()).sum())
}

fun heightDiffs(input: List<String>): List<Int> {
    val cave = emptyCaveWithFloor()
    val jets = input.first().parse()
    return (0..5000).map {
        var rock = cave.nextRock(shapeFor(it))
        do {
            rock = cave.moveRock(rock, jets.next()).first
            val result = cave.moveRock(rock, DOWN)
            rock = result.first
        } while (result.second)
        cave.addAll(rock)
        cave.height()
    }.windowed(2).map { (it.second() - it.first()).toInt() }
}

private fun shapeFor(it: Int) = fallingRocks[it % fallingRocks.size]

private fun emptyCaveWithFloor() = mutableSetOf(
    Point(0, 0),
    Point(1, 0),
    Point(2, 0),
    Point(3, 0),
    Point(4, 0),
    Point(5, 0),
    Point(6, 0),
)

private fun TetrisCave.height() = maxOf { it.y }.toLong()

fun TetrisCave.moveRock(rock: TetrisRock, direction: Direction): Pair<TetrisRock, Boolean> {
    var movedRock: TetrisRock = rock
    var rockMoved = false
    when (direction) {
        DOWN -> {
            val probedRock = rock.map { Point(it.x, it.y - 1) }
            if (probedRock.none { this.contains(it) }) {
                movedRock = probedRock.toSet()
                rockMoved = true
            }
        }

        LEFT -> {
            val probedRock = rock.map { Point(it.x - 1, it.y) }
            if (probedRock.none { this.contains(it) || it.x < leftWall }) {
                movedRock = probedRock.toSet()
                rockMoved = true
            }
        }

        RIGHT -> {
            val probedRock = rock.map { Point(it.x + 1, it.y) }
            if (probedRock.none { this.contains(it) || it.x > rightWall }) {
                movedRock = probedRock.toSet()
                rockMoved = true
            }
        }
    }
    return movedRock to rockMoved
}

fun TetrisCave.nextRock(rock: TetrisRock): TetrisRock {
    val xOffset = 2
    val yOffset = maxOf { it.y } + 4
    return rock.map { Point(it.x + xOffset, it.y + yOffset) }.toSet()
}

fun String.parse(): Jets = map {
    when (it) {
        '<' -> LEFT
        '>' -> RIGHT
        else -> error("illegal input")
    }
}.let { Jets(it) }

Compiled from "day17.kt"
public final class day17.Day17Kt$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method day17/Direction.values:()[Lday17/Direction;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field day17/Direction.DOWN:Lday17/Direction;
      12: invokevirtual #22                 // Method day17/Direction.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field day17/Direction.LEFT:Lday17/Direction;
      26: invokevirtual #22                 // Method day17/Direction.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field day17/Direction.RIGHT:Lday17/Direction;
      40: invokevirtual #22                 // Method day17/Direction.ordinal:()I
      43: iconst_3
      44: iastore
      45: goto          49
      48: astore_1
      49: aload_0
      50: putstatic     #32                 // Field $EnumSwitchMapping$0:[I
      53: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
          35    45    48   Class java/lang/NoSuchFieldError
}

Compiled from "day17.kt"
public final class day17.Day17Kt {
  public static final int leftWall;

  public static final int rightWall;

  private static final java.util.List<java.util.Set<Point>> fallingRocks;

  public static final java.util.List<java.util.Set<Point>> getFallingRocks();
    Code:
       0: getstatic     #12                 // Field fallingRocks:Ljava/util/List;
       3: areturn

  public static final void main();
    Code:
       0: ldc           #16                 // String main/day17/Day17
       2: invokestatic  #22                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #26                 // Method heightDiffs:(Ljava/util/List;)Ljava/util/List;
      10: astore_1
      11: aload_1
      12: sipush        1650
      15: invokestatic  #30                 // Method UtilsKt.findPattern:(Ljava/util/List;I)Lkotlin/Pair;
      18: astore_2
      19: aload_2
      20: invokevirtual #36                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
      23: checkcast     #38                 // class java/lang/Number
      26: invokevirtual #42                 // Method java/lang/Number.intValue:()I
      29: istore_3
      30: aload_2
      31: invokevirtual #45                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
      34: checkcast     #38                 // class java/lang/Number
      37: invokevirtual #42                 // Method java/lang/Number.intValue:()I
      40: istore        4
      42: new           #47                 // class java/lang/StringBuilder
      45: dup
      46: invokespecial #50                 // Method java/lang/StringBuilder."<init>":()V
      49: iload_3
      50: invokevirtual #54                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      53: ldc           #56                 // String ,
      55: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      58: iload         4
      60: invokevirtual #54                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      63: invokevirtual #63                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      66: getstatic     #69                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: swap
      70: invokevirtual #75                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      73: new           #47                 // class java/lang/StringBuilder
      76: dup
      77: invokespecial #50                 // Method java/lang/StringBuilder."<init>":()V
      80: ldc           #77                 // String Part1:
      82: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      85: aload_1
      86: iload_3
      87: iload         4
      89: ldc2_w        #78                 // long 2022l
      92: invokestatic  #83                 // Method solve:(Ljava/util/List;IIJ)J
      95: invokevirtual #86                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      98: invokevirtual #63                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     101: getstatic     #69                 // Field java/lang/System.out:Ljava/io/PrintStream;
     104: swap
     105: invokevirtual #75                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     108: new           #47                 // class java/lang/StringBuilder
     111: dup
     112: invokespecial #50                 // Method java/lang/StringBuilder."<init>":()V
     115: ldc           #77                 // String Part1:
     117: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     120: aload_1
     121: iload_3
     122: iload         4
     124: ldc2_w        #87                 // long 1000000000000l
     127: invokestatic  #83                 // Method solve:(Ljava/util/List;IIJ)J
     130: invokevirtual #86                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     133: invokevirtual #63                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     136: getstatic     #69                 // Field java/lang/System.out:Ljava/io/PrintStream;
     139: swap
     140: invokevirtual #75                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     143: return

  private static final long solve(java.util.List<java.lang.Integer>, int, int, long);
    Code:
       0: lload_3
       1: iload_1
       2: i2l
       3: lsub
       4: lstore        5
       6: aload_0
       7: checkcast     #95                 // class java/lang/Iterable
      10: iload_1
      11: iconst_1
      12: isub
      13: invokestatic  #101                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      16: checkcast     #95                 // class java/lang/Iterable
      19: iload_2
      20: invokestatic  #104                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      23: astore        7
      25: aload         7
      27: checkcast     #95                 // class java/lang/Iterable
      30: invokestatic  #108                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      33: istore        8
      35: aload_0
      36: checkcast     #95                 // class java/lang/Iterable
      39: iload_1
      40: invokestatic  #104                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      43: checkcast     #95                 // class java/lang/Iterable
      46: invokestatic  #108                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      49: i2l
      50: lload         5
      52: iload_2
      53: i2l
      54: ldiv
      55: iload         8
      57: i2l
      58: lmul
      59: aload         7
      61: checkcast     #95                 // class java/lang/Iterable
      64: lload         5
      66: lload         5
      68: iload_2
      69: i2l
      70: ldiv
      71: iload_2
      72: i2l
      73: lmul
      74: lsub
      75: l2i
      76: invokestatic  #104                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      79: checkcast     #95                 // class java/lang/Iterable
      82: invokestatic  #108                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      85: i2l
      86: ladd
      87: ladd
      88: lreturn

  public static final java.util.List<java.lang.Integer> heightDiffs(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #115                // String input
       3: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: invokestatic  #125                // Method emptyCaveWithFloor:()Ljava/util/Set;
       9: astore_1
      10: aload_0
      11: invokestatic  #129                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      14: checkcast     #131                // class java/lang/String
      17: invokestatic  #135                // Method parse:(Ljava/lang/String;)Lday17/Jets;
      20: astore_2
      21: new           #137                // class kotlin/ranges/IntRange
      24: dup
      25: iconst_0
      26: sipush        5000
      29: invokespecial #140                // Method kotlin/ranges/IntRange."<init>":(II)V
      32: checkcast     #95                 // class java/lang/Iterable
      35: astore_3
      36: iconst_0
      37: istore        4
      39: aload_3
      40: astore        5
      42: new           #142                // class java/util/ArrayList
      45: dup
      46: aload_3
      47: bipush        10
      49: invokestatic  #146                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      52: invokespecial #149                // Method java/util/ArrayList."<init>":(I)V
      55: checkcast     #151                // class java/util/Collection
      58: astore        6
      60: iconst_0
      61: istore        7
      63: aload         5
      65: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      70: astore        8
      72: aload         8
      74: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      79: ifeq          198
      82: aload         8
      84: checkcast     #163                // class kotlin/collections/IntIterator
      87: invokevirtual #166                // Method kotlin/collections/IntIterator.nextInt:()I
      90: istore        9
      92: aload         6
      94: iload         9
      96: istore        10
      98: astore        14
     100: iconst_0
     101: istore        11
     103: aload_1
     104: iload         10
     106: invokestatic  #170                // Method shapeFor:(I)Ljava/util/Set;
     109: invokestatic  #174                // Method nextRock:(Ljava/util/Set;Ljava/util/Set;)Ljava/util/Set;
     112: astore        12
     114: aload_1
     115: aload         12
     117: aload_2
     118: invokevirtual #180                // Method day17/Jets.next:()Lday17/Direction;
     121: invokestatic  #184                // Method moveRock:(Ljava/util/Set;Ljava/util/Set;Lday17/Direction;)Lkotlin/Pair;
     124: invokevirtual #187                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     127: checkcast     #189                // class java/util/Set
     130: astore        12
     132: aload_1
     133: aload         12
     135: getstatic     #195                // Field day17/Direction.DOWN:Lday17/Direction;
     138: invokestatic  #184                // Method moveRock:(Ljava/util/Set;Ljava/util/Set;Lday17/Direction;)Lkotlin/Pair;
     141: astore        13
     143: aload         13
     145: invokevirtual #187                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     148: checkcast     #189                // class java/util/Set
     151: astore        12
     153: aload         13
     155: invokevirtual #198                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     158: checkcast     #200                // class java/lang/Boolean
     161: invokevirtual #203                // Method java/lang/Boolean.booleanValue:()Z
     164: ifne          114
     167: aload_1
     168: aload         12
     170: checkcast     #151                // class java/util/Collection
     173: invokeinterface #207,  2          // InterfaceMethod java/util/Set.addAll:(Ljava/util/Collection;)Z
     178: pop
     179: aload_1
     180: invokestatic  #211                // Method height:(Ljava/util/Set;)J
     183: invokestatic  #217                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     186: aload         14
     188: swap
     189: invokeinterface #221,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     194: pop
     195: goto          72
     198: aload         6
     200: checkcast     #223                // class java/util/List
     203: nop
     204: checkcast     #95                 // class java/lang/Iterable
     207: iconst_2
     208: iconst_0
     209: iconst_0
     210: bipush        6
     212: aconst_null
     213: invokestatic  #227                // Method kotlin/collections/CollectionsKt.windowed$default:(Ljava/lang/Iterable;IIZILjava/lang/Object;)Ljava/util/List;
     216: checkcast     #95                 // class java/lang/Iterable
     219: astore_3
     220: iconst_0
     221: istore        4
     223: aload_3
     224: astore        5
     226: new           #142                // class java/util/ArrayList
     229: dup
     230: aload_3
     231: bipush        10
     233: invokestatic  #146                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     236: invokespecial #149                // Method java/util/ArrayList."<init>":(I)V
     239: checkcast     #151                // class java/util/Collection
     242: astore        6
     244: iconst_0
     245: istore        7
     247: aload         5
     249: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     254: astore        8
     256: aload         8
     258: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     263: ifeq          328
     266: aload         8
     268: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     273: astore        9
     275: aload         6
     277: aload         9
     279: checkcast     #223                // class java/util/List
     282: astore        10
     284: astore        14
     286: iconst_0
     287: istore        11
     289: aload         10
     291: invokestatic  #232                // Method UtilsKt.second:(Ljava/util/List;)Ljava/lang/Object;
     294: checkcast     #38                 // class java/lang/Number
     297: invokevirtual #236                // Method java/lang/Number.longValue:()J
     300: aload         10
     302: invokestatic  #129                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     305: checkcast     #38                 // class java/lang/Number
     308: invokevirtual #236                // Method java/lang/Number.longValue:()J
     311: lsub
     312: l2i
     313: invokestatic  #241                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     316: aload         14
     318: swap
     319: invokeinterface #221,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     324: pop
     325: goto          256
     328: aload         6
     330: checkcast     #223                // class java/util/List
     333: nop
     334: areturn

  private static final java.util.Set<Point> shapeFor(int);
    Code:
       0: getstatic     #12                 // Field fallingRocks:Ljava/util/List;
       3: iload_0
       4: getstatic     #12                 // Field fallingRocks:Ljava/util/List;
       7: invokeinterface #264,  1          // InterfaceMethod java/util/List.size:()I
      12: irem
      13: invokeinterface #268,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      18: checkcast     #189                // class java/util/Set
      21: areturn

  private static final java.util.Set<Point> emptyCaveWithFloor();
    Code:
       0: bipush        7
       2: anewarray     #271                // class Point
       5: astore_0
       6: aload_0
       7: iconst_0
       8: new           #271                // class Point
      11: dup
      12: iconst_0
      13: iconst_0
      14: invokespecial #272                // Method Point."<init>":(II)V
      17: aastore
      18: aload_0
      19: iconst_1
      20: new           #271                // class Point
      23: dup
      24: iconst_1
      25: iconst_0
      26: invokespecial #272                // Method Point."<init>":(II)V
      29: aastore
      30: aload_0
      31: iconst_2
      32: new           #271                // class Point
      35: dup
      36: iconst_2
      37: iconst_0
      38: invokespecial #272                // Method Point."<init>":(II)V
      41: aastore
      42: aload_0
      43: iconst_3
      44: new           #271                // class Point
      47: dup
      48: iconst_3
      49: iconst_0
      50: invokespecial #272                // Method Point."<init>":(II)V
      53: aastore
      54: aload_0
      55: iconst_4
      56: new           #271                // class Point
      59: dup
      60: iconst_4
      61: iconst_0
      62: invokespecial #272                // Method Point."<init>":(II)V
      65: aastore
      66: aload_0
      67: iconst_5
      68: new           #271                // class Point
      71: dup
      72: iconst_5
      73: iconst_0
      74: invokespecial #272                // Method Point."<init>":(II)V
      77: aastore
      78: aload_0
      79: bipush        6
      81: new           #271                // class Point
      84: dup
      85: bipush        6
      87: iconst_0
      88: invokespecial #272                // Method Point."<init>":(II)V
      91: aastore
      92: aload_0
      93: invokestatic  #278                // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
      96: areturn

  private static final long height(java.util.Set<Point>);
    Code:
       0: aload_0
       1: checkcast     #95                 // class java/lang/Iterable
       4: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: astore_1
      10: aload_1
      11: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      16: ifne          27
      19: new           #281                // class java/util/NoSuchElementException
      22: dup
      23: invokespecial #282                // Method java/util/NoSuchElementException."<init>":()V
      26: athrow
      27: aload_1
      28: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #271                // class Point
      36: astore_2
      37: iconst_0
      38: istore_3
      39: aload_2
      40: invokevirtual #285                // Method Point.getY:()I
      43: istore_2
      44: aload_1
      45: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          81
      53: aload_1
      54: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: checkcast     #271                // class Point
      62: astore_3
      63: iconst_0
      64: istore        4
      66: aload_3
      67: invokevirtual #285                // Method Point.getY:()I
      70: istore_3
      71: iload_2
      72: iload_3
      73: if_icmpge     44
      76: iload_3
      77: istore_2
      78: goto          44
      81: iload_2
      82: i2l
      83: lreturn

  public static final kotlin.Pair<java.util.Set<Point>, java.lang.Boolean> moveRock(java.util.Set<Point>, java.util.Set<Point>, day17.Direction);
    Code:
       0: aload_0
       1: ldc_w         #291                // String <this>
       4: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: ldc_w         #292                // String rock
      11: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_2
      15: ldc_w         #294                // String direction
      18: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      21: aload_1
      22: astore_3
      23: iconst_0
      24: istore        4
      26: aload_2
      27: getstatic     #300                // Field day17/Day17Kt$WhenMappings.$EnumSwitchMapping$0:[I
      30: swap
      31: invokevirtual #303                // Method day17/Direction.ordinal:()I
      34: iaload
      35: tableswitch   { // 1 to 3
                     1: 60
                     2: 283
                     3: 522
               default: 763
          }
      60: aload_1
      61: checkcast     #95                 // class java/lang/Iterable
      64: astore        6
      66: iconst_0
      67: istore        7
      69: aload         6
      71: astore        8
      73: new           #142                // class java/util/ArrayList
      76: dup
      77: aload         6
      79: bipush        10
      81: invokestatic  #146                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      84: invokespecial #149                // Method java/util/ArrayList."<init>":(I)V
      87: checkcast     #151                // class java/util/Collection
      90: astore        9
      92: iconst_0
      93: istore        10
      95: aload         8
      97: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     102: astore        11
     104: aload         11
     106: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     111: ifeq          168
     114: aload         11
     116: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     121: astore        12
     123: aload         9
     125: aload         12
     127: checkcast     #271                // class Point
     130: astore        13
     132: astore        15
     134: iconst_0
     135: istore        14
     137: new           #271                // class Point
     140: dup
     141: aload         13
     143: invokevirtual #306                // Method Point.getX:()I
     146: aload         13
     148: invokevirtual #285                // Method Point.getY:()I
     151: iconst_1
     152: isub
     153: invokespecial #272                // Method Point."<init>":(II)V
     156: aload         15
     158: swap
     159: invokeinterface #221,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     164: pop
     165: goto          104
     168: aload         9
     170: checkcast     #223                // class java/util/List
     173: nop
     174: astore        5
     176: aload         5
     178: checkcast     #95                 // class java/lang/Iterable
     181: astore        6
     183: iconst_0
     184: istore        7
     186: aload         6
     188: instanceof    #151                // class java/util/Collection
     191: ifeq          211
     194: aload         6
     196: checkcast     #151                // class java/util/Collection
     199: invokeinterface #309,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     204: ifeq          211
     207: iconst_1
     208: goto          265
     211: aload         6
     213: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     218: astore        8
     220: aload         8
     222: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     227: ifeq          264
     230: aload         8
     232: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     237: astore        9
     239: aload         9
     241: checkcast     #271                // class Point
     244: astore        10
     246: iconst_0
     247: istore        11
     249: aload_0
     250: aload         10
     252: invokeinterface #312,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     257: ifeq          220
     260: iconst_0
     261: goto          265
     264: iconst_1
     265: ifeq          771
     268: aload         5
     270: checkcast     #95                 // class java/lang/Iterable
     273: invokestatic  #316                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     276: astore_3
     277: iconst_1
     278: istore        4
     280: goto          771
     283: aload_1
     284: checkcast     #95                 // class java/lang/Iterable
     287: astore        6
     289: iconst_0
     290: istore        7
     292: aload         6
     294: astore        8
     296: new           #142                // class java/util/ArrayList
     299: dup
     300: aload         6
     302: bipush        10
     304: invokestatic  #146                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     307: invokespecial #149                // Method java/util/ArrayList."<init>":(I)V
     310: checkcast     #151                // class java/util/Collection
     313: astore        9
     315: iconst_0
     316: istore        10
     318: aload         8
     320: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     325: astore        11
     327: aload         11
     329: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     334: ifeq          391
     337: aload         11
     339: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     344: astore        12
     346: aload         9
     348: aload         12
     350: checkcast     #271                // class Point
     353: astore        13
     355: astore        15
     357: iconst_0
     358: istore        14
     360: new           #271                // class Point
     363: dup
     364: aload         13
     366: invokevirtual #306                // Method Point.getX:()I
     369: iconst_1
     370: isub
     371: aload         13
     373: invokevirtual #285                // Method Point.getY:()I
     376: invokespecial #272                // Method Point."<init>":(II)V
     379: aload         15
     381: swap
     382: invokeinterface #221,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     387: pop
     388: goto          327
     391: aload         9
     393: checkcast     #223                // class java/util/List
     396: nop
     397: astore        5
     399: aload         5
     401: checkcast     #95                 // class java/lang/Iterable
     404: astore        6
     406: iconst_0
     407: istore        7
     409: aload         6
     411: instanceof    #151                // class java/util/Collection
     414: ifeq          434
     417: aload         6
     419: checkcast     #151                // class java/util/Collection
     422: invokeinterface #309,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     427: ifeq          434
     430: iconst_1
     431: goto          504
     434: aload         6
     436: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     441: astore        8
     443: aload         8
     445: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     450: ifeq          503
     453: aload         8
     455: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     460: astore        9
     462: aload         9
     464: checkcast     #271                // class Point
     467: astore        10
     469: iconst_0
     470: istore        11
     472: aload_0
     473: aload         10
     475: invokeinterface #312,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     480: ifne          491
     483: aload         10
     485: invokevirtual #306                // Method Point.getX:()I
     488: ifge          495
     491: iconst_1
     492: goto          496
     495: iconst_0
     496: ifeq          443
     499: iconst_0
     500: goto          504
     503: iconst_1
     504: ifeq          771
     507: aload         5
     509: checkcast     #95                 // class java/lang/Iterable
     512: invokestatic  #316                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     515: astore_3
     516: iconst_1
     517: istore        4
     519: goto          771
     522: aload_1
     523: checkcast     #95                 // class java/lang/Iterable
     526: astore        6
     528: iconst_0
     529: istore        7
     531: aload         6
     533: astore        8
     535: new           #142                // class java/util/ArrayList
     538: dup
     539: aload         6
     541: bipush        10
     543: invokestatic  #146                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     546: invokespecial #149                // Method java/util/ArrayList."<init>":(I)V
     549: checkcast     #151                // class java/util/Collection
     552: astore        9
     554: iconst_0
     555: istore        10
     557: aload         8
     559: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     564: astore        11
     566: aload         11
     568: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     573: ifeq          630
     576: aload         11
     578: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     583: astore        12
     585: aload         9
     587: aload         12
     589: checkcast     #271                // class Point
     592: astore        13
     594: astore        15
     596: iconst_0
     597: istore        14
     599: new           #271                // class Point
     602: dup
     603: aload         13
     605: invokevirtual #306                // Method Point.getX:()I
     608: iconst_1
     609: iadd
     610: aload         13
     612: invokevirtual #285                // Method Point.getY:()I
     615: invokespecial #272                // Method Point."<init>":(II)V
     618: aload         15
     620: swap
     621: invokeinterface #221,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     626: pop
     627: goto          566
     630: aload         9
     632: checkcast     #223                // class java/util/List
     635: nop
     636: astore        5
     638: aload         5
     640: checkcast     #95                 // class java/lang/Iterable
     643: astore        6
     645: iconst_0
     646: istore        7
     648: aload         6
     650: instanceof    #151                // class java/util/Collection
     653: ifeq          673
     656: aload         6
     658: checkcast     #151                // class java/util/Collection
     661: invokeinterface #309,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     666: ifeq          673
     669: iconst_1
     670: goto          745
     673: aload         6
     675: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     680: astore        8
     682: aload         8
     684: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     689: ifeq          744
     692: aload         8
     694: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     699: astore        9
     701: aload         9
     703: checkcast     #271                // class Point
     706: astore        10
     708: iconst_0
     709: istore        11
     711: aload_0
     712: aload         10
     714: invokeinterface #312,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     719: ifne          732
     722: aload         10
     724: invokevirtual #306                // Method Point.getX:()I
     727: bipush        6
     729: if_icmple     736
     732: iconst_1
     733: goto          737
     736: iconst_0
     737: ifeq          682
     740: iconst_0
     741: goto          745
     744: iconst_1
     745: ifeq          771
     748: aload         5
     750: checkcast     #95                 // class java/lang/Iterable
     753: invokestatic  #316                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     756: astore_3
     757: iconst_1
     758: istore        4
     760: goto          771
     763: new           #318                // class kotlin/NoWhenBranchMatchedException
     766: dup
     767: invokespecial #319                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     770: athrow
     771: aload_3
     772: iload         4
     774: invokestatic  #322                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     777: invokestatic  #328                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     780: areturn

  public static final java.util.Set<Point> nextRock(java.util.Set<Point>, java.util.Set<Point>);
    Code:
       0: aload_0
       1: ldc_w         #291                // String <this>
       4: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: ldc_w         #292                // String rock
      11: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: iconst_2
      15: istore_2
      16: aload_0
      17: checkcast     #95                 // class java/lang/Iterable
      20: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      25: astore        5
      27: aload         5
      29: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifne          45
      37: new           #281                // class java/util/NoSuchElementException
      40: dup
      41: invokespecial #282                // Method java/util/NoSuchElementException."<init>":()V
      44: athrow
      45: aload         5
      47: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: checkcast     #271                // class Point
      55: astore        6
      57: iconst_0
      58: istore        7
      60: aload         6
      62: invokevirtual #285                // Method Point.getY:()I
      65: istore        6
      67: aload         5
      69: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      74: ifeq          113
      77: aload         5
      79: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      84: checkcast     #271                // class Point
      87: astore        7
      89: iconst_0
      90: istore        8
      92: aload         7
      94: invokevirtual #285                // Method Point.getY:()I
      97: istore        7
      99: iload         6
     101: iload         7
     103: if_icmpge     67
     106: iload         7
     108: istore        6
     110: goto          67
     113: iload         6
     115: iconst_4
     116: iadd
     117: istore_3
     118: aload_1
     119: checkcast     #95                 // class java/lang/Iterable
     122: astore        4
     124: iconst_0
     125: istore        5
     127: aload         4
     129: astore        6
     131: new           #142                // class java/util/ArrayList
     134: dup
     135: aload         4
     137: bipush        10
     139: invokestatic  #146                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     142: invokespecial #149                // Method java/util/ArrayList."<init>":(I)V
     145: checkcast     #151                // class java/util/Collection
     148: astore        7
     150: iconst_0
     151: istore        8
     153: aload         6
     155: invokeinterface #155,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     160: astore        9
     162: aload         9
     164: invokeinterface #161,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     169: ifeq          228
     172: aload         9
     174: invokeinterface #229,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     179: astore        10
     181: aload         7
     183: aload         10
     185: checkcast     #271                // class Point
     188: astore        11
     190: astore        13
     192: iconst_0
     193: istore        12
     195: new           #271                // class Point
     198: dup
     199: aload         11
     201: invokevirtual #306                // Method Point.getX:()I
     204: iload_2
     205: iadd
     206: aload         11
     208: invokevirtual #285                // Method Point.getY:()I
     211: iload_3
     212: iadd
     213: invokespecial #272                // Method Point."<init>":(II)V
     216: aload         13
     218: swap
     219: invokeinterface #221,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     224: pop
     225: goto          162
     228: aload         7
     230: checkcast     #223                // class java/util/List
     233: nop
     234: checkcast     #95                 // class java/lang/Iterable
     237: invokestatic  #316                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     240: areturn

  public static final day17.Jets parse(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #291                // String <this>
       4: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #350                // class java/lang/CharSequence
      11: astore_1
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #142                // class java/util/ArrayList
      19: dup
      20: aload_1
      21: invokeinterface #353,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      26: invokespecial #149                // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #151                // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: iconst_0
      38: istore        6
      40: iload         6
      42: aload_3
      43: invokeinterface #353,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      48: if_icmpge     142
      51: aload_3
      52: iload         6
      54: invokeinterface #357,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      59: istore        7
      61: aload         4
      63: iload         7
      65: istore        8
      67: astore        10
      69: iconst_0
      70: istore        9
      72: iload         8
      74: tableswitch   { // 60 to 62
                    60: 100
                    61: 112
                    62: 106
               default: 112
          }
     100: getstatic     #360                // Field day17/Direction.LEFT:Lday17/Direction;
     103: goto          126
     106: getstatic     #363                // Field day17/Direction.RIGHT:Lday17/Direction;
     109: goto          126
     112: new           #365                // class java/lang/IllegalStateException
     115: dup
     116: ldc_w         #367                // String illegal input
     119: invokevirtual #368                // Method java/lang/Object.toString:()Ljava/lang/String;
     122: invokespecial #371                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     125: athrow
     126: nop
     127: aload         10
     129: swap
     130: invokeinterface #221,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     135: pop
     136: iinc          6, 1
     139: goto          40
     142: aload         4
     144: checkcast     #223                // class java/util/List
     147: nop
     148: astore_2
     149: iconst_0
     150: istore_3
     151: new           #176                // class day17/Jets
     154: dup
     155: aload_2
     156: invokespecial #374                // Method day17/Jets."<init>":(Ljava/util/List;)V
     159: nop
     160: areturn

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

  static {};
    Code:
       0: iconst_5
       1: anewarray     #189                // class java/util/Set
       4: astore_0
       5: aload_0
       6: iconst_0
       7: iconst_4
       8: anewarray     #271                // class Point
      11: astore_1
      12: aload_1
      13: iconst_0
      14: new           #271                // class Point
      17: dup
      18: iconst_0
      19: iconst_0
      20: invokespecial #272                // Method Point."<init>":(II)V
      23: aastore
      24: aload_1
      25: iconst_1
      26: new           #271                // class Point
      29: dup
      30: iconst_1
      31: iconst_0
      32: invokespecial #272                // Method Point."<init>":(II)V
      35: aastore
      36: aload_1
      37: iconst_2
      38: new           #271                // class Point
      41: dup
      42: iconst_2
      43: iconst_0
      44: invokespecial #272                // Method Point."<init>":(II)V
      47: aastore
      48: aload_1
      49: iconst_3
      50: new           #271                // class Point
      53: dup
      54: iconst_3
      55: iconst_0
      56: invokespecial #272                // Method Point."<init>":(II)V
      59: aastore
      60: aload_1
      61: invokestatic  #389                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      64: aastore
      65: aload_0
      66: iconst_1
      67: iconst_5
      68: anewarray     #271                // class Point
      71: astore_1
      72: aload_1
      73: iconst_0
      74: new           #271                // class Point
      77: dup
      78: iconst_1
      79: iconst_0
      80: invokespecial #272                // Method Point."<init>":(II)V
      83: aastore
      84: aload_1
      85: iconst_1
      86: new           #271                // class Point
      89: dup
      90: iconst_0
      91: iconst_1
      92: invokespecial #272                // Method Point."<init>":(II)V
      95: aastore
      96: aload_1
      97: iconst_2
      98: new           #271                // class Point
     101: dup
     102: iconst_1
     103: iconst_1
     104: invokespecial #272                // Method Point."<init>":(II)V
     107: aastore
     108: aload_1
     109: iconst_3
     110: new           #271                // class Point
     113: dup
     114: iconst_2
     115: iconst_1
     116: invokespecial #272                // Method Point."<init>":(II)V
     119: aastore
     120: aload_1
     121: iconst_4
     122: new           #271                // class Point
     125: dup
     126: iconst_1
     127: iconst_2
     128: invokespecial #272                // Method Point."<init>":(II)V
     131: aastore
     132: aload_1
     133: invokestatic  #389                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     136: aastore
     137: aload_0
     138: iconst_2
     139: iconst_5
     140: anewarray     #271                // class Point
     143: astore_1
     144: aload_1
     145: iconst_0
     146: new           #271                // class Point
     149: dup
     150: iconst_0
     151: iconst_0
     152: invokespecial #272                // Method Point."<init>":(II)V
     155: aastore
     156: aload_1
     157: iconst_1
     158: new           #271                // class Point
     161: dup
     162: iconst_1
     163: iconst_0
     164: invokespecial #272                // Method Point."<init>":(II)V
     167: aastore
     168: aload_1
     169: iconst_2
     170: new           #271                // class Point
     173: dup
     174: iconst_2
     175: iconst_0
     176: invokespecial #272                // Method Point."<init>":(II)V
     179: aastore
     180: aload_1
     181: iconst_3
     182: new           #271                // class Point
     185: dup
     186: iconst_2
     187: iconst_1
     188: invokespecial #272                // Method Point."<init>":(II)V
     191: aastore
     192: aload_1
     193: iconst_4
     194: new           #271                // class Point
     197: dup
     198: iconst_2
     199: iconst_2
     200: invokespecial #272                // Method Point."<init>":(II)V
     203: aastore
     204: aload_1
     205: invokestatic  #389                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     208: aastore
     209: aload_0
     210: iconst_3
     211: iconst_4
     212: anewarray     #271                // class Point
     215: astore_1
     216: aload_1
     217: iconst_0
     218: new           #271                // class Point
     221: dup
     222: iconst_0
     223: iconst_0
     224: invokespecial #272                // Method Point."<init>":(II)V
     227: aastore
     228: aload_1
     229: iconst_1
     230: new           #271                // class Point
     233: dup
     234: iconst_0
     235: iconst_1
     236: invokespecial #272                // Method Point."<init>":(II)V
     239: aastore
     240: aload_1
     241: iconst_2
     242: new           #271                // class Point
     245: dup
     246: iconst_0
     247: iconst_2
     248: invokespecial #272                // Method Point."<init>":(II)V
     251: aastore
     252: aload_1
     253: iconst_3
     254: new           #271                // class Point
     257: dup
     258: iconst_0
     259: iconst_3
     260: invokespecial #272                // Method Point."<init>":(II)V
     263: aastore
     264: aload_1
     265: invokestatic  #389                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     268: aastore
     269: aload_0
     270: iconst_4
     271: iconst_4
     272: anewarray     #271                // class Point
     275: astore_1
     276: aload_1
     277: iconst_0
     278: new           #271                // class Point
     281: dup
     282: iconst_0
     283: iconst_0
     284: invokespecial #272                // Method Point."<init>":(II)V
     287: aastore
     288: aload_1
     289: iconst_1
     290: new           #271                // class Point
     293: dup
     294: iconst_1
     295: iconst_0
     296: invokespecial #272                // Method Point."<init>":(II)V
     299: aastore
     300: aload_1
     301: iconst_2
     302: new           #271                // class Point
     305: dup
     306: iconst_0
     307: iconst_1
     308: invokespecial #272                // Method Point."<init>":(II)V
     311: aastore
     312: aload_1
     313: iconst_3
     314: new           #271                // class Point
     317: dup
     318: iconst_1
     319: iconst_1
     320: invokespecial #272                // Method Point."<init>":(II)V
     323: aastore
     324: aload_1
     325: invokestatic  #389                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     328: aastore
     329: aload_0
     330: invokestatic  #393                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     333: putstatic     #12                 // Field fallingRocks:Ljava/util/List;
     336: return
}


package day21

import readInput

fun main() {
    val input = readInput("main/day21/Day21")

    println(part1(input))
    println(part2(input))
}

fun part1(input: List<String>): Long {
    val monkeys = input.map { it.toMonkey() }.associateBy { it.name }
    return solvePart1(monkeys.toMutableMap(), monkeys["root"]!!)
}

fun part2(input: List<String>): Long {
    var humanNumber = 1000000000000L
    val monkeys = input.map { it.toMonkey() }.associateBy { it.name }
    while (true) {
        if (humanNumber % 10000L == 0L) println(humanNumber)
        if (checkForMatch(monkeys.toMutableMap(), humanNumber)) return humanNumber
        humanNumber++
    }

    return -1
}

fun checkForMatch(monkeys: MutableMap<String, Monkey>, humanNumber: Long): Boolean {
    val rootMonkey = monkeys["root"]!!

    val human = monkeys["humn"]!!.copy(number = humanNumber)
    monkeys["humn"] = human

    val firstMonkey = monkeys[rootMonkey.op?.first!!]!!
    val secondMonkey = monkeys[rootMonkey.op.second]!!
    val first = solvePart1(monkeys, firstMonkey)
    val second = solvePart1(monkeys, secondMonkey)

    return (first != null && first == second)
}

fun solvePart1(monkeys: MutableMap<String, Monkey>, current: Monkey): Long =
    if (current.number != null) {
        current.number
    } else {
        val firstMonkey = monkeys[current.op?.first] ?: error("out of monkeys")
        val secondMonkey = monkeys[current.op?.second] ?: error("out of monkeys")
        val firstNumber = solvePart1(monkeys, firstMonkey)
        monkeys[firstMonkey.name] = firstMonkey.copy(number = firstNumber)

        val secondNumber = solvePart1(monkeys, secondMonkey)
        monkeys[secondMonkey.name] = secondMonkey.copy(number = secondNumber)

        val func = current.op?.operator?.func!!
        func.invoke(firstNumber, secondNumber)
    }

fun String.toMonkey(): Monkey {
    return split(": ").let { (name, rest) ->
        if (rest.all(Char::isDigit)) {
            Monkey(name = name, number = rest.toLong())
        } else {
            rest.split(" ").let { (first, op, second) ->
                Monkey(name = name, op = MonkeyOp(first = first, second = second, operator = Operator.fromString(op)))
            }
        }
    }
}

data class Monkey(val name: String, val number: Long? = null, val op: MonkeyOp? = null)

data class MonkeyOp(val first: String, val second: String, val operator: Operator)

enum class Operator(val func: (Long, Long) -> Long) {
    PLUS({ a, b -> a + b }),
    MINUS({ a, b -> a - b }),
    TIMES({ a, b -> a * b }),
    DIV({ a, b -> a / b });

    fun opposite() = when (this) {
        PLUS -> MINUS
        MINUS -> PLUS
        TIMES -> DIV
        DIV -> TIMES
    }

    companion object {
        fun fromString(operation: String) =
            when (operation.trim()) {
                "+" -> PLUS
                "-" -> MINUS
                "*" -> TIMES
                "/" -> DIV
                else -> error("illegal operation")
            }
    }

}

Compiled from "day21.kt"
public final class day21.Day21Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String main/day21/Day21
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method part1:(Ljava/util/List;)J
      10: lstore_1
      11: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: lload_1
      15: invokevirtual #30                 // Method java/io/PrintStream.println:(J)V
      18: aload_0
      19: invokestatic  #33                 // Method part2:(Ljava/util/List;)J
      22: lstore_1
      23: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: lload_1
      27: invokevirtual #30                 // Method java/io/PrintStream.println:(J)V
      30: return

  public static final long part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #38                 // String input
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #46                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #48                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #58                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #60                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          96
      56: aload         7
      58: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #76                 // class java/lang/String
      72: astore        9
      74: astore        12
      76: iconst_0
      77: istore        10
      79: aload         9
      81: invokestatic  #80                 // Method toMonkey:(Ljava/lang/String;)Lday21/Monkey;
      84: aload         12
      86: swap
      87: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      92: pop
      93: goto          46
      96: aload         5
      98: checkcast     #86                 // class java/util/List
     101: nop
     102: checkcast     #46                 // class java/lang/Iterable
     105: astore_2
     106: nop
     107: iconst_0
     108: istore_3
     109: aload_2
     110: bipush        10
     112: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     115: invokestatic  #92                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     118: bipush        16
     120: invokestatic  #98                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     123: istore        4
     125: aload_2
     126: astore        5
     128: new           #100                // class java/util/LinkedHashMap
     131: dup
     132: iload         4
     134: invokespecial #101                // Method java/util/LinkedHashMap."<init>":(I)V
     137: checkcast     #103                // class java/util/Map
     140: astore        6
     142: iconst_0
     143: istore        7
     145: aload         5
     147: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     152: astore        8
     154: aload         8
     156: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     161: ifeq          206
     164: aload         8
     166: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     171: astore        9
     173: aload         6
     175: aload         9
     177: checkcast     #105                // class day21/Monkey
     180: astore        10
     182: astore        12
     184: iconst_0
     185: istore        11
     187: aload         10
     189: invokevirtual #109                // Method day21/Monkey.getName:()Ljava/lang/String;
     192: aload         12
     194: swap
     195: aload         9
     197: invokeinterface #113,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     202: pop
     203: goto          154
     206: aload         6
     208: nop
     209: astore_1
     210: aload_1
     211: invokestatic  #117                // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     214: aload_1
     215: ldc           #119                // String root
     217: invokeinterface #123,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     222: dup
     223: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     226: checkcast     #105                // class day21/Monkey
     229: invokestatic  #131                // Method solvePart1:(Ljava/util/Map;Lday21/Monkey;)J
     232: lreturn

  public static final long part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #38                 // String input
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc2_w        #155                // long 1000000000000l
       9: lstore_1
      10: aload_0
      11: checkcast     #46                 // class java/lang/Iterable
      14: astore        4
      16: iconst_0
      17: istore        5
      19: aload         4
      21: astore        6
      23: new           #48                 // class java/util/ArrayList
      26: dup
      27: aload         4
      29: bipush        10
      31: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #58                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #60                 // class java/util/Collection
      40: astore        7
      42: iconst_0
      43: istore        8
      45: aload         6
      47: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        9
      54: aload         9
      56: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          104
      64: aload         9
      66: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: astore        10
      73: aload         7
      75: aload         10
      77: checkcast     #76                 // class java/lang/String
      80: astore        11
      82: astore        14
      84: iconst_0
      85: istore        12
      87: aload         11
      89: invokestatic  #80                 // Method toMonkey:(Ljava/lang/String;)Lday21/Monkey;
      92: aload         14
      94: swap
      95: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     100: pop
     101: goto          54
     104: aload         7
     106: checkcast     #86                 // class java/util/List
     109: nop
     110: checkcast     #46                 // class java/lang/Iterable
     113: astore        4
     115: nop
     116: iconst_0
     117: istore        5
     119: aload         4
     121: bipush        10
     123: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     126: invokestatic  #92                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     129: bipush        16
     131: invokestatic  #98                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     134: istore        6
     136: aload         4
     138: astore        7
     140: new           #100                // class java/util/LinkedHashMap
     143: dup
     144: iload         6
     146: invokespecial #101                // Method java/util/LinkedHashMap."<init>":(I)V
     149: checkcast     #103                // class java/util/Map
     152: astore        8
     154: iconst_0
     155: istore        9
     157: aload         7
     159: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     164: astore        10
     166: aload         10
     168: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     173: ifeq          218
     176: aload         10
     178: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     183: astore        11
     185: aload         8
     187: aload         11
     189: checkcast     #105                // class day21/Monkey
     192: astore        12
     194: astore        14
     196: iconst_0
     197: istore        13
     199: aload         12
     201: invokevirtual #109                // Method day21/Monkey.getName:()Ljava/lang/String;
     204: aload         14
     206: swap
     207: aload         11
     209: invokeinterface #113,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     214: pop
     215: goto          166
     218: aload         8
     220: nop
     221: astore_3
     222: nop
     223: lload_1
     224: ldc2_w        #157                // long 10000l
     227: lrem
     228: lconst_0
     229: lcmp
     230: ifne          240
     233: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
     236: lload_1
     237: invokevirtual #30                 // Method java/io/PrintStream.println:(J)V
     240: aload_3
     241: invokestatic  #117                // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     244: lload_1
     245: invokestatic  #162                // Method checkForMatch:(Ljava/util/Map;J)Z
     248: ifeq          253
     251: lload_1
     252: lreturn
     253: lload_1
     254: lstore        4
     256: lload         4
     258: lconst_1
     259: ladd
     260: lstore_1
     261: goto          222

  public static final boolean checkForMatch(java.util.Map<java.lang.String, day21.Monkey>, long);
    Code:
       0: aload_0
       1: ldc           #168                // String monkeys
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: ldc           #119                // String root
       9: invokeinterface #123,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      14: dup
      15: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      18: checkcast     #105                // class day21/Monkey
      21: astore_3
      22: aload_0
      23: ldc           #170                // String humn
      25: invokeinterface #123,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      30: dup
      31: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      34: checkcast     #105                // class day21/Monkey
      37: aconst_null
      38: lload_1
      39: invokestatic  #176                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      42: aconst_null
      43: iconst_5
      44: aconst_null
      45: invokestatic  #180                // Method day21/Monkey.copy$default:(Lday21/Monkey;Ljava/lang/String;Ljava/lang/Long;Lday21/MonkeyOp;ILjava/lang/Object;)Lday21/Monkey;
      48: astore        4
      50: aload_0
      51: ldc           #170                // String humn
      53: aload         4
      55: invokeinterface #113,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      60: pop
      61: aload_0
      62: aload_3
      63: invokevirtual #184                // Method day21/Monkey.getOp:()Lday21/MonkeyOp;
      66: dup
      67: ifnull        76
      70: invokevirtual #189                // Method day21/MonkeyOp.getFirst:()Ljava/lang/String;
      73: goto          78
      76: pop
      77: aconst_null
      78: dup
      79: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      82: invokeinterface #123,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      87: dup
      88: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      91: checkcast     #105                // class day21/Monkey
      94: astore        5
      96: aload_0
      97: aload_3
      98: invokevirtual #184                // Method day21/Monkey.getOp:()Lday21/MonkeyOp;
     101: invokevirtual #192                // Method day21/MonkeyOp.getSecond:()Ljava/lang/String;
     104: invokeinterface #123,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     109: dup
     110: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     113: checkcast     #105                // class day21/Monkey
     116: astore        6
     118: aload_0
     119: aload         5
     121: invokestatic  #131                // Method solvePart1:(Ljava/util/Map;Lday21/Monkey;)J
     124: lstore        7
     126: aload_0
     127: aload         6
     129: invokestatic  #131                // Method solvePart1:(Ljava/util/Map;Lday21/Monkey;)J
     132: lstore        9
     134: lload         7
     136: lload         9
     138: lcmp
     139: ifne          146
     142: iconst_1
     143: goto          147
     146: iconst_0
     147: ireturn

  public static final long solvePart1(java.util.Map<java.lang.String, day21.Monkey>, day21.Monkey);
    Code:
       0: aload_0
       1: ldc           #168                // String monkeys
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #201                // String current
       9: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokevirtual #205                // Method day21/Monkey.getNumber:()Ljava/lang/Long;
      16: ifnull        29
      19: aload_1
      20: invokevirtual #205                // Method day21/Monkey.getNumber:()Ljava/lang/Long;
      23: invokevirtual #209                // Method java/lang/Long.longValue:()J
      26: goto          241
      29: aload_0
      30: astore        4
      32: aload_1
      33: invokevirtual #184                // Method day21/Monkey.getOp:()Lday21/MonkeyOp;
      36: dup
      37: ifnull        46
      40: invokevirtual #189                // Method day21/MonkeyOp.getFirst:()Ljava/lang/String;
      43: goto          48
      46: pop
      47: aconst_null
      48: aload         4
      50: swap
      51: invokeinterface #123,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      56: checkcast     #105                // class day21/Monkey
      59: dup
      60: ifnonnull     77
      63: pop
      64: new           #211                // class java/lang/IllegalStateException
      67: dup
      68: ldc           #213                // String out of monkeys
      70: invokevirtual #216                // Method java/lang/Object.toString:()Ljava/lang/String;
      73: invokespecial #219                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      76: athrow
      77: astore_2
      78: aload_0
      79: astore        5
      81: aload_1
      82: invokevirtual #184                // Method day21/Monkey.getOp:()Lday21/MonkeyOp;
      85: dup
      86: ifnull        95
      89: invokevirtual #192                // Method day21/MonkeyOp.getSecond:()Ljava/lang/String;
      92: goto          97
      95: pop
      96: aconst_null
      97: aload         5
      99: swap
     100: invokeinterface #123,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     105: checkcast     #105                // class day21/Monkey
     108: dup
     109: ifnonnull     126
     112: pop
     113: new           #211                // class java/lang/IllegalStateException
     116: dup
     117: ldc           #213                // String out of monkeys
     119: invokevirtual #216                // Method java/lang/Object.toString:()Ljava/lang/String;
     122: invokespecial #219                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     125: athrow
     126: astore_3
     127: aload_0
     128: aload_2
     129: invokestatic  #131                // Method solvePart1:(Ljava/util/Map;Lday21/Monkey;)J
     132: lstore        4
     134: aload_0
     135: aload_2
     136: invokevirtual #109                // Method day21/Monkey.getName:()Ljava/lang/String;
     139: aload_2
     140: aconst_null
     141: lload         4
     143: invokestatic  #176                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     146: aconst_null
     147: iconst_5
     148: aconst_null
     149: invokestatic  #180                // Method day21/Monkey.copy$default:(Lday21/Monkey;Ljava/lang/String;Ljava/lang/Long;Lday21/MonkeyOp;ILjava/lang/Object;)Lday21/Monkey;
     152: invokeinterface #113,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     157: pop
     158: aload_0
     159: aload_3
     160: invokestatic  #131                // Method solvePart1:(Ljava/util/Map;Lday21/Monkey;)J
     163: lstore        6
     165: aload_0
     166: aload_3
     167: invokevirtual #109                // Method day21/Monkey.getName:()Ljava/lang/String;
     170: aload_3
     171: aconst_null
     172: lload         6
     174: invokestatic  #176                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     177: aconst_null
     178: iconst_5
     179: aconst_null
     180: invokestatic  #180                // Method day21/Monkey.copy$default:(Lday21/Monkey;Ljava/lang/String;Ljava/lang/Long;Lday21/MonkeyOp;ILjava/lang/Object;)Lday21/Monkey;
     183: invokeinterface #113,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     188: pop
     189: aload_1
     190: invokevirtual #184                // Method day21/Monkey.getOp:()Lday21/MonkeyOp;
     193: dup
     194: ifnull        210
     197: invokevirtual #223                // Method day21/MonkeyOp.getOperator:()Lday21/Operator;
     200: dup
     201: ifnull        210
     204: invokevirtual #229                // Method day21/Operator.getFunc:()Lkotlin/jvm/functions/Function2;
     207: goto          212
     210: pop
     211: aconst_null
     212: dup
     213: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     216: astore        8
     218: aload         8
     220: lload         4
     222: invokestatic  #176                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     225: lload         6
     227: invokestatic  #176                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     230: invokeinterface #234,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     235: checkcast     #236                // class java/lang/Number
     238: invokevirtual #237                // Method java/lang/Number.longValue:()J
     241: lreturn

  public static final day21.Monkey toMonkey(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #243                // String <this>
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #245                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #76                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #247                // String :
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #253                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_2
      30: iconst_0
      31: istore_3
      32: aload_2
      33: iconst_0
      34: invokeinterface #256,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      39: checkcast     #76                 // class java/lang/String
      42: astore        4
      44: aload_2
      45: iconst_1
      46: invokeinterface #256,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      51: checkcast     #76                 // class java/lang/String
      54: astore        5
      56: aload         5
      58: checkcast     #245                // class java/lang/CharSequence
      61: astore        6
      63: iconst_0
      64: istore        7
      66: iconst_0
      67: istore        8
      69: iload         8
      71: aload         6
      73: invokeinterface #260,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      78: if_icmpge     118
      81: aload         6
      83: iload         8
      85: invokeinterface #264,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      90: istore        9
      92: iload         9
      94: istore        10
      96: iconst_0
      97: istore        11
      99: iload         10
     101: invokestatic  #270                // Method java/lang/Character.isDigit:(C)Z
     104: nop
     105: ifne          112
     108: iconst_0
     109: goto          119
     112: iinc          8, 1
     115: goto          69
     118: iconst_1
     119: ifeq          145
     122: new           #105                // class day21/Monkey
     125: dup
     126: aload         4
     128: aload         5
     130: invokestatic  #274                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     133: invokestatic  #176                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     136: aconst_null
     137: iconst_4
     138: aconst_null
     139: invokespecial #277                // Method day21/Monkey."<init>":(Ljava/lang/String;Ljava/lang/Long;Lday21/MonkeyOp;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     142: goto          249
     145: aload         5
     147: checkcast     #245                // class java/lang/CharSequence
     150: iconst_1
     151: anewarray     #76                 // class java/lang/String
     154: astore        6
     156: aload         6
     158: iconst_0
     159: ldc_w         #279                // String
     162: aastore
     163: aload         6
     165: iconst_0
     166: iconst_0
     167: bipush        6
     169: aconst_null
     170: invokestatic  #253                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     173: astore        7
     175: iconst_0
     176: istore        8
     178: aload         7
     180: iconst_0
     181: invokeinterface #256,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: checkcast     #76                 // class java/lang/String
     189: astore        9
     191: aload         7
     193: iconst_1
     194: invokeinterface #256,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     199: checkcast     #76                 // class java/lang/String
     202: astore        10
     204: aload         7
     206: iconst_2
     207: invokeinterface #256,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     212: checkcast     #76                 // class java/lang/String
     215: astore        11
     217: new           #105                // class day21/Monkey
     220: dup
     221: aload         4
     223: aconst_null
     224: new           #186                // class day21/MonkeyOp
     227: dup
     228: aload         9
     230: aload         11
     232: getstatic     #283                // Field day21/Operator.Companion:Lday21/Operator$Companion;
     235: aload         10
     237: invokevirtual #289                // Method day21/Operator$Companion.fromString:(Ljava/lang/String;)Lday21/Operator;
     240: invokespecial #292                // Method day21/MonkeyOp."<init>":(Ljava/lang/String;Ljava/lang/String;Lday21/Operator;)V
     243: iconst_2
     244: aconst_null
     245: invokespecial #277                // Method day21/Monkey."<init>":(Ljava/lang/String;Ljava/lang/Long;Lday21/MonkeyOp;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     248: nop
     249: nop
     250: nop
     251: areturn

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