package org.aoc2021

import java.nio.file.Files
import java.nio.file.Path
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

object Day23 {
    private const val hallwayLength = 11

    private val amphipodChars = setOf('A', 'B', 'C', 'D')
    private val roomIndices = setOf(2, 4, 6, 8)

    private val secondRow = listOf(Amphipod.DESERT, Amphipod.COPPER, Amphipod.BRONZE, Amphipod.AMBER)
    private val thirdRow = listOf(Amphipod.DESERT, Amphipod.BRONZE, Amphipod.AMBER, Amphipod.COPPER)

    enum class Amphipod(val energyPerStep: Int) {
        AMBER(1),
        BRONZE(10),
        COPPER(100),
        DESERT(1000),
    }

    private val winState = Amphipod.values().toList()

    sealed interface HallwayPosition

    data class Space(val occupant: Amphipod?) : HallwayPosition

    data class Room(val occupants: List<Amphipod?>) : HallwayPosition {
        fun withNewOccupant(occupant: Amphipod): Room {
            if (occupants.all { it == null }) {
                return Room(occupants.drop(1).plus(occupant))
            }
            val firstNullIndex = firstOpenIndex()
            return Room(
                occupants.take(firstNullIndex).plus(occupant).plus(occupants.drop(firstNullIndex + 1))
            )
        }

        fun withoutTopOccupant(): Room {
            val firstNonNullIndex = firstOccupiedIndex()
            return Room(
                occupants.take(firstNonNullIndex).plus(null).plus(occupants.drop(firstNonNullIndex + 1))
            )
        }

        fun firstOpenIndex(): Int {
            return occupants.indexOfLast { it == null }
        }

        fun firstOccupiedIndex(): Int {
            return occupants.indexOfFirst { it != null }
        }
    }

    data class State(val distance: Int, val hallway: List<HallwayPosition>)

    private fun solve(lines: List<String>, expandMiddle: Boolean): Int {
        val hallway = parseInput(lines, expandMiddle)

        val pq = PriorityQueue<State> { a, b ->
            a.distance.compareTo(b.distance)
        }

        pq.add(State(0, hallway))

        val stateToMinDistance = mutableMapOf<List<HallwayPosition>, Int>()

        while (!pq.isEmpty()) {
            val state = pq.remove()

            if (state.distance >= (stateToMinDistance[state.hallway] ?: Integer.MAX_VALUE)) {
                continue
            }

            stateToMinDistance[state.hallway] = state.distance

            if (isWinningState(state.hallway)) {
                return state.distance
            }

            generatePossibleMoves(state.hallway).forEach { (moveDistance, moveState) ->
                val newDistance = state.distance + moveDistance
                if (newDistance < (stateToMinDistance[moveState] ?: Integer.MAX_VALUE)) {
                    pq.add(State(newDistance, moveState))
                }
            }
        }

        throw IllegalArgumentException("no winning solution found")
    }

    private fun isWinningState(state: List<HallwayPosition>): Boolean {
        return state.filterIsInstance<Room>().zip(winState).all { (room, targetAmphipod) ->
            room.occupants.all { it == targetAmphipod }
        }
    }

    private fun generatePossibleMoves(hallway: List<HallwayPosition>): List<Pair<Int, List<HallwayPosition>>> {
        val moves = mutableListOf<Pair<Int, List<HallwayPosition>>>()

        hallway.forEachIndexed { i, position ->
            when (position) {
                is Space -> moves.addAll(generateSpaceMoves(hallway, i, position))
                is Room -> moves.addAll(generateRoomMoves(hallway, i, position))
            }
        }

        return moves.toList()
    }

    private fun generateSpaceMoves(
        hallway: List<HallwayPosition>,
        i: Int,
        space: Space,
    ): List<Pair<Int, List<HallwayPosition>>> {
        if (space.occupant == null) {
            return listOf()
        }

        val targetIndex = 2 * winState.indexOf(space.occupant) + 2
        val targetRoom = hallway[targetIndex] as Room
        if (canMoveToRoom(hallway, i, targetIndex)) {
            val distance = space.occupant.energyPerStep * (abs(i - targetIndex) + 1 + targetRoom.firstOpenIndex())
            val newState = hallway.map { position ->
                if (position === space) {
                    Space(null)
                } else if (position === targetRoom) {
                    targetRoom.withNewOccupant(space.occupant)
                } else {
                    position
                }
            }
            return listOf(distance to newState)
        }

        return listOf()
    }

    private fun generateRoomMoves(
        hallway: List<HallwayPosition>,
        i: Int,
        room: Room,
    ): List<Pair<Int, List<HallwayPosition>>> {
        val targetAmphipod = winState[(i - 2) / 2]
        if (room.occupants.all { it == null || it == targetAmphipod }) {
            return listOf()
        }

        val firstOccupiedIndex = room.firstOccupiedIndex()
        val first = room.occupants[firstOccupiedIndex]!!

        if (first != targetAmphipod) {
            val firstTargetIndex = 2 * winState.indexOf(first) + 2
            val firstTargetRoom = hallway[firstTargetIndex] as Room
            if (canMoveToRoom(hallway, i, firstTargetIndex)) {
                val steps = abs(i - firstTargetIndex) + 2 + firstOccupiedIndex + firstTargetRoom.firstOpenIndex()
                val distance = first.energyPerStep * steps
                val newState = hallway.map { position ->
                    if (position === room) {
                        room.withoutTopOccupant()
                    } else if (position === firstTargetRoom) {
                        firstTargetRoom.withNewOccupant(first)
                    } else {
                        position
                    }
                }
                return listOf(distance to newState)
            }
        }

        val moves = mutableListOf<Pair<Int, List<HallwayPosition>>>()
        for (j in hallway.indices) {
            val space = hallway[j]
            if (space !is Space) {
                continue
            }

            if (canMoveToSpace(hallway, i, j)) {
                val distance = first.energyPerStep * (abs(i - j) + 1 + room.firstOccupiedIndex())
                val newState = hallway.map { position ->
                    if (position === room) {
                        room.withoutTopOccupant()
                    } else if (position === space) {
                        Space(first)
                    } else {
                        position
                    }
                }
                moves.add(distance to newState)
            }
        }
        return moves.toList()
    }

    private fun canMoveToSpace(
        hallway: List<HallwayPosition>,
        i: Int,
        targetIndex: Int,
    ): Boolean {
        val space = hallway[targetIndex] as Space
        if (space.occupant != null) {
            return false
        }
        return canMoveToPosition(hallway, i, targetIndex)
    }

    private fun canMoveToRoom(
        hallway: List<HallwayPosition>,
        i: Int,
        targetIndex: Int,
    ): Boolean {
        val targetAmphipod = winState[(targetIndex - 2) / 2]
        val targetRoom = hallway[targetIndex] as Room
        if (!targetRoom.occupants.all { it == null || it == targetAmphipod }) {
            return false
        }

        return canMoveToPosition(hallway, i, targetIndex)
    }

    private fun canMoveToPosition(
        hallway: List<HallwayPosition>,
        i: Int,
        targetIndex: Int,
    ): Boolean {
        val start = min(i, targetIndex)
        val end = max(i, targetIndex)
        return ((start + 1) until end).all { j ->
            val position = hallway[j]
            position !is Space || position.occupant == null
        }
    }

    private fun parseInput(lines: List<String>, expandMiddle: Boolean): List<HallwayPosition> {
        val frontOccupants = lines[2].filter(amphipodChars::contains).toCharArray()
        val backOccupants = lines[3].filter(amphipodChars::contains).toCharArray()

        val roomOccupants = frontOccupants.zip(backOccupants)
        var occupantsIndex = 0
        val result = mutableListOf<HallwayPosition>()
        for (i in 0 until hallwayLength) {
            if (roomIndices.contains(i)) {
                val (frontOccupant, backOccupant) = roomOccupants[occupantsIndex]
                val room = if (expandMiddle) {
                    Room(listOf(
                        charToAmphipod(frontOccupant),
                        secondRow[(i - 2) / 2],
                        thirdRow[(i - 2) / 2],
                        charToAmphipod(backOccupant),
                    ))
                } else {
                    Room(listOf(charToAmphipod(frontOccupant), charToAmphipod(backOccupant)))
                }
                result.add(room)

                occupantsIndex++
            } else {
                result.add(Space(occupant = null))
            }
        }

        return result.toList()
    }

    private fun charToAmphipod(c: Char): Amphipod = when (c) {
        'A' -> Amphipod.AMBER
        'B' -> Amphipod.BRONZE
        'C' -> Amphipod.COPPER
        'D' -> Amphipod.DESERT
        else -> throw IllegalArgumentException("$c")
    }

