package day02

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

enum class MoveTypes {
    ROCK,
    PAPER,
    SCISSORS
}

fun getWinningMove(move: Move) = when(move.type) {
    MoveTypes.ROCK -> Move("B")
    MoveTypes.PAPER -> Move("C")
    MoveTypes.SCISSORS -> Move("A")
}

fun getLosingMove(move: Move) = when(move.type) {
    MoveTypes.ROCK -> Move("C")
    MoveTypes.PAPER -> Move("A")
    MoveTypes.SCISSORS -> Move("B")
}

class Move(
    code: String
): Comparable<Move> {

    val type = when(code) {
        "A" -> MoveTypes.ROCK
        "B" -> MoveTypes.PAPER
        "C" -> MoveTypes.SCISSORS
        "X" -> MoveTypes.ROCK
        "Y" -> MoveTypes.PAPER
        "Z" -> MoveTypes.SCISSORS
        else -> throw Exception()
    }
    override fun compareTo(other: Move): Int {
        if(type == other.type) return 0
        return when(type) {
            MoveTypes.ROCK -> { if(other.type == MoveTypes.SCISSORS) return 1 else return -1 }
            MoveTypes.PAPER -> { if(other.type == MoveTypes.ROCK) return 1 else return -1 }
            MoveTypes.SCISSORS -> { if(other.type == MoveTypes.PAPER) return 1 else return -1 }
        }
    }

    fun value(): Int =
        when(type) {
            MoveTypes.ROCK -> 1
            MoveTypes.PAPER -> 2
            MoveTypes.SCISSORS -> 3
        }

}

class Match(
    private val yourMove: Move,
    private val otherMove: Move
) {
    fun score(): Int {
        return if (yourMove < otherMove) yourMove.value()
        else if (yourMove > otherMove) 6 + yourMove.value()
        else 3 + yourMove.value()
    }
}

fun getListOfMatchesFromFile() =
    File("src/main/kotlin/day022/input.txt")
        .readLines()
        .fold(listOf<Pair<String, String>>()) { moves, it ->
            val (opponentMove, yourMove) = it.split(" ")
            moves + Pair(opponentMove, yourMove)
        }

fun interpretPairsAsMatches() =
    getListOfMatchesFromFile()
        .map {
            Match(
                Move(it.second),
                Move(it.first)
            )
        }

fun interpretPairsAsResults() =
    getListOfMatchesFromFile()
        .map {
            when(it.second) {
                "X" -> Match(getLosingMove(Move(it.first)), Move(it.first))
                "Y" -> Match(Move(it.first), Move(it.first))
                "Z" -> Match(getWinningMove(Move(it.first)), Move(it.first))
                else -> throw Exception()
            }
        }

fun getTotalScore() = interpretPairsAsMatches().sumOf { it.score() }

fun getTotalScoreWithOutcome() = interpretPairsAsResults().sumOf { it.score() }

fun main() {
    println("The total score if the second row is the move is: ${getTotalScore()}")
    println("The total score if the second row is the outcome is: ${getTotalScoreWithOutcome()}")
}