    @JvmStatic
    fun main(args: Array<String>) {
        val lines = Files.readAllLines(Path.of("input23.txt"), Charsets.UTF_8)
        val solution1 = solve(lines, false)
        println(solution1)
        val solution2 = solve(lines, true)
        println(solution2)
    }
}

Compiled from "Day23.kt"
public final class org.aoc2021.Day23$Room implements org.aoc2021.Day23$HallwayPosition {
  private final java.util.List<org.aoc2021.Day23$Amphipod> occupants;

  public org.aoc2021.Day23$Room(java.util.List<? extends org.aoc2021.Day23$Amphipod>);
    Code:
       0: aload_1
       1: ldc           #12                 // String occupants
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #21                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #24                 // Field occupants:Ljava/util/List;
      15: return

  public final java.util.List<org.aoc2021.Day23$Amphipod> getOccupants();
    Code:
       0: aload_0
       1: getfield      #24                 // Field occupants:Ljava/util/List;
       4: areturn

  public final org.aoc2021.Day23$Room withNewOccupant(org.aoc2021.Day23$Amphipod);
    Code:
       0: aload_1
       1: ldc           #33                 // String occupant
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #24                 // Field occupants:Ljava/util/List;
      10: checkcast     #35                 // class java/lang/Iterable
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_2
      17: instanceof    #37                 // class java/util/Collection
      20: ifeq          39
      23: aload_2
      24: checkcast     #37                 // class java/util/Collection
      27: invokeinterface #41,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      32: ifeq          39
      35: iconst_1
      36: goto          94
      39: aload_2
      40: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        4
      47: aload         4
      49: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          93
      57: aload         4
      59: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        5
      66: aload         5
      68: checkcast     #56                 // class org/aoc2021/Day23$Amphipod
      71: astore        6
      73: iconst_0
      74: istore        7
      76: aload         6
      78: ifnonnull     85
      81: iconst_1
      82: goto          86
      85: iconst_0
      86: ifne          47
      89: iconst_0
      90: goto          94
      93: iconst_1
      94: ifeq          123
      97: new           #2                  // class org/aoc2021/Day23$Room
     100: dup
     101: aload_0
     102: getfield      #24                 // Field occupants:Ljava/util/List;
     105: checkcast     #35                 // class java/lang/Iterable
     108: iconst_1
     109: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     112: checkcast     #37                 // class java/util/Collection
     115: aload_1
     116: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     119: invokespecial #68                 // Method "<init>":(Ljava/util/List;)V
     122: areturn
     123: aload_0
     124: invokevirtual #72                 // Method firstOpenIndex:()I
     127: istore_2
     128: new           #2                  // class org/aoc2021/Day23$Room
     131: dup
     132: aload_0
     133: getfield      #24                 // Field occupants:Ljava/util/List;
     136: checkcast     #35                 // class java/lang/Iterable
     139: iload_2
     140: invokestatic  #75                 // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     143: checkcast     #37                 // class java/util/Collection
     146: aload_1
     147: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     150: checkcast     #37                 // class java/util/Collection
     153: aload_0
     154: getfield      #24                 // Field occupants:Ljava/util/List;
     157: checkcast     #35                 // class java/lang/Iterable
     160: iload_2
     161: iconst_1
     162: iadd
     163: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     166: checkcast     #35                 // class java/lang/Iterable
     169: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     172: invokespecial #68                 // Method "<init>":(Ljava/util/List;)V
     175: areturn

  public final org.aoc2021.Day23$Room withoutTopOccupant();
    Code:
       0: aload_0
       1: invokevirtual #93                 // Method firstOccupiedIndex:()I
       4: istore_1
       5: new           #2                  // class org/aoc2021/Day23$Room
       8: dup
       9: aload_0
      10: getfield      #24                 // Field occupants:Ljava/util/List;
      13: checkcast     #35                 // class java/lang/Iterable
      16: iload_1
      17: invokestatic  #75                 // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      20: checkcast     #37                 // class java/util/Collection
      23: aconst_null
      24: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
      27: checkcast     #37                 // class java/util/Collection
      30: aload_0
      31: getfield      #24                 // Field occupants:Ljava/util/List;
      34: checkcast     #35                 // class java/lang/Iterable
      37: iload_1
      38: iconst_1
      39: iadd
      40: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      43: checkcast     #35                 // class java/lang/Iterable
      46: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
      49: invokespecial #68                 // Method "<init>":(Ljava/util/List;)V
      52: areturn

  public final int firstOpenIndex();
    Code:
       0: aload_0
       1: getfield      #24                 // Field occupants:Ljava/util/List;
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: aload_1
       9: invokeinterface #99,  1           // InterfaceMethod java/util/List.size:()I
      14: invokeinterface #103,  2          // InterfaceMethod java/util/List.listIterator:(I)Ljava/util/ListIterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #108,  1          // InterfaceMethod java/util/ListIterator.hasPrevious:()Z
      26: ifeq          65
      29: aload_3
      30: invokeinterface #111,  1          // InterfaceMethod java/util/ListIterator.previous:()Ljava/lang/Object;
      35: checkcast     #56                 // class org/aoc2021/Day23$Amphipod
      38: astore        4
      40: iconst_0
      41: istore        5
      43: aload         4
      45: ifnonnull     52
      48: iconst_1
      49: goto          53
      52: iconst_0
      53: ifeq          20
      56: aload_3
      57: invokeinterface #114,  1          // InterfaceMethod java/util/ListIterator.nextIndex:()I
      62: goto          66
      65: iconst_m1
      66: ireturn

  public final int firstOccupiedIndex();
    Code:
       0: aload_0
       1: getfield      #24                 // Field occupants:Ljava/util/List;
       4: astore_1
       5: iconst_0
       6: istore_2
       7: iconst_0
       8: istore_3
       9: aload_1
      10: invokeinterface #120,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      15: astore        4
      17: aload         4
      19: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          69
      27: aload         4
      29: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: astore        5
      36: aload         5
      38: checkcast     #56                 // class org/aoc2021/Day23$Amphipod
      41: astore        6
      43: iconst_0
      44: istore        7
      46: aload         6
      48: ifnull        55
      51: iconst_1
      52: goto          56
      55: iconst_0
      56: ifeq          63
      59: iload_3
      60: goto          70
      63: iinc          3, 1
      66: goto          17
      69: iconst_m1
      70: ireturn

  public final java.util.List<org.aoc2021.Day23$Amphipod> component1();
    Code:
       0: aload_0
       1: getfield      #24                 // Field occupants:Ljava/util/List;
       4: areturn

  public final org.aoc2021.Day23$Room copy(java.util.List<? extends org.aoc2021.Day23$Amphipod>);
    Code:
       0: aload_1
       1: ldc           #12                 // String occupants
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class org/aoc2021/Day23$Room
       9: dup
      10: aload_1
      11: invokespecial #68                 // Method "<init>":(Ljava/util/List;)V
      14: areturn

  public static org.aoc2021.Day23$Room copy$default(org.aoc2021.Day23$Room, java.util.List, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #24                 // Field occupants:Ljava/util/List;
      10: astore_1
      11: aload_0
      12: aload_1
      13: invokevirtual #133                // Method copy:(Ljava/util/List;)Lorg/aoc2021/Day23$Room;
      16: areturn

  public java.lang.String toString();
    Code:
       0: new           #137                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #138                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #140                // String Room(occupants=
       9: invokevirtual #144                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #24                 // Field occupants:Ljava/util/List;
      16: invokevirtual #147                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: bipush        41
      21: invokevirtual #150                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      24: invokevirtual #152                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      27: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #24                 // Field occupants:Ljava/util/List;
       4: invokevirtual #155                // Method java/lang/Object.hashCode:()I
       7: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class org/aoc2021/Day23$Room
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class org/aoc2021/Day23$Room
      20: astore_2
      21: aload_0
      22: getfield      #24                 // Field occupants:Ljava/util/List;
      25: aload_2
      26: getfield      #24                 // Field occupants:Ljava/util/List;
      29: invokestatic  #162                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: iconst_1
      38: ireturn
}

Compiled from "Day23.kt"
public final class org.aoc2021.Day23$Amphipod extends java.lang.Enum<org.aoc2021.Day23$Amphipod> {
  private final int energyPerStep;

  public static final org.aoc2021.Day23$Amphipod AMBER;

  public static final org.aoc2021.Day23$Amphipod BRONZE;

  public static final org.aoc2021.Day23$Amphipod COPPER;

  public static final org.aoc2021.Day23$Amphipod DESERT;

  private static final org.aoc2021.Day23$Amphipod[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private org.aoc2021.Day23$Amphipod(int);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #11                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: aload_0
       7: iload_3
       8: putfield      #15                 // Field energyPerStep:I
      11: return

  public final int getEnergyPerStep();
    Code:
       0: aload_0
       1: getfield      #15                 // Field energyPerStep:I
       4: ireturn

  public static org.aoc2021.Day23$Amphipod[] values();
    Code:
       0: getstatic     #28                 // Field $VALUES:[Lorg/aoc2021/Day23$Amphipod;
       3: invokevirtual #34                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #35                 // class "[Lorg/aoc2021/Day23$Amphipod;"
       9: areturn

  public static org.aoc2021.Day23$Amphipod valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class org/aoc2021/Day23$Amphipod
       2: aload_0
       3: invokestatic  #40                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class org/aoc2021/Day23$Amphipod
       9: areturn

  public static kotlin.enums.EnumEntries<org.aoc2021.Day23$Amphipod> getEntries();
    Code:
       0: getstatic     #49                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final org.aoc2021.Day23$Amphipod[] $values();
    Code:
       0: iconst_4
       1: anewarray     #2                  // class org/aoc2021/Day23$Amphipod
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #53                 // Field AMBER:Lorg/aoc2021/Day23$Amphipod;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #56                 // Field BRONZE:Lorg/aoc2021/Day23$Amphipod;
      16: aastore
      17: aload_0
      18: iconst_2
      19: getstatic     #59                 // Field COPPER:Lorg/aoc2021/Day23$Amphipod;
      22: aastore
      23: aload_0
      24: iconst_3
      25: getstatic     #62                 // Field DESERT:Lorg/aoc2021/Day23$Amphipod;
      28: aastore
      29: aload_0
      30: areturn

  static {};
    Code:
       0: new           #2                  // class org/aoc2021/Day23$Amphipod
       3: dup
       4: ldc           #65                 // String AMBER
       6: iconst_0
       7: iconst_1
       8: invokespecial #67                 // Method "<init>":(Ljava/lang/String;II)V
      11: putstatic     #53                 // Field AMBER:Lorg/aoc2021/Day23$Amphipod;
      14: new           #2                  // class org/aoc2021/Day23$Amphipod
      17: dup
      18: ldc           #68                 // String BRONZE
      20: iconst_1
      21: bipush        10
      23: invokespecial #67                 // Method "<init>":(Ljava/lang/String;II)V
      26: putstatic     #56                 // Field BRONZE:Lorg/aoc2021/Day23$Amphipod;
      29: new           #2                  // class org/aoc2021/Day23$Amphipod
      32: dup
      33: ldc           #69                 // String COPPER
      35: iconst_2
      36: bipush        100
      38: invokespecial #67                 // Method "<init>":(Ljava/lang/String;II)V
      41: putstatic     #59                 // Field COPPER:Lorg/aoc2021/Day23$Amphipod;
      44: new           #2                  // class org/aoc2021/Day23$Amphipod
      47: dup
      48: ldc           #70                 // String DESERT
      50: iconst_3
      51: sipush        1000
      54: invokespecial #67                 // Method "<init>":(Ljava/lang/String;II)V
      57: putstatic     #62                 // Field DESERT:Lorg/aoc2021/Day23$Amphipod;
      60: invokestatic  #72                 // Method $values:()[Lorg/aoc2021/Day23$Amphipod;
      63: putstatic     #28                 // Field $VALUES:[Lorg/aoc2021/Day23$Amphipod;
      66: getstatic     #28                 // Field $VALUES:[Lorg/aoc2021/Day23$Amphipod;
      69: checkcast     #74                 // class "[Ljava/lang/Enum;"
      72: invokestatic  #80                 // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      75: putstatic     #49                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      78: return
}

Compiled from "Day23.kt"
public interface org.aoc2021.Day23$HallwayPosition {
}

Compiled from "Day23.kt"
public final class org.aoc2021.Day23 {
  public static final org.aoc2021.Day23 INSTANCE;

  private static final int hallwayLength;

  private static final java.util.Set<java.lang.Character> amphipodChars;

  private static final java.util.Set<java.lang.Integer> roomIndices;

  private static final java.util.List<org.aoc2021.Day23$Amphipod> secondRow;

  private static final java.util.List<org.aoc2021.Day23$Amphipod> thirdRow;

  private static final java.util.List<org.aoc2021.Day23$Amphipod> winState;

  private org.aoc2021.Day23();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  private final int solve(java.util.List<java.lang.String>, boolean);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #17                 // Method parseInput:(Ljava/util/List;Z)Ljava/util/List;
       6: astore_3
       7: new           #19                 // class java/util/PriorityQueue
      10: dup
      11: invokedynamic #39,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
      16: invokedynamic #50,  0             // InvokeDynamic #1:compare:(Lkotlin/jvm/functions/Function2;)Ljava/util/Comparator;
      21: invokespecial #53                 // Method java/util/PriorityQueue."<init>":(Ljava/util/Comparator;)V
      24: astore        4
      26: aload         4
      28: new           #55                 // class org/aoc2021/Day23$State
      31: dup
      32: iconst_0
      33: aload_3
      34: invokespecial #58                 // Method org/aoc2021/Day23$State."<init>":(ILjava/util/List;)V
      37: invokevirtual #62                 // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
      40: pop
      41: new           #64                 // class java/util/LinkedHashMap
      44: dup
      45: invokespecial #65                 // Method java/util/LinkedHashMap."<init>":()V
      48: checkcast     #67                 // class java/util/Map
      51: astore        5
      53: aload         4
      55: invokevirtual #71                 // Method java/util/PriorityQueue.isEmpty:()Z
      58: ifne          293
      61: aload         4
      63: invokevirtual #75                 // Method java/util/PriorityQueue.remove:()Ljava/lang/Object;
      66: checkcast     #55                 // class org/aoc2021/Day23$State
      69: astore        6
      71: aload         6
      73: invokevirtual #79                 // Method org/aoc2021/Day23$State.getDistance:()I
      76: aload         5
      78: aload         6
      80: invokevirtual #83                 // Method org/aoc2021/Day23$State.getHallway:()Ljava/util/List;
      83: invokeinterface #87,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      88: checkcast     #89                 // class java/lang/Integer
      91: dup
      92: ifnull        101
      95: invokevirtual #92                 // Method java/lang/Integer.intValue:()I
      98: goto          104
     101: pop
     102: ldc           #93                 // int 2147483647
     104: if_icmplt     110
     107: goto          53
     110: aload         5
     112: aload         6
     114: invokevirtual #83                 // Method org/aoc2021/Day23$State.getHallway:()Ljava/util/List;
     117: aload         6
     119: invokevirtual #79                 // Method org/aoc2021/Day23$State.getDistance:()I
     122: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     125: invokeinterface #100,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     130: pop
     131: aload_0
     132: aload         6
     134: invokevirtual #83                 // Method org/aoc2021/Day23$State.getHallway:()Ljava/util/List;
     137: invokespecial #104                // Method isWinningState:(Ljava/util/List;)Z
     140: ifeq          149
     143: aload         6
     145: invokevirtual #79                 // Method org/aoc2021/Day23$State.getDistance:()I
     148: ireturn
     149: aload_0
     150: aload         6
     152: invokevirtual #83                 // Method org/aoc2021/Day23$State.getHallway:()Ljava/util/List;
     155: invokespecial #108                // Method generatePossibleMoves:(Ljava/util/List;)Ljava/util/List;
     158: checkcast     #110                // class java/lang/Iterable
     161: astore        7
     163: iconst_0
     164: istore        8
     166: aload         7
     168: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     173: astore        9
     175: aload         9
     177: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     182: ifeq          289
     185: aload         9
     187: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     192: astore        10
     194: aload         10
     196: checkcast     #124                // class kotlin/Pair
     199: astore        11
     201: iconst_0
     202: istore        12
     204: aload         11
     206: invokevirtual #127                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     209: checkcast     #129                // class java/lang/Number
     212: invokevirtual #130                // Method java/lang/Number.intValue:()I
     215: istore        13
     217: aload         11
     219: invokevirtual #133                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     222: checkcast     #135                // class java/util/List
     225: astore        14
     227: aload         6
     229: invokevirtual #79                 // Method org/aoc2021/Day23$State.getDistance:()I
     232: iload         13
     234: iadd
     235: istore        15
     237: iload         15
     239: aload         5
     241: aload         14
     243: invokeinterface #87,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     248: checkcast     #89                 // class java/lang/Integer
     251: dup
     252: ifnull        261
     255: invokevirtual #92                 // Method java/lang/Integer.intValue:()I
     258: goto          264
     261: pop
     262: ldc           #93                 // int 2147483647
     264: if_icmpge     284
     267: aload         4
     269: new           #55                 // class org/aoc2021/Day23$State
     272: dup
     273: iload         15
     275: aload         14
     277: invokespecial #58                 // Method org/aoc2021/Day23$State."<init>":(ILjava/util/List;)V
     280: invokevirtual #62                 // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
     283: pop
     284: nop
     285: nop
     286: goto          175
     289: nop
     290: goto          53
     293: new           #137                // class java/lang/IllegalArgumentException
     296: dup
     297: ldc           #139                // String no winning solution found
     299: invokespecial #142                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     302: athrow