Compiled from "Solution.kt"
public final class day02.SolutionKt$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method day02/MoveTypes.values:()[Lday02/MoveTypes;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field day02/MoveTypes.ROCK:Lday02/MoveTypes;
      12: invokevirtual #22                 // Method day02/MoveTypes.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field day02/MoveTypes.PAPER:Lday02/MoveTypes;
      26: invokevirtual #22                 // Method day02/MoveTypes.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field day02/MoveTypes.SCISSORS:Lday02/MoveTypes;
      40: invokevirtual #22                 // Method day02/MoveTypes.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 "Solution.kt"
public final class day02.SolutionKt {
  public static final day02.Move getWinningMove(day02.Move);
    Code:
       0: aload_0
       1: ldc           #9                  // String move
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #21                 // Method day02/Move.getType:()Lday02/MoveTypes;
      10: getstatic     #27                 // Field day02/SolutionKt$WhenMappings.$EnumSwitchMapping$0:[I
      13: swap
      14: invokevirtual #33                 // Method day02/MoveTypes.ordinal:()I
      17: iaload
      18: tableswitch   { // 1 to 3
                     1: 44
                     2: 56
                     3: 68
               default: 80
          }
      44: new           #17                 // class day02/Move
      47: dup
      48: ldc           #35                 // String B
      50: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
      53: goto          88
      56: new           #17                 // class day02/Move
      59: dup
      60: ldc           #41                 // String C
      62: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
      65: goto          88
      68: new           #17                 // class day02/Move
      71: dup
      72: ldc           #43                 // String A
      74: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
      77: goto          88
      80: new           #45                 // class kotlin/NoWhenBranchMatchedException
      83: dup
      84: invokespecial #48                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
      87: athrow
      88: areturn

  public static final day02.Move getLosingMove(day02.Move);
    Code:
       0: aload_0
       1: ldc           #9                  // String move
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #21                 // Method day02/Move.getType:()Lday02/MoveTypes;
      10: getstatic     #27                 // Field day02/SolutionKt$WhenMappings.$EnumSwitchMapping$0:[I
      13: swap
      14: invokevirtual #33                 // Method day02/MoveTypes.ordinal:()I
      17: iaload
      18: tableswitch   { // 1 to 3
                     1: 44
                     2: 56
                     3: 68
               default: 80
          }
      44: new           #17                 // class day02/Move
      47: dup
      48: ldc           #41                 // String C
      50: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
      53: goto          88
      56: new           #17                 // class day02/Move
      59: dup
      60: ldc           #43                 // String A
      62: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
      65: goto          88
      68: new           #17                 // class day02/Move
      71: dup
      72: ldc           #35                 // String B
      74: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
      77: goto          88
      80: new           #45                 // class kotlin/NoWhenBranchMatchedException
      83: dup
      84: invokespecial #48                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
      87: athrow
      88: areturn

  public static final java.util.List<kotlin.Pair<java.lang.String, java.lang.String>> getListOfMatchesFromFile();
    Code:
       0: new           #55                 // class java/io/File
       3: dup
       4: ldc           #57                 // String src/main/kotlin/day022/input.txt
       6: invokespecial #58                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #64                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #66                 // class java/lang/Iterable
      18: astore_0
      19: invokestatic  #71                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      22: astore_1
      23: nop
      24: iconst_0
      25: istore_2
      26: aload_1
      27: astore_3
      28: aload_0
      29: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      34: astore        4
      36: aload         4
      38: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          146
      46: aload         4
      48: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        5
      55: aload_3
      56: aload         5
      58: checkcast     #87                 // class java/lang/String
      61: astore        6
      63: astore        7
      65: iconst_0
      66: istore        8
      68: aload         6
      70: checkcast     #89                 // class java/lang/CharSequence
      73: iconst_1
      74: anewarray     #87                 // class java/lang/String
      77: astore        9
      79: aload         9
      81: iconst_0
      82: ldc           #91                 // String
      84: aastore
      85: aload         9
      87: iconst_0
      88: iconst_0
      89: bipush        6
      91: aconst_null
      92: invokestatic  #97                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      95: astore        10
      97: aload         10
      99: iconst_0
     100: invokeinterface #103,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     105: checkcast     #87                 // class java/lang/String
     108: astore        9
     110: aload         10
     112: iconst_1
     113: invokeinterface #103,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     118: checkcast     #87                 // class java/lang/String
     121: astore        11
     123: aload         7
     125: checkcast     #105                // class java/util/Collection
     128: new           #107                // class kotlin/Pair
     131: dup
     132: aload         9
     134: aload         11
     136: invokespecial #110                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     139: invokestatic  #114                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     142: astore_3
     143: goto          36
     146: aload_3
     147: areturn

  public static final java.util.List<day02.Match> interpretPairsAsMatches();
    Code:
       0: invokestatic  #133                // Method getListOfMatchesFromFile:()Ljava/util/List;
       3: checkcast     #66                 // class java/lang/Iterable
       6: astore_0
       7: nop
       8: iconst_0
       9: istore_1
      10: aload_0
      11: astore_2
      12: new           #135                // class java/util/ArrayList
      15: dup
      16: aload_0
      17: bipush        10
      19: invokestatic  #139                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      22: invokespecial #142                // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #105                // class java/util/Collection
      28: astore_3
      29: iconst_0
      30: istore        4
      32: aload_2
      33: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        5
      40: aload         5
      42: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          122
      50: aload         5
      52: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        6
      59: aload_3
      60: aload         6
      62: checkcast     #107                // class kotlin/Pair
      65: astore        7
      67: astore        9
      69: iconst_0
      70: istore        8
      72: new           #144                // class day02/Match
      75: dup
      76: new           #17                 // class day02/Move
      79: dup
      80: aload         7
      82: invokevirtual #147                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      85: checkcast     #87                 // class java/lang/String
      88: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
      91: new           #17                 // class day02/Move
      94: dup
      95: aload         7
      97: invokevirtual #150                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     100: checkcast     #87                 // class java/lang/String
     103: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
     106: invokespecial #153                // Method day02/Match."<init>":(Lday02/Move;Lday02/Move;)V
     109: nop
     110: aload         9
     112: swap
     113: invokeinterface #157,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     118: pop
     119: goto          40
     122: aload_3
     123: checkcast     #99                 // class java/util/List
     126: nop
     127: areturn

  public static final java.util.List<day02.Match> interpretPairsAsResults();
    Code:
       0: invokestatic  #133                // Method getListOfMatchesFromFile:()Ljava/util/List;
       3: checkcast     #66                 // class java/lang/Iterable
       6: astore_0
       7: nop
       8: iconst_0
       9: istore_1
      10: aload_0
      11: astore_2
      12: new           #135                // class java/util/ArrayList
      15: dup
      16: aload_0
      17: bipush        10
      19: invokestatic  #139                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      22: invokespecial #142                // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #105                // class java/util/Collection
      28: astore_3
      29: iconst_0
      30: istore        4
      32: aload_2
      33: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        5
      40: aload         5
      42: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          298
      50: aload         5
      52: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        6
      59: aload_3
      60: aload         6
      62: checkcast     #107                // class kotlin/Pair
      65: astore        7
      67: astore        10
      69: iconst_0
      70: istore        8
      72: aload         7
      74: invokevirtual #147                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      77: checkcast     #87                 // class java/lang/String
      80: astore        9
      82: aload         9
      84: invokevirtual #170                // Method java/lang/String.hashCode:()I
      87: tableswitch   { // 88 to 90
                    88: 112
                    89: 125
                    90: 138
               default: 277
          }
     112: aload         9
     114: ldc           #172                // String X
     116: invokevirtual #175                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     119: ifne          151
     122: goto          277
     125: aload         9
     127: ldc           #177                // String Y
     129: invokevirtual #175                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     132: ifne          194
     135: goto          277
     138: aload         9
     140: ldc           #179                // String Z
     142: invokevirtual #175                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     145: ifne          234
     148: goto          277
     151: new           #144                // class day02/Match
     154: dup
     155: new           #17                 // class day02/Move
     158: dup
     159: aload         7
     161: invokevirtual #150                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     164: checkcast     #87                 // class java/lang/String
     167: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
     170: invokestatic  #181                // Method getLosingMove:(Lday02/Move;)Lday02/Move;
     173: new           #17                 // class day02/Move
     176: dup
     177: aload         7
     179: invokevirtual #150                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     182: checkcast     #87                 // class java/lang/String
     185: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
     188: invokespecial #153                // Method day02/Match."<init>":(Lday02/Move;Lday02/Move;)V
     191: goto          285
     194: new           #144                // class day02/Match
     197: dup
     198: new           #17                 // class day02/Move
     201: dup
     202: aload         7
     204: invokevirtual #150                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     207: checkcast     #87                 // class java/lang/String
     210: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
     213: new           #17                 // class day02/Move
     216: dup
     217: aload         7
     219: invokevirtual #150                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     222: checkcast     #87                 // class java/lang/String
     225: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
     228: invokespecial #153                // Method day02/Match."<init>":(Lday02/Move;Lday02/Move;)V
     231: goto          285
     234: new           #144                // class day02/Match
     237: dup
     238: new           #17                 // class day02/Move
     241: dup
     242: aload         7
     244: invokevirtual #150                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     247: checkcast     #87                 // class java/lang/String
     250: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
     253: invokestatic  #183                // Method getWinningMove:(Lday02/Move;)Lday02/Move;
     256: new           #17                 // class day02/Move
     259: dup
     260: aload         7
     262: invokevirtual #150                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     265: checkcast     #87                 // class java/lang/String
     268: invokespecial #39                 // Method day02/Move."<init>":(Ljava/lang/String;)V
     271: invokespecial #153                // Method day02/Match."<init>":(Lday02/Move;Lday02/Move;)V
     274: goto          285
     277: new           #185                // class java/lang/Exception
     280: dup
     281: invokespecial #186                // Method java/lang/Exception."<init>":()V
     284: athrow
     285: nop
     286: aload         10
     288: swap
     289: invokeinterface #157,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     294: pop
     295: goto          40
     298: aload_3
     299: checkcast     #99                 // class java/util/List
     302: nop
     303: areturn

  public static final int getTotalScore();
    Code:
       0: invokestatic  #190                // Method interpretPairsAsMatches:()Ljava/util/List;
       3: checkcast     #66                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      15: astore_2
      16: aload_2
      17: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      22: ifeq          60
      25: aload_2
      26: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      31: astore_3
      32: iload_1
      33: aload_3
      34: checkcast     #144                // class day02/Match
      37: astore        4
      39: istore        6
      41: iconst_0
      42: istore        5
      44: aload         4
      46: invokevirtual #193                // Method day02/Match.score:()I
      49: istore        7
      51: iload         6
      53: iload         7
      55: iadd
      56: istore_1
      57: goto          16
      60: iload_1
      61: ireturn

  public static final int getTotalScoreWithOutcome();
    Code:
       0: invokestatic  #198                // Method interpretPairsAsResults:()Ljava/util/List;
       3: checkcast     #66                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      15: astore_2
      16: aload_2
      17: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      22: ifeq          60
      25: aload_2
      26: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      31: astore_3
      32: iload_1
      33: aload_3
      34: checkcast     #144                // class day02/Match
      37: astore        4
      39: istore        6
      41: iconst_0
      42: istore        5
      44: aload         4
      46: invokevirtual #193                // Method day02/Match.score:()I
      49: istore        7
      51: iload         6
      53: iload         7
      55: iadd
      56: istore_1
      57: goto          16
      60: iload_1
      61: ireturn

  public static final void main();
    Code:
       0: new           #202                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #203                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #205                // String The total score if the second row is the move is:
       9: invokevirtual #209                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: invokestatic  #211                // Method getTotalScore:()I
      15: invokevirtual #214                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      18: invokevirtual #218                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      21: getstatic     #224                // Field java/lang/System.out:Ljava/io/PrintStream;
      24: swap
      25: invokevirtual #230                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      28: new           #202                // class java/lang/StringBuilder
      31: dup
      32: invokespecial #203                // Method java/lang/StringBuilder."<init>":()V
      35: ldc           #232                // String The total score if the second row is the outcome is:
      37: invokevirtual #209                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      40: invokestatic  #234                // Method getTotalScoreWithOutcome:()I
      43: invokevirtual #214                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      46: invokevirtual #218                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      49: getstatic     #224                // Field java/lang/System.out:Ljava/io/PrintStream;
      52: swap
      53: invokevirtual #230                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      56: return

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


package day05

import java.io.File
import java.util.*

data class Move(
    val qty: Int,
    val source: String,
    val dest: String
)

fun parseStack(rawInput: List<String>): Map<String, Stack<Char>> =
    (1 .. 9).fold(emptyMap()) { acc, it ->
        acc + (it.toString() to rawInput
            .last()
            .indexOf(it.toString())
            .let { index ->
                rawInput
                    .reversed()
                    .subList(1, rawInput.size)
                    .fold(Stack<Char>()) { stack, line ->
                        if (line.length > index && line[index] != ' ')
                            stack.push(line[index])
                        stack
                    }
            })
    }

fun parseCommands(rawCommands: List<String>) =
    rawCommands.mapNotNull { line ->
        Regex("move ([0-9]+) from ([0-9]+) to ([0-9]+)")
            .find(line)
            ?.groups
            ?.toList()
            ?.let {
                Move(
                    it[1]!!.value.toInt(),
                    it[2]!!.value,
                    it[3]!!.value
                )
            }
    }

fun parseInputFile() =
    File("src/main/kotlin/day05/input.txt")
        .readLines()
        .fold(Pair<List<String>, List<String>>(emptyList(), emptyList())) { acc, line ->
            if (line.startsWith("move")) Pair(acc.first, acc.second + line)
            else if (line.isEmpty()) acc
            else Pair(acc.first + line, acc.second)
        }.let {
            Pair(
                parseStack(it.first),
                parseCommands(it.second)
            )

        }

fun findFinalConfigurationMovingOneCrateAtTime() =
    parseInputFile()
        .let { input ->
            input.second.forEach {move ->
                repeat((1 .. move.qty).count()) {
                    if (input.first[move.source]!!.isNotEmpty())
                        input.first[move.dest]!!.push(input.first[move.source]!!.pop())
                }
            }
            (1..9).fold("") { acc, it ->
                acc + input.first[it.toString()]!!.peek()
            }
        }

fun findFinalConfigurationMovingMultipleCratesAtTime() =
    parseInputFile()
        .let { input ->
            input.second.forEach { move ->
                (1 .. move.qty).fold(emptyList<Char>()) { acc, _ ->
                    if (input.first[move.source]!!.isNotEmpty())
                        acc + input.first[move.source]!!.pop()
                    else acc
                }.reversed().forEach { input.first[move.dest]!!.push(it) }
            }
            (1..9).fold("") { acc, it ->
                acc + input.first[it.toString()]!!.peek()
            }
        }

fun main() {
    println("The top crates at the end using the CrateMover 9000 are: ${findFinalConfigurationMovingOneCrateAtTime()}")
    println("The top crates at the end using the CrateMover 9001 are: ${findFinalConfigurationMovingMultipleCratesAtTime()}")
}

Compiled from "Solution.kt"
public final class day05.SolutionKt {
  public static final java.util.Map<java.lang.String, java.util.Stack<java.lang.Character>> parseStack(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String rawInput
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class kotlin/ranges/IntRange
       9: dup
      10: iconst_1
      11: bipush        9
      13: invokespecial #22                 // Method kotlin/ranges/IntRange."<init>":(II)V
      16: checkcast     #24                 // class java/lang/Iterable
      19: astore_1
      20: invokestatic  #30                 // Method kotlin/collections/MapsKt.emptyMap:()Ljava/util/Map;
      23: astore_2
      24: iconst_0
      25: istore_3
      26: aload_2
      27: astore        4
      29: aload_1
      30: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      35: astore        5
      37: aload         5
      39: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          255
      47: aload         5
      49: checkcast     #42                 // class kotlin/collections/IntIterator
      52: invokevirtual #46                 // Method kotlin/collections/IntIterator.nextInt:()I
      55: istore        6
      57: aload         4
      59: iload         6
      61: istore        7
      63: astore        8
      65: iconst_0
      66: istore        9
      68: aload         8
      70: iload         7
      72: invokestatic  #52                 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      75: aload_0
      76: invokestatic  #58                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      79: checkcast     #60                 // class java/lang/CharSequence
      82: iload         7
      84: invokestatic  #52                 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      87: iconst_0
      88: iconst_0
      89: bipush        6
      91: aconst_null
      92: invokestatic  #66                 // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
      95: istore        10
      97: astore        11
      99: astore        12
     101: iconst_0
     102: istore        13
     104: aload_0
     105: checkcast     #24                 // class java/lang/Iterable
     108: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     111: iconst_1
     112: aload_0
     113: invokeinterface #75,  1           // InterfaceMethod java/util/List.size:()I
     118: invokeinterface #79,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     123: checkcast     #24                 // class java/lang/Iterable
     126: astore        14
     128: new           #81                 // class java/util/Stack
     131: dup
     132: invokespecial #84                 // Method java/util/Stack."<init>":()V
     135: astore        15
     137: iconst_0
     138: istore        16
     140: aload         15
     142: astore        17
     144: aload         14
     146: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     151: astore        18
     153: aload         18
     155: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     160: ifeq          231
     163: aload         18
     165: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     170: astore        19
     172: aload         17
     174: aload         19
     176: checkcast     #48                 // class java/lang/String
     179: astore        20
     181: astore        21
     183: iconst_0
     184: istore        22
     186: aload         20
     188: invokevirtual #91                 // Method java/lang/String.length:()I
     191: iload         10
     193: if_icmple     224
     196: aload         20
     198: iload         10
     200: invokevirtual #95                 // Method java/lang/String.charAt:(I)C
     203: bipush        32
     205: if_icmpeq     224
     208: aload         21
     210: aload         20
     212: iload         10
     214: invokevirtual #95                 // Method java/lang/String.charAt:(I)C
     217: invokestatic  #100                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     220: invokevirtual #104                // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     223: pop
     224: aload         21
     226: astore        17
     228: goto          153
     231: aload         17
     233: nop
     234: astore        23
     236: aload         12
     238: aload         11
     240: aload         23
     242: nop
     243: invokestatic  #110                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     246: invokestatic  #114                // Method kotlin/collections/MapsKt.plus:(Ljava/util/Map;Lkotlin/Pair;)Ljava/util/Map;
     249: nop
     250: astore        4
     252: goto          37
     255: aload         4
     257: areturn

  public static final java.util.List<day05.Move> parseCommands(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #141                // String rawCommands
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #24                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #143                // class java/util/ArrayList
      18: dup
      19: invokespecial #144                // Method java/util/ArrayList."<init>":()V
      22: checkcast     #146                // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: astore        6
      33: iconst_0
      34: istore        7
      36: aload         6
      38: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        8
      45: aload         8
      47: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          241
      55: aload         8
      57: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        9
      64: aload         9
      66: astore        10
      68: iconst_0
      69: istore        11
      71: aload         10
      73: checkcast     #48                 // class java/lang/String
      76: astore        12
      78: iconst_0
      79: istore        13
      81: new           #148                // class kotlin/text/Regex
      84: dup
      85: ldc           #150                // String move ([0-9]+) from ([0-9]+) to ([0-9]+)
      87: invokespecial #153                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      90: aload         12
      92: checkcast     #60                 // class java/lang/CharSequence
      95: iconst_0
      96: iconst_2
      97: aconst_null
      98: invokestatic  #157                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     101: astore        14
     103: aload         14
     105: ifnull        212
     108: aload         14
     110: invokeinterface #163,  1          // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     115: astore        15
     117: aload         15
     119: ifnull        212
     122: aload         15
     124: checkcast     #24                 // class java/lang/Iterable
     127: invokestatic  #166                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     130: astore        16
     132: aload         16
     134: ifnull        212
     137: aload         16
     139: astore        17
     141: iconst_0
     142: istore        18
     144: new           #168                // class day05/Move
     147: dup
     148: aload         17
     150: iconst_1
     151: invokeinterface #172,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     156: dup
     157: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     160: checkcast     #178                // class kotlin/text/MatchGroup
     163: invokevirtual #182                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     166: invokestatic  #188                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     169: aload         17
     171: iconst_2
     172: invokeinterface #172,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     177: dup
     178: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     181: checkcast     #178                // class kotlin/text/MatchGroup
     184: invokevirtual #182                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     187: aload         17
     189: iconst_3
     190: invokeinterface #172,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     195: dup
     196: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     199: checkcast     #178                // class kotlin/text/MatchGroup
     202: invokevirtual #182                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     205: invokespecial #191                // Method day05/Move."<init>":(ILjava/lang/String;Ljava/lang/String;)V
     208: nop
     209: goto          213
     212: aconst_null
     213: nop
     214: dup
     215: ifnull        236
     218: astore        19
     220: iconst_0
     221: istore        20
     223: aload         4
     225: aload         19
     227: invokeinterface #195,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     232: pop
     233: goto          237
     236: pop
     237: nop
     238: goto          45
     241: nop
     242: aload         4
     244: checkcast     #72                 // class java/util/List
     247: nop
     248: areturn

  public static final kotlin.Pair<java.util.Map<java.lang.String, java.util.Stack<java.lang.Character>>, java.util.List<day05.Move>> parseInputFile();
    Code:
       0: new           #215                // class java/io/File
       3: dup
       4: ldc           #217                // String src/main/kotlin/day05/input.txt
       6: invokespecial #218                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #224                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #24                 // class java/lang/Iterable
      18: astore_0
      19: new           #226                // class kotlin/Pair
      22: dup
      23: invokestatic  #230                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      26: invokestatic  #230                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      29: invokespecial #233                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: aload_0
      38: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        4
      45: aload         4
      47: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          173
      55: aload         4
      57: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        5
      64: aload_3
      65: aload         5
      67: checkcast     #48                 // class java/lang/String
      70: astore        6
      72: astore        7
      74: iconst_0
      75: istore        8
      77: aload         6
      79: ldc           #235                // String move
      81: iconst_0
      82: iconst_2
      83: aconst_null
      84: invokestatic  #239                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      87: ifeq          118
      90: new           #226                // class kotlin/Pair
      93: dup
      94: aload         7
      96: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      99: aload         7
     101: invokevirtual #245                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     104: checkcast     #146                // class java/util/Collection
     107: aload         6
     109: invokestatic  #248                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     112: invokespecial #233                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     115: goto          169
     118: aload         6
     120: checkcast     #60                 // class java/lang/CharSequence
     123: invokeinterface #249,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     128: ifne          135
     131: iconst_1
     132: goto          136
     135: iconst_0
     136: ifeq          144
     139: aload         7
     141: goto          169
     144: new           #226                // class kotlin/Pair
     147: dup
     148: aload         7
     150: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     153: checkcast     #146                // class java/util/Collection
     156: aload         6
     158: invokestatic  #248                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     161: aload         7
     163: invokevirtual #245                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     166: invokespecial #233                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     169: astore_3
     170: goto          45
     173: aload_3
     174: astore_1
     175: iconst_0
     176: istore_2
     177: new           #226                // class kotlin/Pair
     180: dup
     181: aload_1
     182: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     185: checkcast     #72                 // class java/util/List
     188: invokestatic  #251                // Method parseStack:(Ljava/util/List;)Ljava/util/Map;
     191: aload_1
     192: invokevirtual #245                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     195: checkcast     #72                 // class java/util/List
     198: invokestatic  #253                // Method parseCommands:(Ljava/util/List;)Ljava/util/List;
     201: invokespecial #233                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     204: nop
     205: nop
     206: areturn

  public static final java.lang.String findFinalConfigurationMovingOneCrateAtTime();
    Code:
       0: invokestatic  #259                // Method parseInputFile:()Lkotlin/Pair;
       3: astore_0
       4: iconst_0
       5: istore_1
       6: aload_0
       7: invokevirtual #245                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      10: checkcast     #24                 // class java/lang/Iterable
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_2
      17: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore        4
      24: aload         4
      26: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      31: ifeq          198
      34: aload         4
      36: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      41: astore        5
      43: aload         5
      45: checkcast     #168                // class day05/Move
      48: astore        6
      50: iconst_0
      51: istore        7
      53: new           #18                 // class kotlin/ranges/IntRange
      56: dup
      57: iconst_1
      58: aload         6
      60: invokevirtual #262                // Method day05/Move.getQty:()I
      63: invokespecial #22                 // Method kotlin/ranges/IntRange."<init>":(II)V
      66: checkcast     #24                 // class java/lang/Iterable
      69: invokestatic  #266                // Method kotlin/collections/CollectionsKt.count:(Ljava/lang/Iterable;)I
      72: istore        8
      74: iconst_0
      75: istore        9
      77: iload         9
      79: iload         8
      81: if_icmpge     193
      84: iload         9
      86: istore        10
      88: iconst_0
      89: istore        11
      91: aload_0
      92: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      95: checkcast     #136                // class java/util/Map
      98: aload         6
     100: invokevirtual #269                // Method day05/Move.getSource:()Ljava/lang/String;
     103: invokeinterface #271,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     108: dup
     109: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     112: checkcast     #146                // class java/util/Collection
     115: invokeinterface #274,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     120: ifne          127
     123: iconst_1
     124: goto          128
     127: iconst_0
     128: ifeq          186
     131: aload_0
     132: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     135: checkcast     #136                // class java/util/Map
     138: aload         6
     140: invokevirtual #277                // Method day05/Move.getDest:()Ljava/lang/String;
     143: invokeinterface #271,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     148: dup
     149: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     152: checkcast     #81                 // class java/util/Stack
     155: aload_0
     156: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     159: checkcast     #136                // class java/util/Map
     162: aload         6
     164: invokevirtual #269                // Method day05/Move.getSource:()Ljava/lang/String;
     167: invokeinterface #271,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     172: dup
     173: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     176: checkcast     #81                 // class java/util/Stack
     179: invokevirtual #280                // Method java/util/Stack.pop:()Ljava/lang/Object;
     182: invokevirtual #104                // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     185: pop
     186: nop
     187: iinc          9, 1
     190: goto          77
     193: nop
     194: nop
     195: goto          24
     198: nop
     199: new           #18                 // class kotlin/ranges/IntRange
     202: dup
     203: iconst_1
     204: bipush        9
     206: invokespecial #22                 // Method kotlin/ranges/IntRange."<init>":(II)V
     209: checkcast     #24                 // class java/lang/Iterable
     212: astore_2
     213: ldc_w         #282                // String
     216: astore_3
     217: iconst_0
     218: istore        4
     220: aload_3
     221: astore        5
     223: aload_2
     224: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     229: astore        6
     231: aload         6
     233: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     238: ifeq          312
     241: aload         6
     243: checkcast     #42                 // class kotlin/collections/IntIterator
     246: invokevirtual #46                 // Method kotlin/collections/IntIterator.nextInt:()I
     249: istore        7
     251: aload         5
     253: iload         7
     255: istore        8
     257: astore        9
     259: iconst_0
     260: istore        10
     262: new           #284                // class java/lang/StringBuilder
     265: dup
     266: invokespecial #285                // Method java/lang/StringBuilder."<init>":()V
     269: aload         9
     271: invokevirtual #289                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     274: aload_0
     275: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     278: checkcast     #136                // class java/util/Map
     281: iload         8
     283: invokestatic  #52                 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
     286: invokeinterface #271,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     291: dup
     292: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     295: checkcast     #81                 // class java/util/Stack
     298: invokevirtual #292                // Method java/util/Stack.peek:()Ljava/lang/Object;
     301: invokevirtual #295                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     304: invokevirtual #298                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     307: astore        5
     309: goto          231
     312: aload         5
     314: nop
     315: nop
     316: areturn

  public static final java.lang.String findFinalConfigurationMovingMultipleCratesAtTime();
    Code:
       0: invokestatic  #259                // Method parseInputFile:()Lkotlin/Pair;
       3: astore_0
       4: iconst_0
       5: istore_1
       6: aload_0
       7: invokevirtual #245                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      10: checkcast     #24                 // class java/lang/Iterable
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_2
      17: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore        4
      24: aload         4
      26: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      31: ifeq          304
      34: aload         4
      36: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      41: astore        5
      43: aload         5
      45: checkcast     #168                // class day05/Move
      48: astore        6
      50: iconst_0
      51: istore        7
      53: new           #18                 // class kotlin/ranges/IntRange
      56: dup
      57: iconst_1
      58: aload         6
      60: invokevirtual #262                // Method day05/Move.getQty:()I
      63: invokespecial #22                 // Method kotlin/ranges/IntRange."<init>":(II)V
      66: checkcast     #24                 // class java/lang/Iterable
      69: astore        8
      71: invokestatic  #230                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      74: astore        9
      76: iconst_0
      77: istore        10
      79: aload         9
      81: astore        11
      83: aload         8
      85: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      90: astore        12
      92: aload         12
      94: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      99: ifeq          204
     102: aload         12
     104: checkcast     #42                 // class kotlin/collections/IntIterator
     107: invokevirtual #46                 // Method kotlin/collections/IntIterator.nextInt:()I
     110: istore        13
     112: aload         11
     114: astore        14
     116: iconst_0
     117: istore        15
     119: aload_0
     120: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     123: checkcast     #136                // class java/util/Map
     126: aload         6
     128: invokevirtual #269                // Method day05/Move.getSource:()Ljava/lang/String;
     131: invokeinterface #271,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     136: dup
     137: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     140: checkcast     #146                // class java/util/Collection
     143: invokeinterface #274,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     148: ifne          155
     151: iconst_1
     152: goto          156
     155: iconst_0
     156: ifeq          197
     159: aload         14
     161: checkcast     #146                // class java/util/Collection
     164: aload_0
     165: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     168: checkcast     #136                // class java/util/Map
     171: aload         6
     173: invokevirtual #269                // Method day05/Move.getSource:()Ljava/lang/String;
     176: invokeinterface #271,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     181: dup
     182: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     185: checkcast     #81                 // class java/util/Stack
     188: invokevirtual #280                // Method java/util/Stack.pop:()Ljava/lang/Object;
     191: invokestatic  #248                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     194: goto          199
     197: aload         14
     199: astore        11
     201: goto          92
     204: aload         11
     206: checkcast     #24                 // class java/lang/Iterable
     209: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     212: checkcast     #24                 // class java/lang/Iterable
     215: astore        8
     217: iconst_0
     218: istore        9
     220: aload         8
     222: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     227: astore        10
     229: aload         10
     231: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     236: ifeq          298
     239: aload         10
     241: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     246: astore        11
     248: aload         11
     250: checkcast     #97                 // class java/lang/Character
     253: invokevirtual #310                // Method java/lang/Character.charValue:()C
     256: istore        12
     258: iconst_0
     259: istore        13
     261: aload_0
     262: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     265: checkcast     #136                // class java/util/Map
     268: aload         6
     270: invokevirtual #277                // Method day05/Move.getDest:()Ljava/lang/String;
     273: invokeinterface #271,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     278: dup
     279: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     282: checkcast     #81                 // class java/util/Stack
     285: iload         12
     287: invokestatic  #100                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     290: invokevirtual #104                // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     293: pop
     294: nop
     295: goto          229
     298: nop
     299: nop
     300: nop
     301: goto          24
     304: nop
     305: new           #18                 // class kotlin/ranges/IntRange
     308: dup
     309: iconst_1
     310: bipush        9
     312: invokespecial #22                 // Method kotlin/ranges/IntRange."<init>":(II)V
     315: checkcast     #24                 // class java/lang/Iterable
     318: astore_2
     319: ldc_w         #282                // String
     322: astore_3
     323: iconst_0
     324: istore        4
     326: aload_3
     327: astore        5
     329: aload_2
     330: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     335: astore        6
     337: aload         6
     339: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     344: ifeq          418
     347: aload         6
     349: checkcast     #42                 // class kotlin/collections/IntIterator
     352: invokevirtual #46                 // Method kotlin/collections/IntIterator.nextInt:()I
     355: istore        7
     357: aload         5
     359: iload         7
     361: istore        8
     363: astore        9
     365: iconst_0
     366: istore        10
     368: new           #284                // class java/lang/StringBuilder
     371: dup
     372: invokespecial #285                // Method java/lang/StringBuilder."<init>":()V
     375: aload         9
     377: invokevirtual #289                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     380: aload_0
     381: invokevirtual #242                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     384: checkcast     #136                // class java/util/Map
     387: iload         8
     389: invokestatic  #52                 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
     392: invokeinterface #271,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     397: dup
     398: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     401: checkcast     #81                 // class java/util/Stack
     404: invokevirtual #292                // Method java/util/Stack.peek:()Ljava/lang/Object;
     407: invokevirtual #295                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     410: invokevirtual #298                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     413: astore        5
     415: goto          337
     418: aload         5
     420: nop
     421: nop
     422: areturn

  public static final void main();
    Code:
       0: new           #284                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #285                // Method java/lang/StringBuilder."<init>":()V
       7: ldc_w         #319                // String The top crates at the end using the CrateMover 9000 are:
      10: invokevirtual #289                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      13: invokestatic  #321                // Method findFinalConfigurationMovingOneCrateAtTime:()Ljava/lang/String;
      16: invokevirtual #289                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      19: invokevirtual #298                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      22: getstatic     #327                // Field java/lang/System.out:Ljava/io/PrintStream;
      25: swap
      26: invokevirtual #332                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      29: new           #284                // class java/lang/StringBuilder
      32: dup
      33: invokespecial #285                // Method java/lang/StringBuilder."<init>":()V
      36: ldc_w         #334                // String The top crates at the end using the CrateMover 9001 are:
      39: invokevirtual #289                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: invokestatic  #336                // Method findFinalConfigurationMovingMultipleCratesAtTime:()Ljava/lang/String;
      45: invokevirtual #289                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      48: invokevirtual #298                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: getstatic     #327                // Field java/lang/System.out:Ljava/io/PrintStream;
      54: swap
      55: invokevirtual #332                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      58: return

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


package day11

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

class IntModule(
    initial: Int = 0,
    oldModuleMap: Map<Int, Int>? = null
) {
    private val moduleMap = oldModuleMap ?: listOf(2,3,5,7,11,13,17,19,23).fold(emptyMap()) { acc, it -> acc + (it to initial%it)}

    operator fun plus(increment: Int): IntModule =
        moduleMap.keys.fold(emptyMap<Int, Int>()) { acc, it ->
            acc + (it to (moduleMap[it]!! + increment)%it)
        }.let {
            IntModule(oldModuleMap = it)
        }

    operator fun times(increment: Int): IntModule =
        moduleMap.keys.fold(emptyMap<Int, Int>()) { acc, it ->
            acc + (it to (moduleMap[it]!! * increment)%it)
        }.let {
            IntModule(oldModuleMap = it)
        }

    fun squared(): IntModule =
        moduleMap.keys.fold(emptyMap<Int, Int>()) { acc, it ->
            acc + (it to (moduleMap[it]!! * moduleMap[it]!!)%it)
        }.let {
            IntModule(oldModuleMap = it)
        }

    fun isDivisibleBy(other: Int): Boolean = moduleMap[other] == 0

}

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

    fun doATurn(monkeys: List<MonkeyModule>, verbose: Boolean = false): List<MonkeyModule> {
        if (items.isEmpty()) return monkeys
        val updatedMonkeys = items.fold(monkeys) { acc, item ->
            if (verbose) println("Monkey $id inspects an item with a worry level of $item.")
            val newLevel = operation(item)
            if (verbose) println("\tWorry level is now $newLevel.")
            val receiverMonkeyId = nextMonkey(newLevel)
            if (verbose) println("\tItem with worry level $newLevel is thrown to monkey $receiverMonkeyId.")
            val receiverMonkey = acc.first { it.id == receiverMonkeyId }

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

}

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

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

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

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

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

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

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

  public static final java.util.List<day11.MonkeyModule> parseInputFileWithModule();
    Code:
       0: new           #142                // class java/io/File
       3: dup
       4: ldc           #144                // String src/main/kotlin/day11/input.txt
       6: invokespecial #145                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #151                // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: checkcast     #26                 // class java/lang/CharSequence
      18: astore_0
      19: new           #18                 // class kotlin/text/Regex
      22: dup
      23: ldc           #153                // String \r?\n\r?\n
      25: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      28: astore_1
      29: iconst_0
      30: istore_2
      31: aload_1
      32: aload_0
      33: iload_2
      34: invokevirtual #157                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      37: checkcast     #159                // class java/lang/Iterable
      40: astore_0
      41: invokestatic  #164                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      44: astore_1
      45: iconst_0
      46: istore_2
      47: aload_1
      48: astore_3
      49: aload_0
      50: invokeinterface #168,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      55: astore        4
      57: aload         4
      59: invokeinterface #174,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      64: ifeq          371
      67: aload         4
      69: invokeinterface #178,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      74: astore        5
      76: aload_3
      77: aload         5
      79: checkcast     #48                 // class java/lang/String
      82: astore        6
      84: astore        7
      86: iconst_0
      87: istore        8
      89: new           #18                 // class kotlin/text/Regex
      92: dup
      93: ldc           #180                // String Monkey ([0-9]+)
      95: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      98: aload         6
     100: checkcast     #26                 // class java/lang/CharSequence
     103: iconst_0
     104: iconst_2
     105: aconst_null
     106: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     109: dup
     110: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     113: invokeinterface #40,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     118: iconst_1
     119: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     124: checkcast     #48                 // class java/lang/String
     127: invokestatic  #54                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     130: istore        9
     132: new           #18                 // class kotlin/text/Regex
     135: dup
     136: ldc           #182                // String [0-9]+
     138: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     141: new           #18                 // class kotlin/text/Regex
     144: dup
     145: ldc           #184                // String Starting items: ([0-9]+,? ?)+
     147: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     150: aload         6
     152: checkcast     #26                 // class java/lang/CharSequence
     155: iconst_0
     156: iconst_2
     157: aconst_null
     158: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     161: dup
     162: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     165: invokeinterface #188,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     170: checkcast     #26                 // class java/lang/CharSequence
     173: iconst_0
     174: iconst_2
     175: aconst_null
     176: invokestatic  #192                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
     179: invokestatic  #198                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     182: checkcast     #159                // class java/lang/Iterable
     185: astore        10
     187: iconst_0
     188: istore        11
     190: aload         10
     192: astore        12
     194: new           #200                // class java/util/ArrayList
     197: dup
     198: aload         10
     200: bipush        10
     202: invokestatic  #204                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     205: invokespecial #207                // Method java/util/ArrayList."<init>":(I)V
     208: checkcast     #209                // class java/util/Collection
     211: astore        13
     213: iconst_0
     214: istore        14
     216: aload         12
     218: invokeinterface #168,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     223: astore        15
     225: aload         15
     227: invokeinterface #174,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     232: ifeq          290
     235: aload         15
     237: invokeinterface #178,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     242: astore        16
     244: aload         13
     246: aload         16
     248: checkcast     #36                 // class kotlin/text/MatchResult
     251: astore        17
     253: astore        18
     255: iconst_0
     256: istore        19
     258: new           #211                // class day11/IntModule
     261: dup
     262: aload         17
     264: invokeinterface #188,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     269: invokestatic  #54                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     272: aconst_null
     273: iconst_2
     274: aconst_null
     275: invokespecial #214                // Method day11/IntModule."<init>":(ILjava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     278: aload         18
     280: swap
     281: invokeinterface #218,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     286: pop
     287: goto          225
     290: aload         13
     292: checkcast     #42                 // class java/util/List
     295: nop
     296: astore        20
     298: new           #18                 // class kotlin/text/Regex
     301: dup
     302: ldc           #220                // String Operation: new = [a-z0-9]+ [*+-] [a-z0-9]+
     304: invokespecial #24                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     307: aload         6
     309: checkcast     #26                 // class java/lang/CharSequence
     312: iconst_0
     313: iconst_2
     314: aconst_null
     315: invokestatic  #30                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     318: dup
     319: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     322: invokeinterface #188,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     327: invokestatic  #222                // Method parseOperationWithModule:(Ljava/lang/String;)Lkotlin/jvm/functions/Function1;
     330: astore        10
     332: aload         6
     334: invokestatic  #224                // Method parseNextMonkeyWithModule:(Ljava/lang/String;)Lkotlin/jvm/functions/Function1;
     337: astore        11
     339: aload         7
     341: checkcast     #209                // class java/util/Collection
     344: new           #226                // class day11/MonkeyModule
     347: dup
     348: iload         9
     350: aload         20
     352: aload         10
     354: aload         11
     356: lconst_0
     357: bipush        16
     359: aconst_null
     360: invokespecial #229                // Method day11/MonkeyModule."<init>":(ILjava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;JILkotlin/jvm/internal/DefaultConstructorMarker;)V
     363: invokestatic  #233                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     366: nop
     367: astore_3
     368: goto          57
     371: aload_3
     372: areturn

  public static final long findMonkeyBusinessAfterNthRound(int);
    Code:
       0: invokestatic  #262                // Method parseInputFileWithModule:()Ljava/util/List;
       3: astore_1
       4: aload_1
       5: checkcast     #209                // class java/util/Collection
       8: invokestatic  #266                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
      11: astore_2
      12: iconst_0
      13: iload_0
      14: invokestatic  #272                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      17: checkcast     #159                // class java/lang/Iterable
      20: astore        4
      22: iconst_0
      23: istore        5
      25: aload_1
      26: astore        6
      28: aload         4
      30: invokeinterface #168,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      35: astore        7
      37: aload         7
      39: invokeinterface #174,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          227
      47: aload         7
      49: checkcast     #274                // class kotlin/collections/IntIterator
      52: invokevirtual #278                // Method kotlin/collections/IntIterator.nextInt:()I
      55: istore        8
      57: aload         6
      59: astore        10
      61: iconst_0
      62: istore        11
      64: aload_2
      65: checkcast     #159                // class java/lang/Iterable
      68: astore        12
      70: iconst_0
      71: istore        13
      73: aload         10
      75: astore        14
      77: aload         12
      79: invokeinterface #168,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      84: astore        15
      86: aload         15
      88: invokeinterface #174,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      93: ifeq          219
      96: aload         15
      98: checkcast     #274                // class kotlin/collections/IntIterator
     101: invokevirtual #278                // Method kotlin/collections/IntIterator.nextInt:()I
     104: istore        16
     106: aload         14
     108: iload         16
     110: istore        17
     112: astore        18
     114: iconst_0
     115: istore        19
     117: aload         18
     119: checkcast     #159                // class java/lang/Iterable
     122: astore        20
     124: iconst_0
     125: istore        21
     127: aload         20
     129: invokeinterface #168,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     134: astore        22
     136: aload         22
     138: invokeinterface #174,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     143: ifeq          188
     146: aload         22
     148: invokeinterface #178,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     153: astore        23
     155: aload         23
     157: checkcast     #226                // class day11/MonkeyModule
     160: astore        24
     162: iconst_0
     163: istore        25
     165: aload         24
     167: invokevirtual #281                // Method day11/MonkeyModule.getId:()I
     170: iload         17
     172: if_icmpne     179
     175: iconst_1
     176: goto          180
     179: iconst_0
     180: ifeq          136
     183: aload         23
     185: goto          199
     188: new           #283                // class java/util/NoSuchElementException
     191: dup
     192: ldc_w         #285                // String Collection contains no element matching the predicate.
     195: invokespecial #286                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     198: athrow
     199: checkcast     #226                // class day11/MonkeyModule
     202: astore        26
     204: aload         26
     206: aload         18
     208: iconst_0
     209: iconst_2
     210: aconst_null
     211: invokestatic  #290                // Method day11/MonkeyModule.doATurn$default:(Lday11/MonkeyModule;Ljava/util/List;ZILjava/lang/Object;)Ljava/util/List;
     214: astore        14
     216: goto          86
     219: aload         14
     221: nop
     222: astore        6
     224: goto          37
     227: aload         6
     229: astore_3
     230: aload_3
     231: checkcast     #159                // class java/lang/Iterable
     234: astore        5
     236: iconst_0
     237: istore        6
     239: aload         5
     241: astore        7
     243: new           #200                // class java/util/ArrayList
     246: dup
     247: aload         5
     249: bipush        10
     251: invokestatic  #204                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     254: invokespecial #207                // Method java/util/ArrayList."<init>":(I)V
     257: checkcast     #209                // class java/util/Collection
     260: astore        8
     262: iconst_0
     263: istore        9
     265: aload         7
     267: invokeinterface #168,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     272: astore        10
     274: aload         10
     276: invokeinterface #174,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     281: ifeq          327
     284: aload         10
     286: invokeinterface #178,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     291: astore        11
     293: aload         8
     295: aload         11
     297: checkcast     #226                // class day11/MonkeyModule
     300: astore        12
     302: astore        27
     304: iconst_0
     305: istore        13
     307: aload         12
     309: invokevirtual #294                // Method day11/MonkeyModule.getMonkeyActivity:()J
     312: invokestatic  #300                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     315: aload         27
     317: swap
     318: invokeinterface #218,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     323: pop
     324: goto          274
     327: aload         8
     329: checkcast     #42                 // class java/util/List
     332: nop
     333: checkcast     #159                // class java/lang/Iterable
     336: invokestatic  #304                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     339: astore        4
     341: aload         4
     343: iconst_0
     344: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     349: checkcast     #306                // class java/lang/Number
     352: invokevirtual #309                // Method java/lang/Number.longValue:()J
     355: aload         4
     357: iconst_1
     358: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     363: checkcast     #306                // class java/lang/Number
     366: invokevirtual #309                // Method java/lang/Number.longValue:()J
     369: lmul
     370: lreturn

  public static final void main();
    Code:
       0: new           #331                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #333                // Method java/lang/StringBuilder."<init>":()V
       7: ldc_w         #335                // String The level of monkey business after 10000 rounds is
      10: invokevirtual #339                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      13: sipush        10000
      16: invokestatic  #341                // Method findMonkeyBusinessAfterNthRound:(I)J
      19: invokevirtual #344                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      22: invokevirtual #347                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      25: getstatic     #353                // Field java/lang/System.out:Ljava/io/PrintStream;
      28: swap
      29: invokevirtual #358                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      32: return

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

  private static final int parseNextMonkeyWithModule$lambda$0(int, int, int, day11.IntModule);
    Code:
       0: aload_3
       1: ldc_w         #364                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_3
       8: iload_0
       9: invokevirtual #368                // Method day11/IntModule.isDivisibleBy:(I)Z
      12: ifeq          19
      15: iload_1
      16: goto          20
      19: iload_2
      20: ireturn

  private static final day11.IntModule parseOperationWithModule$lambda$5$lambda$1(day11.IntModule);
    Code:
       0: aload_0
       1: ldc_w         #364                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: iconst_2
       9: invokevirtual #376                // Method day11/IntModule.times:(I)Lday11/IntModule;
      12: areturn

  private static final day11.IntModule parseOperationWithModule$lambda$5$lambda$2(day11.IntModule);
    Code:
       0: aload_0
       1: ldc_w         #364                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #380                // Method day11/IntModule.squared:()Lday11/IntModule;
      11: areturn

  private static final day11.IntModule parseOperationWithModule$lambda$5$lambda$3(java.lang.String, day11.IntModule);
    Code:
       0: aload_1
       1: ldc_w         #364                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: aload_0
       9: invokestatic  #54                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      12: invokevirtual #382                // Method day11/IntModule.plus:(I)Lday11/IntModule;
      15: areturn

  private static final day11.IntModule parseOperationWithModule$lambda$5$lambda$4(java.lang.String, day11.IntModule);
    Code:
       0: aload_1
       1: ldc_w         #364                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: aload_0
       9: invokestatic  #54                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      12: invokevirtual #376                // Method day11/IntModule.times:(I)Lday11/IntModule;
      15: areturn
}