  private final boolean isWinningState(java.util.List<? extends org.aoc2021.Day23$HallwayPosition>);
    Code:
       0: aload_1
       1: checkcast     #110                // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: astore        4
      10: new           #166                // class java/util/ArrayList
      13: dup
      14: invokespecial #167                // Method java/util/ArrayList."<init>":()V
      17: checkcast     #169                // class java/util/Collection
      20: astore        5
      22: iconst_0
      23: istore        6
      25: aload         4
      27: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      32: astore        7
      34: aload         7
      36: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          74
      44: aload         7
      46: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: astore        8
      53: aload         8
      55: instanceof    #171                // class org/aoc2021/Day23$Room
      58: ifeq          34
      61: aload         5
      63: aload         8
      65: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      70: pop
      71: goto          34
      74: aload         5
      76: checkcast     #135                // class java/util/List
      79: nop
      80: checkcast     #110                // class java/lang/Iterable
      83: getstatic     #175                // Field winState:Ljava/util/List;
      86: checkcast     #110                // class java/lang/Iterable
      89: invokestatic  #181                // Method kotlin/collections/CollectionsKt.zip:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
      92: checkcast     #110                // class java/lang/Iterable
      95: astore_2
      96: iconst_0
      97: istore_3
      98: aload_2
      99: instanceof    #169                // class java/util/Collection
     102: ifeq          121
     105: aload_2
     106: checkcast     #169                // class java/util/Collection
     109: invokeinterface #182,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     114: ifeq          121
     117: iconst_1
     118: goto          283
     121: aload_2
     122: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     127: astore        4
     129: aload         4
     131: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     136: ifeq          282
     139: aload         4
     141: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     146: astore        5
     148: aload         5
     150: checkcast     #124                // class kotlin/Pair
     153: astore        6
     155: iconst_0
     156: istore        7
     158: aload         6
     160: invokevirtual #127                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     163: checkcast     #171                // class org/aoc2021/Day23$Room
     166: astore        8
     168: aload         6
     170: invokevirtual #133                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     173: checkcast     #184                // class org/aoc2021/Day23$Amphipod
     176: astore        9
     178: aload         8
     180: invokevirtual #187                // Method org/aoc2021/Day23$Room.getOccupants:()Ljava/util/List;
     183: checkcast     #110                // class java/lang/Iterable
     186: astore        10
     188: iconst_0
     189: istore        11
     191: aload         10
     193: instanceof    #169                // class java/util/Collection
     196: ifeq          216
     199: aload         10
     201: checkcast     #169                // class java/util/Collection
     204: invokeinterface #182,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     209: ifeq          216
     212: iconst_1
     213: goto          274
     216: aload         10
     218: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     223: astore        12
     225: aload         12
     227: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     232: ifeq          273
     235: aload         12
     237: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     242: astore        13
     244: aload         13
     246: checkcast     #184                // class org/aoc2021/Day23$Amphipod
     249: astore        14
     251: iconst_0
     252: istore        15
     254: aload         14
     256: aload         9
     258: if_acmpne     265
     261: iconst_1
     262: goto          266
     265: iconst_0
     266: ifne          225
     269: iconst_0
     270: goto          274
     273: iconst_1
     274: nop
     275: ifne          129
     278: iconst_0
     279: goto          283
     282: iconst_1
     283: ireturn

  private final java.util.List<kotlin.Pair<java.lang.Integer, java.util.List<org.aoc2021.Day23$HallwayPosition>>> generatePossibleMoves(java.util.List<? extends org.aoc2021.Day23$HallwayPosition>);
    Code:
       0: new           #166                // class java/util/ArrayList
       3: dup
       4: invokespecial #167                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #135                // class java/util/List
      10: astore_2
      11: aload_1
      12: checkcast     #110                // class java/lang/Iterable
      15: astore_3
      16: iconst_0
      17: istore        4
      19: iconst_0
      20: istore        5
      22: aload_3
      23: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      28: astore        6
      30: aload         6
      32: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      37: ifeq          164
      40: aload         6
      42: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      47: astore        7
      49: iload         5
      51: iinc          5, 1
      54: istore        8
      56: iload         8
      58: ifge          64
      61: invokestatic  #207                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      64: iload         8
      66: aload         7
      68: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
      71: astore        9
      73: istore        10
      75: iconst_0
      76: istore        11
      78: aload         9
      80: astore        12
      82: aload         12
      84: instanceof    #211                // class org/aoc2021/Day23$Space
      87: ifeq          116
      90: aload_2
      91: getstatic     #214                // Field INSTANCE:Lorg/aoc2021/Day23;
      94: aload_1
      95: iload         10
      97: aload         9
      99: checkcast     #211                // class org/aoc2021/Day23$Space
     102: invokespecial #218                // Method generateSpaceMoves:(Ljava/util/List;ILorg/aoc2021/Day23$Space;)Ljava/util/List;
     105: checkcast     #169                // class java/util/Collection
     108: invokeinterface #222,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     113: goto          158
     116: aload         12
     118: instanceof    #171                // class org/aoc2021/Day23$Room
     121: ifeq          150
     124: aload_2
     125: getstatic     #214                // Field INSTANCE:Lorg/aoc2021/Day23;
     128: aload_1
     129: iload         10
     131: aload         9
     133: checkcast     #171                // class org/aoc2021/Day23$Room
     136: invokespecial #226                // Method generateRoomMoves:(Ljava/util/List;ILorg/aoc2021/Day23$Room;)Ljava/util/List;
     139: checkcast     #169                // class java/util/Collection
     142: invokeinterface #222,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     147: goto          158
     150: new           #228                // class kotlin/NoWhenBranchMatchedException
     153: dup
     154: invokespecial #229                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     157: athrow
     158: pop
     159: nop
     160: nop
     161: goto          30
     164: nop
     165: aload_2
     166: checkcast     #110                // class java/lang/Iterable
     169: invokestatic  #233                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     172: areturn

  private final java.util.List<kotlin.Pair<java.lang.Integer, java.util.List<org.aoc2021.Day23$HallwayPosition>>> generateSpaceMoves(java.util.List<? extends org.aoc2021.Day23$HallwayPosition>, int, org.aoc2021.Day23$Space);
    Code:
       0: aload_3
       1: invokevirtual #247                // Method org/aoc2021/Day23$Space.getOccupant:()Lorg/aoc2021/Day23$Amphipod;
       4: ifnonnull     11
       7: invokestatic  #250                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      10: areturn
      11: iconst_2
      12: getstatic     #175                // Field winState:Ljava/util/List;
      15: aload_3
      16: invokevirtual #247                // Method org/aoc2021/Day23$Space.getOccupant:()Lorg/aoc2021/Day23$Amphipod;
      19: invokeinterface #254,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
      24: imul
      25: iconst_2
      26: iadd
      27: istore        4
      29: aload_1
      30: iload         4
      32: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      37: dup
      38: ldc_w         #259                // String null cannot be cast to non-null type org.aoc2021.Day23.Room
      41: invokestatic  #265                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
      44: checkcast     #171                // class org/aoc2021/Day23$Room
      47: astore        5
      49: aload_0
      50: aload_1
      51: iload_2
      52: iload         4
      54: invokespecial #269                // Method canMoveToRoom:(Ljava/util/List;II)Z
      57: ifeq          241
      60: aload_3
      61: invokevirtual #247                // Method org/aoc2021/Day23$Space.getOccupant:()Lorg/aoc2021/Day23$Amphipod;
      64: invokevirtual #272                // Method org/aoc2021/Day23$Amphipod.getEnergyPerStep:()I
      67: iload_2
      68: iload         4
      70: isub
      71: invokestatic  #278                // Method java/lang/Math.abs:(I)I
      74: iconst_1
      75: iadd
      76: aload         5
      78: invokevirtual #281                // Method org/aoc2021/Day23$Room.firstOpenIndex:()I
      81: iadd
      82: imul
      83: istore        6
      85: aload_1
      86: checkcast     #110                // class java/lang/Iterable
      89: astore        8
      91: iconst_0
      92: istore        9
      94: aload         8
      96: astore        10
      98: new           #166                // class java/util/ArrayList
     101: dup
     102: aload         8
     104: bipush        10
     106: invokestatic  #285                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     109: invokespecial #288                // Method java/util/ArrayList."<init>":(I)V
     112: checkcast     #169                // class java/util/Collection
     115: astore        11
     117: iconst_0
     118: istore        12
     120: aload         10
     122: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     127: astore        13
     129: aload         13
     131: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     136: ifeq          219
     139: aload         13
     141: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     146: astore        14
     148: aload         11
     150: aload         14
     152: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     155: astore        15
     157: astore        17
     159: iconst_0
     160: istore        16
     162: aload         15
     164: aload_3
     165: if_acmpne     182
     168: new           #211                // class org/aoc2021/Day23$Space
     171: dup
     172: aconst_null
     173: invokespecial #291                // Method org/aoc2021/Day23$Space."<init>":(Lorg/aoc2021/Day23$Amphipod;)V
     176: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     179: goto          206
     182: aload         15
     184: aload         5
     186: if_acmpne     204
     189: aload         5
     191: aload_3
     192: invokevirtual #247                // Method org/aoc2021/Day23$Space.getOccupant:()Lorg/aoc2021/Day23$Amphipod;
     195: invokevirtual #295                // Method org/aoc2021/Day23$Room.withNewOccupant:(Lorg/aoc2021/Day23$Amphipod;)Lorg/aoc2021/Day23$Room;
     198: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     201: goto          206
     204: aload         15
     206: nop
     207: aload         17
     209: swap
     210: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     215: pop
     216: goto          129
     219: aload         11
     221: checkcast     #135                // class java/util/List
     224: nop
     225: astore        7
     227: iload         6
     229: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     232: aload         7
     234: invokestatic  #301                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     237: invokestatic  #305                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     240: areturn
     241: invokestatic  #250                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     244: areturn

  private final java.util.List<kotlin.Pair<java.lang.Integer, java.util.List<org.aoc2021.Day23$HallwayPosition>>> generateRoomMoves(java.util.List<? extends org.aoc2021.Day23$HallwayPosition>, int, org.aoc2021.Day23$Room);
    Code:
       0: getstatic     #175                // Field winState:Ljava/util/List;
       3: iload_2
       4: iconst_2
       5: isub
       6: iconst_2
       7: idiv
       8: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #184                // class org/aoc2021/Day23$Amphipod
      16: astore        4
      18: aload_3
      19: invokevirtual #187                // Method org/aoc2021/Day23$Room.getOccupants:()Ljava/util/List;
      22: checkcast     #110                // class java/lang/Iterable
      25: astore        5
      27: iconst_0
      28: istore        6
      30: aload         5
      32: instanceof    #169                // class java/util/Collection
      35: ifeq          55
      38: aload         5
      40: checkcast     #169                // class java/util/Collection
      43: invokeinterface #182,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      48: ifeq          55
      51: iconst_1
      52: goto          118
      55: aload         5
      57: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      62: astore        7
      64: aload         7
      66: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      71: ifeq          117
      74: aload         7
      76: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      81: astore        8
      83: aload         8
      85: checkcast     #184                // class org/aoc2021/Day23$Amphipod
      88: astore        9
      90: iconst_0
      91: istore        10
      93: aload         9
      95: ifnull        105
      98: aload         9
     100: aload         4
     102: if_acmpne     109
     105: iconst_1
     106: goto          110
     109: iconst_0
     110: ifne          64
     113: iconst_0
     114: goto          118
     117: iconst_1
     118: ifeq          125
     121: invokestatic  #250                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     124: areturn
     125: aload_3
     126: invokevirtual #321                // Method org/aoc2021/Day23$Room.firstOccupiedIndex:()I
     129: istore        5
     131: aload_3
     132: invokevirtual #187                // Method org/aoc2021/Day23$Room.getOccupants:()Ljava/util/List;
     135: iload         5
     137: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     142: dup
     143: invokestatic  #324                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     146: checkcast     #184                // class org/aoc2021/Day23$Amphipod
     149: astore        6
     151: aload         6
     153: aload         4
     155: if_acmpeq     385
     158: iconst_2
     159: getstatic     #175                // Field winState:Ljava/util/List;
     162: aload         6
     164: invokeinterface #254,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     169: imul
     170: iconst_2
     171: iadd
     172: istore        7
     174: aload_1
     175: iload         7
     177: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     182: dup
     183: ldc_w         #259                // String null cannot be cast to non-null type org.aoc2021.Day23.Room
     186: invokestatic  #265                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
     189: checkcast     #171                // class org/aoc2021/Day23$Room
     192: astore        8
     194: aload_0
     195: aload_1
     196: iload_2
     197: iload         7
     199: invokespecial #269                // Method canMoveToRoom:(Ljava/util/List;II)Z
     202: ifeq          385
     205: iload_2
     206: iload         7
     208: isub
     209: invokestatic  #278                // Method java/lang/Math.abs:(I)I
     212: iconst_2
     213: iadd
     214: iload         5
     216: iadd
     217: aload         8
     219: invokevirtual #281                // Method org/aoc2021/Day23$Room.firstOpenIndex:()I
     222: iadd
     223: istore        9
     225: aload         6
     227: invokevirtual #272                // Method org/aoc2021/Day23$Amphipod.getEnergyPerStep:()I
     230: iload         9
     232: imul
     233: istore        10
     235: aload_1
     236: checkcast     #110                // class java/lang/Iterable
     239: astore        12
     241: iconst_0
     242: istore        13
     244: aload         12
     246: astore        14
     248: new           #166                // class java/util/ArrayList
     251: dup
     252: aload         12
     254: bipush        10
     256: invokestatic  #285                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     259: invokespecial #288                // Method java/util/ArrayList."<init>":(I)V
     262: checkcast     #169                // class java/util/Collection
     265: astore        15
     267: iconst_0
     268: istore        16
     270: aload         14
     272: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     277: astore        17
     279: aload         17
     281: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     286: ifeq          363
     289: aload         17
     291: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     296: astore        18
     298: aload         15
     300: aload         18
     302: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     305: astore        19
     307: astore        22
     309: iconst_0
     310: istore        20
     312: aload         19
     314: aload_3
     315: if_acmpne     328
     318: aload_3
     319: invokevirtual #328                // Method org/aoc2021/Day23$Room.withoutTopOccupant:()Lorg/aoc2021/Day23$Room;
     322: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     325: goto          350
     328: aload         19
     330: aload         8
     332: if_acmpne     348
     335: aload         8
     337: aload         6
     339: invokevirtual #295                // Method org/aoc2021/Day23$Room.withNewOccupant:(Lorg/aoc2021/Day23$Amphipod;)Lorg/aoc2021/Day23$Room;
     342: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     345: goto          350
     348: aload         19
     350: nop
     351: aload         22
     353: swap
     354: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     359: pop
     360: goto          279
     363: aload         15
     365: checkcast     #135                // class java/util/List
     368: nop
     369: astore        11
     371: iload         10
     373: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     376: aload         11
     378: invokestatic  #301                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     381: invokestatic  #305                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     384: areturn
     385: new           #166                // class java/util/ArrayList
     388: dup
     389: invokespecial #167                // Method java/util/ArrayList."<init>":()V
     392: checkcast     #135                // class java/util/List
     395: astore        7
     397: iconst_0
     398: istore        8
     400: aload_1
     401: checkcast     #169                // class java/util/Collection
     404: invokeinterface #331,  1          // InterfaceMethod java/util/Collection.size:()I
     409: istore        9
     411: iload         8
     413: iload         9
     415: if_icmpge     637
     418: aload_1
     419: iload         8
     421: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     426: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     429: astore        10
     431: aload         10
     433: instanceof    #211                // class org/aoc2021/Day23$Space
     436: ifne          442
     439: goto          631
     442: aload_0
     443: aload_1
     444: iload_2
     445: iload         8
     447: invokespecial #334                // Method canMoveToSpace:(Ljava/util/List;II)Z
     450: ifeq          631
     453: aload         6
     455: invokevirtual #272                // Method org/aoc2021/Day23$Amphipod.getEnergyPerStep:()I
     458: iload_2
     459: iload         8
     461: isub
     462: invokestatic  #278                // Method java/lang/Math.abs:(I)I
     465: iconst_1
     466: iadd
     467: aload_3
     468: invokevirtual #321                // Method org/aoc2021/Day23$Room.firstOccupiedIndex:()I
     471: iadd
     472: imul
     473: istore        11
     475: aload_1
     476: checkcast     #110                // class java/lang/Iterable
     479: astore        13
     481: iconst_0
     482: istore        14
     484: aload         13
     486: astore        15
     488: new           #166                // class java/util/ArrayList
     491: dup
     492: aload         13
     494: bipush        10
     496: invokestatic  #285                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     499: invokespecial #288                // Method java/util/ArrayList."<init>":(I)V
     502: checkcast     #169                // class java/util/Collection
     505: astore        16
     507: iconst_0
     508: istore        17
     510: aload         15
     512: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     517: astore        18
     519: aload         18
     521: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     526: ifeq          605
     529: aload         18
     531: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     536: astore        19
     538: aload         16
     540: aload         19
     542: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     545: astore        20
     547: astore        22
     549: iconst_0
     550: istore        21
     552: aload         20
     554: aload_3
     555: if_acmpne     568
     558: aload_3
     559: invokevirtual #328                // Method org/aoc2021/Day23$Room.withoutTopOccupant:()Lorg/aoc2021/Day23$Room;
     562: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     565: goto          592
     568: aload         20
     570: aload         10
     572: if_acmpne     590
     575: new           #211                // class org/aoc2021/Day23$Space
     578: dup
     579: aload         6
     581: invokespecial #291                // Method org/aoc2021/Day23$Space."<init>":(Lorg/aoc2021/Day23$Amphipod;)V
     584: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     587: goto          592
     590: aload         20
     592: nop
     593: aload         22
     595: swap
     596: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     601: pop
     602: goto          519
     605: aload         16
     607: checkcast     #135                // class java/util/List
     610: nop
     611: astore        12
     613: aload         7
     615: iload         11
     617: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     620: aload         12
     622: invokestatic  #301                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     625: invokeinterface #335,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     630: pop
     631: iinc          8, 1
     634: goto          411
     637: aload         7
     639: checkcast     #110                // class java/lang/Iterable
     642: invokestatic  #233                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     645: areturn

  private final boolean canMoveToSpace(java.util.List<? extends org.aoc2021.Day23$HallwayPosition>, int, int);
    Code:
       0: aload_1
       1: iload_3
       2: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: dup
       8: ldc_w         #346                // String null cannot be cast to non-null type org.aoc2021.Day23.Space
      11: invokestatic  #265                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
      14: checkcast     #211                // class org/aoc2021/Day23$Space
      17: astore        4
      19: aload         4
      21: invokevirtual #247                // Method org/aoc2021/Day23$Space.getOccupant:()Lorg/aoc2021/Day23$Amphipod;
      24: ifnull        29
      27: iconst_0
      28: ireturn
      29: aload_0
      30: aload_1
      31: iload_2
      32: iload_3
      33: invokespecial #349                // Method canMoveToPosition:(Ljava/util/List;II)Z
      36: ireturn

  private final boolean canMoveToRoom(java.util.List<? extends org.aoc2021.Day23$HallwayPosition>, int, int);
    Code:
       0: getstatic     #175                // Field winState:Ljava/util/List;
       3: iload_3
       4: iconst_2
       5: isub
       6: iconst_2
       7: idiv
       8: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #184                // class org/aoc2021/Day23$Amphipod
      16: astore        4
      18: aload_1
      19: iload_3
      20: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      25: dup
      26: ldc_w         #259                // String null cannot be cast to non-null type org.aoc2021.Day23.Room
      29: invokestatic  #265                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
      32: checkcast     #171                // class org/aoc2021/Day23$Room
      35: astore        5
      37: aload         5
      39: invokevirtual #187                // Method org/aoc2021/Day23$Room.getOccupants:()Ljava/util/List;
      42: checkcast     #110                // class java/lang/Iterable
      45: astore        6
      47: iconst_0
      48: istore        7
      50: aload         6
      52: instanceof    #169                // class java/util/Collection
      55: ifeq          75
      58: aload         6
      60: checkcast     #169                // class java/util/Collection
      63: invokeinterface #182,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      68: ifeq          75
      71: iconst_1
      72: goto          138
      75: aload         6
      77: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      82: astore        8
      84: aload         8
      86: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      91: ifeq          137
      94: aload         8
      96: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     101: astore        9
     103: aload         9
     105: checkcast     #184                // class org/aoc2021/Day23$Amphipod
     108: astore        10
     110: iconst_0
     111: istore        11
     113: aload         10
     115: ifnull        125
     118: aload         10
     120: aload         4
     122: if_acmpne     129
     125: iconst_1
     126: goto          130
     129: iconst_0
     130: ifne          84
     133: iconst_0
     134: goto          138
     137: iconst_1
     138: ifne          143
     141: iconst_0
     142: ireturn
     143: aload_0
     144: aload_1
     145: iload_2
     146: iload_3
     147: invokespecial #349                // Method canMoveToPosition:(Ljava/util/List;II)Z
     150: ireturn

  private final boolean canMoveToPosition(java.util.List<? extends org.aoc2021.Day23$HallwayPosition>, int, int);
    Code:
       0: iload_2
       1: iload_3
       2: invokestatic  #354                // Method java/lang/Math.min:(II)I
       5: istore        4
       7: iload_2
       8: iload_3
       9: invokestatic  #357                // Method java/lang/Math.max:(II)I
      12: istore        5
      14: iload         4
      16: iconst_1
      17: iadd
      18: iload         5
      20: invokestatic  #363                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      23: checkcast     #110                // class java/lang/Iterable
      26: astore        6
      28: iconst_0
      29: istore        7
      31: aload         6
      33: instanceof    #169                // class java/util/Collection
      36: ifeq          56
      39: aload         6
      41: checkcast     #169                // class java/util/Collection
      44: invokeinterface #182,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      49: ifeq          56
      52: iconst_1
      53: goto          137
      56: aload         6
      58: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        8
      65: aload         8
      67: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          136
      75: aload         8
      77: checkcast     #365                // class kotlin/collections/IntIterator
      80: invokevirtual #368                // Method kotlin/collections/IntIterator.nextInt:()I
      83: istore        9
      85: iload         9
      87: istore        10
      89: iconst_0
      90: istore        11
      92: aload_1
      93: iload         10
      95: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     100: checkcast     #209                // class org/aoc2021/Day23$HallwayPosition
     103: astore        12
     105: aload         12
     107: instanceof    #211                // class org/aoc2021/Day23$Space
     110: ifeq          124
     113: aload         12
     115: checkcast     #211                // class org/aoc2021/Day23$Space
     118: invokevirtual #247                // Method org/aoc2021/Day23$Space.getOccupant:()Lorg/aoc2021/Day23$Amphipod;
     121: ifnonnull     128
     124: iconst_1
     125: goto          129
     128: iconst_0
     129: ifne          65
     132: iconst_0
     133: goto          137
     136: iconst_1
     137: ireturn

  private final java.util.List<org.aoc2021.Day23$HallwayPosition> parseInput(java.util.List<java.lang.String>, boolean);
    Code:
       0: aload_1
       1: iconst_2
       2: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #374                // class java/lang/String
      10: astore        4
      12: getstatic     #378                // Field amphipodChars:Ljava/util/Set;
      15: astore        5
      17: iconst_0
      18: istore        6
      20: aload         4
      22: checkcast     #380                // class java/lang/CharSequence
      25: astore        7
      27: new           #382                // class java/lang/StringBuilder
      30: dup
      31: invokespecial #383                // Method java/lang/StringBuilder."<init>":()V
      34: checkcast     #385                // class java/lang/Appendable
      37: astore        8
      39: iconst_0
      40: istore        9
      42: iconst_0
      43: istore        10
      45: aload         7
      47: invokeinterface #388,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      52: istore        11
      54: iload         10
      56: iload         11
      58: if_icmpge     110
      61: aload         7
      63: iload         10
      65: invokeinterface #392,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      70: istore        12
      72: iload         12
      74: istore        13
      76: iconst_0
      77: istore        14
      79: aload         5
      81: iload         13
      83: invokestatic  #397                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      86: invokeinterface #402,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      91: ifeq          104
      94: aload         8
      96: iload         12
      98: invokeinterface #406,  2          // InterfaceMethod java/lang/Appendable.append:(C)Ljava/lang/Appendable;
     103: pop
     104: iinc          10, 1
     107: goto          54
     110: aload         8
     112: checkcast     #382                // class java/lang/StringBuilder
     115: invokevirtual #410                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     118: invokevirtual #414                // Method java/lang/String.toCharArray:()[C
     121: dup
     122: ldc_w         #416                // String toCharArray(...)
     125: invokestatic  #419                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     128: astore_3
     129: aload_1
     130: iconst_3
     131: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     136: checkcast     #374                // class java/lang/String
     139: astore        5
     141: getstatic     #378                // Field amphipodChars:Ljava/util/Set;
     144: astore        6
     146: iconst_0
     147: istore        7
     149: aload         5
     151: checkcast     #380                // class java/lang/CharSequence
     154: astore        8
     156: new           #382                // class java/lang/StringBuilder
     159: dup
     160: invokespecial #383                // Method java/lang/StringBuilder."<init>":()V
     163: checkcast     #385                // class java/lang/Appendable
     166: astore        9
     168: iconst_0
     169: istore        10
     171: iconst_0
     172: istore        11
     174: aload         8
     176: invokeinterface #388,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     181: istore        12
     183: iload         11
     185: iload         12
     187: if_icmpge     239
     190: aload         8
     192: iload         11
     194: invokeinterface #392,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     199: istore        13
     201: iload         13
     203: istore        14
     205: iconst_0
     206: istore        15
     208: aload         6
     210: iload         14
     212: invokestatic  #397                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     215: invokeinterface #402,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     220: ifeq          233
     223: aload         9
     225: iload         13
     227: invokeinterface #406,  2          // InterfaceMethod java/lang/Appendable.append:(C)Ljava/lang/Appendable;
     232: pop
     233: iinc          11, 1
     236: goto          183
     239: aload         9
     241: checkcast     #382                // class java/lang/StringBuilder
     244: invokevirtual #410                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     247: invokevirtual #414                // Method java/lang/String.toCharArray:()[C
     250: dup
     251: ldc_w         #416                // String toCharArray(...)
     254: invokestatic  #419                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     257: astore        4
     259: aload_3
     260: aload         4
     262: invokestatic  #424                // Method kotlin/collections/ArraysKt.zip:([C[C)Ljava/util/List;
     265: astore        5
     267: iconst_0
     268: istore        6
     270: new           #166                // class java/util/ArrayList
     273: dup
     274: invokespecial #167                // Method java/util/ArrayList."<init>":()V
     277: checkcast     #135                // class java/util/List
     280: astore        7
     282: iconst_0
     283: istore        8
     285: iload         8
     287: bipush        11
     289: if_icmpge     510
     292: getstatic     #427                // Field roomIndices:Ljava/util/Set;
     295: iload         8
     297: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     300: invokeinterface #402,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     305: ifeq          488
     308: aload         5
     310: iload         6
     312: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     317: checkcast     #124                // class kotlin/Pair
     320: astore        9
     322: aload         9
     324: invokevirtual #127                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     327: checkcast     #394                // class java/lang/Character
     330: invokevirtual #431                // Method java/lang/Character.charValue:()C
     333: istore        10
     335: aload         9
     337: invokevirtual #133                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     340: checkcast     #394                // class java/lang/Character
     343: invokevirtual #431                // Method java/lang/Character.charValue:()C
     346: istore        11
     348: iload_2
     349: ifeq          429
     352: new           #171                // class org/aoc2021/Day23$Room
     355: dup
     356: iconst_4
     357: anewarray     #184                // class org/aoc2021/Day23$Amphipod
     360: astore        13
     362: aload         13
     364: iconst_0
     365: aload_0
     366: iload         10
     368: invokespecial #435                // Method charToAmphipod:(C)Lorg/aoc2021/Day23$Amphipod;
     371: aastore
     372: aload         13
     374: iconst_1
     375: getstatic     #438                // Field secondRow:Ljava/util/List;
     378: iload         8
     380: iconst_2
     381: isub
     382: iconst_2
     383: idiv
     384: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     389: aastore
     390: aload         13
     392: iconst_2
     393: getstatic     #441                // Field thirdRow:Ljava/util/List;
     396: iload         8
     398: iconst_2
     399: isub
     400: iconst_2
     401: idiv
     402: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     407: aastore
     408: aload         13
     410: iconst_3
     411: aload_0
     412: iload         11
     414: invokespecial #435                // Method charToAmphipod:(C)Lorg/aoc2021/Day23$Amphipod;
     417: aastore
     418: aload         13
     420: invokestatic  #444                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     423: invokespecial #447                // Method org/aoc2021/Day23$Room."<init>":(Ljava/util/List;)V
     426: goto          467
     429: new           #171                // class org/aoc2021/Day23$Room
     432: dup
     433: iconst_2
     434: anewarray     #184                // class org/aoc2021/Day23$Amphipod
     437: astore        13
     439: aload         13
     441: iconst_0
     442: aload_0
     443: iload         10
     445: invokespecial #435                // Method charToAmphipod:(C)Lorg/aoc2021/Day23$Amphipod;
     448: aastore
     449: aload         13
     451: iconst_1
     452: aload_0
     453: iload         11
     455: invokespecial #435                // Method charToAmphipod:(C)Lorg/aoc2021/Day23$Amphipod;
     458: aastore
     459: aload         13
     461: invokestatic  #444                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     464: invokespecial #447                // Method org/aoc2021/Day23$Room."<init>":(Ljava/util/List;)V
     467: astore        12
     469: aload         7
     471: aload         12
     473: invokeinterface #335,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     478: pop
     479: iload         6
     481: iinc          6, 1
     484: pop
     485: goto          504
     488: aload         7
     490: new           #211                // class org/aoc2021/Day23$Space
     493: dup
     494: aconst_null
     495: invokespecial #291                // Method org/aoc2021/Day23$Space."<init>":(Lorg/aoc2021/Day23$Amphipod;)V
     498: invokeinterface #335,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     503: pop
     504: iinc          8, 1
     507: goto          285
     510: aload         7
     512: checkcast     #110                // class java/lang/Iterable
     515: invokestatic  #233                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     518: areturn

  private final org.aoc2021.Day23$Amphipod charToAmphipod(char);
    Code:
       0: iload_1
       1: tableswitch   { // 65 to 68
                    65: 32
                    66: 38
                    67: 44
                    68: 50
               default: 56
          }
      32: getstatic     #473                // Field org/aoc2021/Day23$Amphipod.AMBER:Lorg/aoc2021/Day23$Amphipod;
      35: goto          68
      38: getstatic     #476                // Field org/aoc2021/Day23$Amphipod.BRONZE:Lorg/aoc2021/Day23$Amphipod;
      41: goto          68
      44: getstatic     #479                // Field org/aoc2021/Day23$Amphipod.COPPER:Lorg/aoc2021/Day23$Amphipod;
      47: goto          68
      50: getstatic     #482                // Field org/aoc2021/Day23$Amphipod.DESERT:Lorg/aoc2021/Day23$Amphipod;
      53: goto          68
      56: new           #137                // class java/lang/IllegalArgumentException
      59: dup
      60: iload_1
      61: invokestatic  #485                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
      64: invokespecial #142                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      67: athrow
      68: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc_w         #492                // String args
       4: invokestatic  #495                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: ldc_w         #497                // String input23.txt
      10: iconst_0
      11: anewarray     #374                // class java/lang/String
      14: invokestatic  #503                // InterfaceMethod java/nio/file/Path.of:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
      17: getstatic     #509                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      20: invokestatic  #515                // Method java/nio/file/Files.readAllLines:(Ljava/nio/file/Path;Ljava/nio/charset/Charset;)Ljava/util/List;
      23: astore_1
      24: getstatic     #214                // Field INSTANCE:Lorg/aoc2021/Day23;
      27: aload_1
      28: invokestatic  #324                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      31: aload_1
      32: iconst_0
      33: invokespecial #517                // Method solve:(Ljava/util/List;Z)I
      36: istore_2
      37: getstatic     #523                // Field java/lang/System.out:Ljava/io/PrintStream;
      40: iload_2
      41: invokevirtual #528                // Method java/io/PrintStream.println:(I)V
      44: getstatic     #214                // Field INSTANCE:Lorg/aoc2021/Day23;
      47: aload_1
      48: iconst_1
      49: invokespecial #517                // Method solve:(Ljava/util/List;Z)I
      52: istore_3
      53: getstatic     #523                // Field java/lang/System.out:Ljava/io/PrintStream;
      56: iload_3
      57: invokevirtual #528                // Method java/io/PrintStream.println:(I)V
      60: return

  private static final int solve$lambda$0(org.aoc2021.Day23$State, org.aoc2021.Day23$State);
    Code:
       0: aload_0
       1: invokevirtual #79                 // Method org/aoc2021/Day23$State.getDistance:()I
       4: aload_1
       5: invokevirtual #79                 // Method org/aoc2021/Day23$State.getDistance:()I
       8: invokestatic  #533                // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      11: ireturn

  private static final int solve$lambda$1(kotlin.jvm.functions.Function2, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokeinterface #539,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
       8: checkcast     #129                // class java/lang/Number
      11: invokevirtual #130                // Method java/lang/Number.intValue:()I
      14: ireturn

  static {};
    Code:
       0: new           #2                  // class org/aoc2021/Day23
       3: dup
       4: invokespecial #544                // Method "<init>":()V
       7: putstatic     #214                // Field INSTANCE:Lorg/aoc2021/Day23;
      10: iconst_4
      11: anewarray     #394                // class java/lang/Character
      14: astore_0
      15: aload_0
      16: iconst_0
      17: bipush        65
      19: invokestatic  #397                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      22: aastore
      23: aload_0
      24: iconst_1
      25: bipush        66
      27: invokestatic  #397                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      30: aastore
      31: aload_0
      32: iconst_2
      33: bipush        67
      35: invokestatic  #397                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      38: aastore
      39: aload_0
      40: iconst_3
      41: bipush        68
      43: invokestatic  #397                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      46: aastore
      47: aload_0
      48: invokestatic  #550                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      51: putstatic     #378                // Field amphipodChars:Ljava/util/Set;
      54: iconst_4
      55: anewarray     #89                 // class java/lang/Integer
      58: astore_0
      59: aload_0
      60: iconst_0
      61: iconst_2
      62: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: aastore
      66: aload_0
      67: iconst_1
      68: iconst_4
      69: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: aastore
      73: aload_0
      74: iconst_2
      75: bipush        6
      77: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aastore
      81: aload_0
      82: iconst_3
      83: bipush        8
      85: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: aastore
      89: aload_0
      90: invokestatic  #550                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      93: putstatic     #427                // Field roomIndices:Ljava/util/Set;
      96: iconst_4
      97: anewarray     #184                // class org/aoc2021/Day23$Amphipod
     100: astore_0
     101: aload_0
     102: iconst_0
     103: getstatic     #482                // Field org/aoc2021/Day23$Amphipod.DESERT:Lorg/aoc2021/Day23$Amphipod;
     106: aastore
     107: aload_0
     108: iconst_1
     109: getstatic     #479                // Field org/aoc2021/Day23$Amphipod.COPPER:Lorg/aoc2021/Day23$Amphipod;
     112: aastore
     113: aload_0
     114: iconst_2
     115: getstatic     #476                // Field org/aoc2021/Day23$Amphipod.BRONZE:Lorg/aoc2021/Day23$Amphipod;
     118: aastore
     119: aload_0
     120: iconst_3
     121: getstatic     #473                // Field org/aoc2021/Day23$Amphipod.AMBER:Lorg/aoc2021/Day23$Amphipod;
     124: aastore
     125: aload_0
     126: invokestatic  #444                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     129: putstatic     #438                // Field secondRow:Ljava/util/List;
     132: iconst_4
     133: anewarray     #184                // class org/aoc2021/Day23$Amphipod
     136: astore_0
     137: aload_0
     138: iconst_0
     139: getstatic     #482                // Field org/aoc2021/Day23$Amphipod.DESERT:Lorg/aoc2021/Day23$Amphipod;
     142: aastore
     143: aload_0
     144: iconst_1
     145: getstatic     #476                // Field org/aoc2021/Day23$Amphipod.BRONZE:Lorg/aoc2021/Day23$Amphipod;
     148: aastore
     149: aload_0
     150: iconst_2
     151: getstatic     #473                // Field org/aoc2021/Day23$Amphipod.AMBER:Lorg/aoc2021/Day23$Amphipod;
     154: aastore
     155: aload_0
     156: iconst_3
     157: getstatic     #479                // Field org/aoc2021/Day23$Amphipod.COPPER:Lorg/aoc2021/Day23$Amphipod;
     160: aastore
     161: aload_0
     162: invokestatic  #444                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     165: putstatic     #441                // Field thirdRow:Ljava/util/List;
     168: invokestatic  #554                // Method org/aoc2021/Day23$Amphipod.values:()[Lorg/aoc2021/Day23$Amphipod;
     171: invokestatic  #556                // Method kotlin/collections/ArraysKt.toList:([Ljava/lang/Object;)Ljava/util/List;
     174: putstatic     #175                // Field winState:Ljava/util/List;
     177: return
}

Compiled from "Day23.kt"
public final class org.aoc2021.Day23$Space implements org.aoc2021.Day23$HallwayPosition {
  private final org.aoc2021.Day23$Amphipod occupant;

  public org.aoc2021.Day23$Space(org.aoc2021.Day23$Amphipod);
    Code:
       0: aload_0
       1: invokespecial #12                 // Method java/lang/Object."<init>":()V
       4: aload_0
       5: aload_1
       6: putfield      #16                 // Field occupant:Lorg/aoc2021/Day23$Amphipod;
       9: return

  public final org.aoc2021.Day23$Amphipod getOccupant();
    Code:
       0: aload_0
       1: getfield      #16                 // Field occupant:Lorg/aoc2021/Day23$Amphipod;
       4: areturn

  public final org.aoc2021.Day23$Amphipod component1();
    Code:
       0: aload_0
       1: getfield      #16                 // Field occupant:Lorg/aoc2021/Day23$Amphipod;
       4: areturn

  public final org.aoc2021.Day23$Space copy(org.aoc2021.Day23$Amphipod);
    Code:
       0: new           #2                  // class org/aoc2021/Day23$Space
       3: dup
       4: aload_1
       5: invokespecial #26                 // Method "<init>":(Lorg/aoc2021/Day23$Amphipod;)V
       8: areturn

  public static org.aoc2021.Day23$Space copy$default(org.aoc2021.Day23$Space, org.aoc2021.Day23$Amphipod, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #16                 // Field occupant:Lorg/aoc2021/Day23$Amphipod;
      10: astore_1
      11: aload_0
      12: aload_1
      13: invokevirtual #30                 // Method copy:(Lorg/aoc2021/Day23$Amphipod;)Lorg/aoc2021/Day23$Space;
      16: areturn

  public java.lang.String toString();
    Code:
       0: new           #34                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #37                 // String Space(occupant=
       9: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #16                 // Field occupant:Lorg/aoc2021/Day23$Amphipod;
      16: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: bipush        41
      21: invokevirtual #47                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      24: invokevirtual #49                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      27: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #16                 // Field occupant:Lorg/aoc2021/Day23$Amphipod;
       4: ifnonnull     11
       7: iconst_0
       8: goto          18
      11: aload_0
      12: getfield      #16                 // Field occupant:Lorg/aoc2021/Day23$Amphipod;
      15: invokevirtual #55                 // Method org/aoc2021/Day23$Amphipod.hashCode:()I
      18: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class org/aoc2021/Day23$Space
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class org/aoc2021/Day23$Space
      20: astore_2
      21: aload_0
      22: getfield      #16                 // Field occupant:Lorg/aoc2021/Day23$Amphipod;
      25: aload_2
      26: getfield      #16                 // Field occupant:Lorg/aoc2021/Day23$Amphipod;
      29: if_acmpeq     34
      32: iconst_0
      33: ireturn
      34: iconst_1
      35: ireturn
}

Compiled from "Day23.kt"
public final class org.aoc2021.Day23$State {
  private final int distance;

  private final java.util.List<org.aoc2021.Day23$HallwayPosition> hallway;

  public org.aoc2021.Day23$State(int, java.util.List<? extends org.aoc2021.Day23$HallwayPosition>);
    Code:
       0: aload_2
       1: ldc           #10                 // String hallway
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: iload_1
      12: putfield      #23                 // Field distance:I
      15: aload_0
      16: aload_2
      17: putfield      #26                 // Field hallway:Ljava/util/List;
      20: return

  public final int getDistance();
    Code:
       0: aload_0
       1: getfield      #23                 // Field distance:I
       4: ireturn

  public final java.util.List<org.aoc2021.Day23$HallwayPosition> getHallway();
    Code:
       0: aload_0
       1: getfield      #26                 // Field hallway:Ljava/util/List;
       4: areturn

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

  public final java.util.List<org.aoc2021.Day23$HallwayPosition> component2();
    Code:
       0: aload_0
       1: getfield      #26                 // Field hallway:Ljava/util/List;
       4: areturn

  public final org.aoc2021.Day23$State copy(int, java.util.List<? extends org.aoc2021.Day23$HallwayPosition>);
    Code:
       0: aload_2
       1: ldc           #10                 // String hallway
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class org/aoc2021/Day23$State
       9: dup
      10: iload_1
      11: aload_2
      12: invokespecial #40                 // Method "<init>":(ILjava/util/List;)V
      15: areturn

  public static org.aoc2021.Day23$State copy$default(org.aoc2021.Day23$State, int, java.util.List, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #23                 // Field distance:I
      10: istore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #26                 // Field hallway:Ljava/util/List;
      21: astore_2
      22: aload_0
      23: iload_1
      24: aload_2
      25: invokevirtual #44                 // Method copy:(ILjava/util/List;)Lorg/aoc2021/Day23$State;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #48                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #49                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #51                 // String State(distance=
       9: invokevirtual #55                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #23                 // Field distance:I
      16: invokevirtual #58                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #60                 // String , hallway=
      21: invokevirtual #55                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #26                 // Field hallway:Ljava/util/List;
      28: invokevirtual #63                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #66                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #68                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #23                 // Field distance:I
       4: invokestatic  #74                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #26                 // Field hallway:Ljava/util/List;
      16: invokevirtual #76                 // Method java/lang/Object.hashCode:()I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class org/aoc2021/Day23$State
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class org/aoc2021/Day23$State
      20: astore_2
      21: aload_0
      22: getfield      #23                 // Field distance:I
      25: aload_2
      26: getfield      #23                 // Field distance:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #26                 // Field hallway:Ljava/util/List;
      38: aload_2
      39: getfield      #26                 // Field hallway:Ljava/util/List;
      42: invokestatic  #84                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      45: ifne          50
      48: iconst_0
      49: ireturn
      50: iconst_1
      51: ireturn
}