package day5

import java.io.File
import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.math.sign

data class Line(val x1: Int, val y1: Int, val x2: Int, val y2: Int)

fun main() {
    val input = File("src/day5/input.txt").readLines()
    val regex = Regex("([0-9]*),([0-9]*) -> ([0-9]*),([0-9]*)")
    val lines = input.map { regex.matchEntire(it)!!.destructured.toList().map { it.toInt() } }
        .map { Line(it[0], it[1], it[2], it[3]) }

    val rectilinear = lines.filter { it.x1 == it.x2 || it.y1 == it.y2 }
    println(solve(rectilinear))

    println(solve(lines))
}

fun solve(lines: List<Line>): Int {
    val points = mutableMapOf<Pair<Int, Int>, Int>()
    lines.forEach { line ->
        val dx = (line.x2 - line.x1).sign
        val dy = (line.y2 - line.y1).sign
        val length = max((line.x1 - line.x2).absoluteValue, (line.y1 - line.y2).absoluteValue)
        (0..length).map { i -> Pair(line.x1 + i * dx, line.y1 + i * dy) }.forEach { point ->
            points[point] = (points[point] ?: 0).plus(1)
        }
    }
    return points.count { it.value > 1 }
}

Compiled from "result.kt"
public final class day5.ResultKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/day5/input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: new           #22                 // class kotlin/text/Regex
      19: dup
      20: ldc           #24                 // String ([0-9]*),([0-9]*) -> ([0-9]*),([0-9]*)
      22: invokespecial #25                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      25: astore_1
      26: aload_0
      27: checkcast     #27                 // class java/lang/Iterable
      30: astore_3
      31: iconst_0
      32: istore        4
      34: aload_3
      35: astore        5
      37: new           #29                 // class java/util/ArrayList
      40: dup
      41: aload_3
      42: bipush        10
      44: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #40                 // class java/util/Collection
      53: astore        6
      55: iconst_0
      56: istore        7
      58: aload         5
      60: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      65: astore        8
      67: aload         8
      69: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      74: ifeq          237
      77: aload         8
      79: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      84: astore        9
      86: aload         6
      88: aload         9
      90: checkcast     #56                 // class java/lang/String
      93: astore        10
      95: astore        22
      97: iconst_0
      98: istore        11
     100: aload_1
     101: aload         10
     103: checkcast     #58                 // class java/lang/CharSequence
     106: invokevirtual #62                 // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
     109: dup
     110: invokestatic  #68                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     113: invokeinterface #74,  1           // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     118: invokevirtual #80                 // Method kotlin/text/MatchResult$Destructured.toList:()Ljava/util/List;
     121: checkcast     #27                 // class java/lang/Iterable
     124: astore        12
     126: iconst_0
     127: istore        13
     129: aload         12
     131: astore        14
     133: new           #29                 // class java/util/ArrayList
     136: dup
     137: aload         12
     139: bipush        10
     141: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     144: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     147: checkcast     #40                 // class java/util/Collection
     150: astore        15
     152: iconst_0
     153: istore        16
     155: aload         14
     157: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     162: astore        17
     164: aload         17
     166: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     171: ifeq          218
     174: aload         17
     176: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     181: astore        18
     183: aload         15
     185: aload         18
     187: checkcast     #56                 // class java/lang/String
     190: astore        19
     192: astore        20
     194: iconst_0
     195: istore        21
     197: aload         19
     199: invokestatic  #86                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     202: nop
     203: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     206: aload         20
     208: swap
     209: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     214: pop
     215: goto          164
     218: aload         15
     220: checkcast     #96                 // class java/util/List
     223: nop
     224: nop
     225: aload         22
     227: swap
     228: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     233: pop
     234: goto          67
     237: aload         6
     239: checkcast     #96                 // class java/util/List
     242: nop
     243: checkcast     #27                 // class java/lang/Iterable
     246: astore_3
     247: nop
     248: iconst_0
     249: istore        4
     251: aload_3
     252: astore        5
     254: new           #29                 // class java/util/ArrayList
     257: dup
     258: aload_3
     259: bipush        10
     261: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     264: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     267: checkcast     #40                 // class java/util/Collection
     270: astore        6
     272: iconst_0
     273: istore        7
     275: aload         5
     277: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     282: astore        8
     284: aload         8
     286: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     291: ifeq          392
     294: aload         8
     296: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     301: astore        9
     303: aload         6
     305: aload         9
     307: checkcast     #96                 // class java/util/List
     310: astore        10
     312: astore        22
     314: iconst_0
     315: istore        11
     317: new           #98                 // class day5/Line
     320: dup
     321: aload         10
     323: iconst_0
     324: invokeinterface #102,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     329: checkcast     #104                // class java/lang/Number
     332: invokevirtual #108                // Method java/lang/Number.intValue:()I
     335: aload         10
     337: iconst_1
     338: invokeinterface #102,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     343: checkcast     #104                // class java/lang/Number
     346: invokevirtual #108                // Method java/lang/Number.intValue:()I
     349: aload         10
     351: iconst_2
     352: invokeinterface #102,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     357: checkcast     #104                // class java/lang/Number
     360: invokevirtual #108                // Method java/lang/Number.intValue:()I
     363: aload         10
     365: iconst_3
     366: invokeinterface #102,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     371: checkcast     #104                // class java/lang/Number
     374: invokevirtual #108                // Method java/lang/Number.intValue:()I
     377: invokespecial #111                // Method day5/Line."<init>":(IIII)V
     380: aload         22
     382: swap
     383: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     388: pop
     389: goto          284
     392: aload         6
     394: checkcast     #96                 // class java/util/List
     397: nop
     398: astore_2
     399: aload_2
     400: checkcast     #27                 // class java/lang/Iterable
     403: astore        4
     405: iconst_0
     406: istore        5
     408: aload         4
     410: astore        6
     412: new           #29                 // class java/util/ArrayList
     415: dup
     416: invokespecial #113                // Method java/util/ArrayList."<init>":()V
     419: checkcast     #40                 // class java/util/Collection
     422: astore        7
     424: iconst_0
     425: istore        8
     427: aload         6
     429: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     434: astore        9
     436: aload         9
     438: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     443: ifeq          512
     446: aload         9
     448: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     453: astore        10
     455: aload         10
     457: checkcast     #98                 // class day5/Line
     460: astore        11
     462: iconst_0
     463: istore        12
     465: aload         11
     467: invokevirtual #116                // Method day5/Line.getX1:()I
     470: aload         11
     472: invokevirtual #119                // Method day5/Line.getX2:()I
     475: if_icmpeq     491
     478: aload         11
     480: invokevirtual #122                // Method day5/Line.getY1:()I
     483: aload         11
     485: invokevirtual #125                // Method day5/Line.getY2:()I
     488: if_icmpne     495
     491: iconst_1
     492: goto          496
     495: iconst_0
     496: ifeq          436
     499: aload         7
     501: aload         10
     503: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     508: pop
     509: goto          436
     512: aload         7
     514: checkcast     #96                 // class java/util/List
     517: nop
     518: astore_3
     519: aload_3
     520: invokestatic  #129                // Method solve:(Ljava/util/List;)I
     523: istore        4
     525: getstatic     #135                // Field java/lang/System.out:Ljava/io/PrintStream;
     528: iload         4
     530: invokevirtual #140                // Method java/io/PrintStream.println:(I)V
     533: aload_2
     534: invokestatic  #129                // Method solve:(Ljava/util/List;)I
     537: istore        4
     539: getstatic     #135                // Field java/lang/System.out:Ljava/io/PrintStream;
     542: iload         4
     544: invokevirtual #140                // Method java/io/PrintStream.println:(I)V
     547: return

  public static final int solve(java.util.List<day5.Line>);
    Code:
       0: aload_0
       1: ldc           #171                // String lines
       3: invokestatic  #175                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #177                // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #178                // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #180                // class java/util/Map
      16: astore_1
      17: aload_0
      18: checkcast     #27                 // class java/lang/Iterable
      21: astore_2
      22: iconst_0
      23: istore_3
      24: aload_2
      25: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      30: astore        4
      32: aload         4
      34: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          367
      42: aload         4
      44: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        5
      51: aload         5
      53: checkcast     #98                 // class day5/Line
      56: astore        6
      58: iconst_0
      59: istore        7
      61: aload         6
      63: invokevirtual #119                // Method day5/Line.getX2:()I
      66: aload         6
      68: invokevirtual #116                // Method day5/Line.getX1:()I
      71: isub
      72: invokestatic  #186                // Method kotlin/math/MathKt.getSign:(I)I
      75: istore        8
      77: aload         6
      79: invokevirtual #125                // Method day5/Line.getY2:()I
      82: aload         6
      84: invokevirtual #122                // Method day5/Line.getY1:()I
      87: isub
      88: invokestatic  #186                // Method kotlin/math/MathKt.getSign:(I)I
      91: istore        9
      93: nop
      94: aload         6
      96: invokevirtual #116                // Method day5/Line.getX1:()I
      99: aload         6
     101: invokevirtual #119                // Method day5/Line.getX2:()I
     104: isub
     105: invokestatic  #191                // Method java/lang/Math.abs:(I)I
     108: aload         6
     110: invokevirtual #122                // Method day5/Line.getY1:()I
     113: aload         6
     115: invokevirtual #125                // Method day5/Line.getY2:()I
     118: isub
     119: invokestatic  #191                // Method java/lang/Math.abs:(I)I
     122: invokestatic  #195                // Method java/lang/Math.max:(II)I
     125: istore        10
     127: new           #197                // class kotlin/ranges/IntRange
     130: dup
     131: iconst_0
     132: iload         10
     134: invokespecial #200                // Method kotlin/ranges/IntRange."<init>":(II)V
     137: checkcast     #27                 // class java/lang/Iterable
     140: astore        11
     142: iconst_0
     143: istore        12
     145: aload         11
     147: astore        13
     149: new           #29                 // class java/util/ArrayList
     152: dup
     153: aload         11
     155: bipush        10
     157: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     160: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     163: checkcast     #40                 // class java/util/Collection
     166: astore        14
     168: iconst_0
     169: istore        15
     171: aload         13
     173: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     178: astore        16
     180: aload         16
     182: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     187: ifeq          258
     190: aload         16
     192: checkcast     #202                // class kotlin/collections/IntIterator
     195: invokevirtual #205                // Method kotlin/collections/IntIterator.nextInt:()I
     198: istore        17
     200: aload         14
     202: iload         17
     204: istore        18
     206: astore        19
     208: iconst_0
     209: istore        20
     211: new           #207                // class kotlin/Pair
     214: dup
     215: aload         6
     217: invokevirtual #116                // Method day5/Line.getX1:()I
     220: iload         18
     222: iload         8
     224: imul
     225: iadd
     226: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     229: aload         6
     231: invokevirtual #122                // Method day5/Line.getY1:()I
     234: iload         18
     236: iload         9
     238: imul
     239: iadd
     240: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     243: invokespecial #210                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     246: aload         19
     248: swap
     249: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     254: pop
     255: goto          180
     258: aload         14
     260: checkcast     #96                 // class java/util/List
     263: nop
     264: checkcast     #27                 // class java/lang/Iterable
     267: astore        11
     269: nop
     270: iconst_0
     271: istore        12
     273: aload         11
     275: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     280: astore        13
     282: aload         13
     284: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     289: ifeq          361
     292: aload         13
     294: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     299: astore        14
     301: aload         14
     303: checkcast     #207                // class kotlin/Pair
     306: astore        15
     308: iconst_0
     309: istore        16
     311: aload_1
     312: astore        17
     314: aload_1
     315: aload         15
     317: invokeinterface #213,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     322: checkcast     #82                 // class java/lang/Integer
     325: dup
     326: ifnull        335
     329: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     332: goto          337
     335: pop
     336: iconst_0
     337: iconst_1
     338: iadd
     339: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     342: astore        18
     344: aload         17
     346: aload         15
     348: aload         18
     350: invokeinterface #218,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     355: pop
     356: nop
     357: nop
     358: goto          282
     361: nop
     362: nop
     363: nop
     364: goto          32
     367: nop
     368: aload_1
     369: astore_2
     370: iconst_0
     371: istore_3
     372: aload_2
     373: invokeinterface #221,  1          // InterfaceMethod java/util/Map.isEmpty:()Z
     378: ifeq          385
     381: iconst_0
     382: goto          463
     385: iconst_0
     386: istore        4
     388: aload_2
     389: invokeinterface #225,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     394: invokeinterface #228,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     399: astore        5
     401: aload         5
     403: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     408: ifeq          461
     411: aload         5
     413: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     418: checkcast     #230                // class java/util/Map$Entry
     421: astore        6
     423: aload         6
     425: astore        7
     427: iconst_0
     428: istore        8
     430: aload         7
     432: invokeinterface #233,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     437: checkcast     #104                // class java/lang/Number
     440: invokevirtual #108                // Method java/lang/Number.intValue:()I
     443: iconst_1
     444: if_icmple     451
     447: iconst_1
     448: goto          452
     451: iconst_0
     452: ifeq          401
     455: iinc          4, 1
     458: goto          401
     461: iload         4
     463: ireturn

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


package day23

import java.io.File
import java.util.*
import kotlin.math.abs

fun main() {
    println(solve("src/day23/input.txt"))
    println(solve("src/day23/input-part2.txt"))
}

enum class Amphipod(val stepEnergy: Int) { A(1), B(10), C(100), D(1000) }

data class Room(val natives: Amphipod, val size: Int, val entry: Int, val inhabitants: List<Amphipod>) {
    fun allHome() = full() && allNatives()
    fun full() = inhabitants.size == size
    fun allNatives() = inhabitants.all { it == natives }
    fun exit(): Pair<Amphipod, Room>? {
        if (allNatives()) return null
        if (inhabitants.isEmpty()) return null
        return Pair(inhabitants.first(), copy(inhabitants = inhabitants.subList(1, inhabitants.size)))
    }
    fun entry(a: Amphipod?): Room? {
        if (a != natives) return null
        if (!allNatives()) return null
        return copy(inhabitants = listOf(a) + inhabitants)
    }
}

data class Burrow(val hallway: List<Amphipod?>, val rooms: List<Room>, val energy: Int = 0) {
    fun allHome() = rooms.all { it.allHome() }
    fun hallwayClear(from: Int, to: Int) = (if (from < to) (from+1..to) else (to until from)).all { hallway[it] == null }
    fun entries() = rooms.map { it.entry }
    fun hallwayStops() = hallway.indices.filterNot { it in entries() }
    fun moves(): List<Burrow> {
        val roomExits = rooms.withIndex().map { (roomIndex, room) ->
            val exit = room.exit()
            if (exit == null) {
                emptyList()
            } else {
                hallwayStops().filter { hallwayClear(room.entry, it) }.map { to ->
                    val newHallway = hallway.mapIndexed { index, amphipod -> if (index == to) exit.first else amphipod }
                    val newRooms = rooms.mapIndexed { index, room ->
                        if (index == roomIndex) exit.second else room
                    }
                    val steps = 1 + abs(to - room.entry) + (room.size - room.inhabitants.size)
                    val energyUse = steps * exit.first.stepEnergy
                    Burrow(newHallway, newRooms, energy + energyUse)
                }
            }
        }.flatten()
        val roomEntries = hallway.mapIndexed { from, amphipod ->
            rooms.mapIndexedNotNull { roomIndex, room ->
                val newRoom = room.entry(amphipod)
                if (newRoom != null && hallwayClear(from, room.entry)) {
                    val newHallway = hallway.mapIndexed { index, amphipod -> if (index == from) null else amphipod }
                    val newRooms = rooms.mapIndexed { index, room -> if (index == roomIndex) newRoom else room }
                    val steps = abs(from - room.entry) + (room.size - room.inhabitants.size)
                    val energyUse = steps * amphipod!!.stepEnergy
                    Burrow(newHallway, newRooms, energy + energyUse)
                } else {
                    null
                }
            }
        }.flatten()
        return roomEntries + roomExits
    }

    fun print() {
        println("Energy: $energy")
        println(hallway.map { amphipod -> amphipod?.name ?: "." }.joinToString("") { it })
        (0 until rooms[0].size).forEach { row ->
            println(hallway.indices.map { index -> rooms.firstOrNull { room -> room.entry == index } }
                .map { room -> if (room == null) " " else (row + room.inhabitants.size - room.size).let { if (it >= 0) room.inhabitants[it].name else "." } }
                .joinToString("") { it })
        }
    }
}

fun solve(filename: String): Int? {
    val queue = PriorityQueue<List<Burrow>>(Comparator.comparingInt { it.last().energy })
    queue.add(listOf(parse(filename)))
    val visited = mutableMapOf<Pair<List<Amphipod?>, List<Room>>, Int>()
    while (queue.isNotEmpty()) {
        val burrows = queue.poll()
        val burrow = burrows.last()
        val signature = Pair(burrow.hallway, burrow.rooms)
        val previousBestEnergy = visited[signature]
        if ((previousBestEnergy != null) && (previousBestEnergy <= burrow.energy)) {
            continue
        }
        visited[signature] = burrow.energy
        if (burrow.allHome()) {
            burrows.forEach { it.print() }
            return burrow.energy
        }
        queue.addAll(burrow.moves().map { burrows + it })
    }
    return null
}

fun parse(filename: String): Burrow {
    val lines = File(filename).readLines()
    val hallway = lines[1].drop(1).dropLast(1).map { if (it == '.') null else Amphipod.valueOf(it.toString()) }
    val roomLines = lines.drop(2).dropLast(1)
    val rooms = (0..3).map { room ->
        val natives = Amphipod.values()[room]
        val inhabitants = roomLines.mapNotNull { if (it[3 + (room * 2)] == '.') null else Amphipod.valueOf(it[3 + (room * 2)].toString()) }
        Room(natives, roomLines.size, 2 + (room * 2), inhabitants)
    }
    return Burrow(hallway, rooms)
}

Compiled from "result.kt"
public final class day23.ResultKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/day23/input.txt
       2: invokestatic  #12                 // Method solve:(Ljava/lang/String;)Ljava/lang/Integer;
       5: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
       8: swap
       9: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      12: ldc           #26                 // String src/day23/input-part2.txt
      14: invokestatic  #12                 // Method solve:(Ljava/lang/String;)Ljava/lang/Integer;
      17: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
      20: swap
      21: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      24: return

  public static final java.lang.Integer solve(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #30                 // String filename
       3: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #38                 // class java/util/PriorityQueue
       9: dup
      10: invokedynamic #58,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      15: invokedynamic #69,  0             // InvokeDynamic #1:applyAsInt:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/ToIntFunction;
      20: invokestatic  #75                 // InterfaceMethod java/util/Comparator.comparingInt:(Ljava/util/function/ToIntFunction;)Ljava/util/Comparator;
      23: invokespecial #79                 // Method java/util/PriorityQueue."<init>":(Ljava/util/Comparator;)V
      26: astore_1
      27: aload_1
      28: aload_0
      29: invokestatic  #83                 // Method parse:(Ljava/lang/String;)Lday23/Burrow;
      32: invokestatic  #89                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      35: invokevirtual #93                 // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
      38: pop
      39: new           #95                 // class java/util/LinkedHashMap
      42: dup
      43: invokespecial #97                 // Method java/util/LinkedHashMap."<init>":()V
      46: checkcast     #99                 // class java/util/Map
      49: astore_2
      50: aload_1
      51: checkcast     #101                // class java/util/Collection
      54: invokeinterface #105,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      59: ifne          66
      62: iconst_1
      63: goto          67
      66: iconst_0
      67: ifeq          359
      70: aload_1
      71: invokevirtual #109                // Method java/util/PriorityQueue.poll:()Ljava/lang/Object;
      74: checkcast     #111                // class java/util/List
      77: astore_3
      78: aload_3
      79: invokestatic  #114                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      82: aload_3
      83: invokestatic  #118                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      86: checkcast     #120                // class day23/Burrow
      89: astore        4
      91: new           #122                // class kotlin/Pair
      94: dup
      95: aload         4
      97: invokevirtual #126                // Method day23/Burrow.getHallway:()Ljava/util/List;
     100: aload         4
     102: invokevirtual #129                // Method day23/Burrow.getRooms:()Ljava/util/List;
     105: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     108: astore        5
     110: aload_2
     111: aload         5
     113: invokeinterface #135,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     118: checkcast     #137                // class java/lang/Integer
     121: astore        6
     123: aload         6
     125: ifnull        144
     128: aload         6
     130: invokevirtual #141                // Method java/lang/Integer.intValue:()I
     133: aload         4
     135: invokevirtual #144                // Method day23/Burrow.getEnergy:()I
     138: if_icmpgt     144
     141: goto          50
     144: aload_2
     145: aload         5
     147: aload         4
     149: invokevirtual #144                // Method day23/Burrow.getEnergy:()I
     152: invokestatic  #148                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     155: invokeinterface #152,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     160: pop
     161: aload         4
     163: invokevirtual #155                // Method day23/Burrow.allHome:()Z
     166: ifeq          235
     169: aload_3
     170: checkcast     #157                // class java/lang/Iterable
     173: astore        7
     175: iconst_0
     176: istore        8
     178: aload         7
     180: invokeinterface #161,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     185: astore        9
     187: aload         9
     189: invokeinterface #166,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     194: ifeq          225
     197: aload         9
     199: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     204: astore        10
     206: aload         10
     208: checkcast     #120                // class day23/Burrow
     211: astore        11
     213: iconst_0
     214: istore        12
     216: aload         11
     218: invokevirtual #172                // Method day23/Burrow.print:()V
     221: nop
     222: goto          187
     225: nop
     226: aload         4
     228: invokevirtual #144                // Method day23/Burrow.getEnergy:()I
     231: invokestatic  #148                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     234: areturn
     235: aload_1
     236: aload         4
     238: invokevirtual #175                // Method day23/Burrow.moves:()Ljava/util/List;
     241: checkcast     #157                // class java/lang/Iterable
     244: astore        7
     246: astore        16
     248: iconst_0
     249: istore        8
     251: aload         7
     253: astore        9
     255: new           #177                // class java/util/ArrayList
     258: dup
     259: aload         7
     261: bipush        10
     263: invokestatic  #181                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     266: invokespecial #184                // Method java/util/ArrayList."<init>":(I)V
     269: checkcast     #101                // class java/util/Collection
     272: astore        10
     274: iconst_0
     275: istore        11
     277: aload         9
     279: invokeinterface #161,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     284: astore        12
     286: aload         12
     288: invokeinterface #166,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     293: ifeq          340
     296: aload         12
     298: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     303: astore        13
     305: aload         10
     307: aload         13
     309: checkcast     #120                // class day23/Burrow
     312: astore        14
     314: astore        17
     316: iconst_0
     317: istore        15
     319: aload_3
     320: checkcast     #101                // class java/util/Collection
     323: aload         14
     325: invokestatic  #188                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     328: aload         17
     330: swap
     331: invokeinterface #189,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     336: pop
     337: goto          286
     340: aload         10
     342: checkcast     #111                // class java/util/List
     345: nop
     346: aload         16
     348: swap
     349: checkcast     #101                // class java/util/Collection
     352: invokevirtual #193                // Method java/util/PriorityQueue.addAll:(Ljava/util/Collection;)Z
     355: pop
     356: goto          50
     359: aconst_null
     360: areturn

  public static final day23.Burrow parse(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #30                 // String filename
       3: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #226                // class java/io/File
       9: dup
      10: aload_0
      11: invokespecial #229                // Method java/io/File."<init>":(Ljava/lang/String;)V
      14: aconst_null
      15: iconst_1
      16: aconst_null
      17: invokestatic  #235                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      20: astore_1
      21: aload_1
      22: iconst_1
      23: invokeinterface #238,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      28: checkcast     #224                // class java/lang/String
      31: iconst_1
      32: invokestatic  #244                // Method kotlin/text/StringsKt.drop:(Ljava/lang/String;I)Ljava/lang/String;
      35: iconst_1
      36: invokestatic  #247                // Method kotlin/text/StringsKt.dropLast:(Ljava/lang/String;I)Ljava/lang/String;
      39: checkcast     #249                // class java/lang/CharSequence
      42: astore_3
      43: iconst_0
      44: istore        4
      46: aload_3
      47: astore        5
      49: new           #177                // class java/util/ArrayList
      52: dup
      53: aload_3
      54: invokeinterface #252,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      59: invokespecial #184                // Method java/util/ArrayList."<init>":(I)V
      62: checkcast     #101                // class java/util/Collection
      65: astore        6
      67: iconst_0
      68: istore        7
      70: iconst_0
      71: istore        8
      73: iload         8
      75: aload         5
      77: invokeinterface #252,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      82: if_icmpge     141
      85: aload         5
      87: iload         8
      89: invokeinterface #256,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      94: istore        9
      96: aload         6
      98: iload         9
     100: istore        10
     102: astore        31
     104: iconst_0
     105: istore        11
     107: iload         10
     109: bipush        46
     111: if_icmpne     118
     114: aconst_null
     115: goto          126
     118: iload         10
     120: invokestatic  #259                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     123: invokestatic  #264                // Method day23/Amphipod.valueOf:(Ljava/lang/String;)Lday23/Amphipod;
     126: aload         31
     128: swap
     129: invokeinterface #189,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     134: pop
     135: iinc          8, 1
     138: goto          73
     141: aload         6
     143: checkcast     #111                // class java/util/List
     146: nop
     147: astore_2
     148: aload_1
     149: checkcast     #157                // class java/lang/Iterable
     152: iconst_2
     153: invokestatic  #267                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     156: iconst_1
     157: invokestatic  #270                // Method kotlin/collections/CollectionsKt.dropLast:(Ljava/util/List;I)Ljava/util/List;
     160: astore_3
     161: new           #272                // class kotlin/ranges/IntRange
     164: dup
     165: iconst_0
     166: iconst_3
     167: invokespecial #275                // Method kotlin/ranges/IntRange."<init>":(II)V
     170: checkcast     #157                // class java/lang/Iterable
     173: astore        5
     175: iconst_0
     176: istore        6
     178: aload         5
     180: astore        7
     182: new           #177                // class java/util/ArrayList
     185: dup
     186: aload         5
     188: bipush        10
     190: invokestatic  #181                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     193: invokespecial #184                // Method java/util/ArrayList."<init>":(I)V
     196: checkcast     #101                // class java/util/Collection
     199: astore        8
     201: iconst_0
     202: istore        9
     204: aload         7
     206: invokeinterface #161,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     211: astore        10
     213: aload         10
     215: invokeinterface #166,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     220: ifeq          440
     223: aload         10
     225: checkcast     #277                // class kotlin/collections/IntIterator
     228: invokevirtual #280                // Method kotlin/collections/IntIterator.nextInt:()I
     231: istore        11
     233: aload         8
     235: iload         11
     237: istore        12
     239: astore        31
     241: iconst_0
     242: istore        13
     244: invokestatic  #284                // Method day23/Amphipod.values:()[Lday23/Amphipod;
     247: iload         12
     249: aaload
     250: astore        14
     252: aload_3
     253: checkcast     #157                // class java/lang/Iterable
     256: astore        15
     258: iconst_0
     259: istore        16
     261: aload         15
     263: astore        17
     265: new           #177                // class java/util/ArrayList
     268: dup
     269: invokespecial #285                // Method java/util/ArrayList."<init>":()V
     272: checkcast     #101                // class java/util/Collection
     275: astore        18
     277: iconst_0
     278: istore        19
     280: aload         17
     282: astore        20
     284: iconst_0
     285: istore        21
     287: aload         20
     289: invokeinterface #161,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     294: astore        22
     296: aload         22
     298: invokeinterface #166,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     303: ifeq          396
     306: aload         22
     308: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     313: astore        23
     315: aload         23
     317: astore        24
     319: iconst_0
     320: istore        25
     322: aload         24
     324: checkcast     #224                // class java/lang/String
     327: astore        26
     329: iconst_0
     330: istore        27
     332: aload         26
     334: iconst_3
     335: iload         12
     337: iconst_2
     338: imul
     339: iadd
     340: invokevirtual #286                // Method java/lang/String.charAt:(I)C
     343: bipush        46
     345: if_icmpne     352
     348: aconst_null
     349: goto          369
     352: aload         26
     354: iconst_3
     355: iload         12
     357: iconst_2
     358: imul
     359: iadd
     360: invokevirtual #286                // Method java/lang/String.charAt:(I)C
     363: invokestatic  #259                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     366: invokestatic  #264                // Method day23/Amphipod.valueOf:(Ljava/lang/String;)Lday23/Amphipod;
     369: dup
     370: ifnull        391
     373: astore        28
     375: iconst_0
     376: istore        29
     378: aload         18
     380: aload         28
     382: invokeinterface #189,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     387: pop
     388: goto          392
     391: pop
     392: nop
     393: goto          296
     396: nop
     397: aload         18
     399: checkcast     #111                // class java/util/List
     402: nop
     403: astore        30
     405: new           #288                // class day23/Room
     408: dup
     409: aload         14
     411: aload_3
     412: invokeinterface #291,  1          // InterfaceMethod java/util/List.size:()I
     417: iconst_2
     418: iload         12
     420: iconst_2
     421: imul
     422: iadd
     423: aload         30
     425: invokespecial #294                // Method day23/Room."<init>":(Lday23/Amphipod;IILjava/util/List;)V
     428: aload         31
     430: swap
     431: invokeinterface #189,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     436: pop
     437: goto          213
     440: aload         8
     442: checkcast     #111                // class java/util/List
     445: nop
     446: astore        4
     448: new           #120                // class day23/Burrow
     451: dup
     452: aload_2
     453: aload         4
     455: iconst_0
     456: iconst_4
     457: aconst_null
     458: invokespecial #297                // Method day23/Burrow."<init>":(Ljava/util/List;Ljava/util/List;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
     461: areturn

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

  private static final int solve$lambda$0(java.util.List);
    Code:
       0: aload_0
       1: invokestatic  #114                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       4: aload_0
       5: invokestatic  #118                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
       8: checkcast     #120                // class day23/Burrow
      11: invokevirtual #144                // Method day23/Burrow.getEnergy:()I
      14: ireturn

  private static final int solve$lambda$1(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #329,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #331                // class java/lang/Number
      10: invokevirtual #332                // Method java/lang/Number.intValue:()I
      13: ireturn
}


package day12

import java.io.File

fun Map<String, List<String>>.partOne(path: List<String>) : List<List<String>> {
    if (path.last() == "end") {
        return listOf(path)
    }
    return this[path.last()]!!
        .filter { it.uppercase() == it || !path.contains(it) }
        .map{ partOne( path + it) }
        .flatten()
}

fun Map<String, List<String>>.partTwo(path: List<String>, revisited: String? = null) : List<List<String>> {
    if (path.last() == "end") {
        return listOf(path)
    }
    return this[path.last()]!!
        .filter { it.uppercase() == it || !path.contains(it) || (it != "start" && path.contains(it) && revisited == null) }
        .map{ partTwo( path + it, if (it.lowercase() == it && path.contains(it)) it else revisited ) }
        .flatten()
}

fun main() {
    val input = File("src/day12/input.txt")
        .readLines()
        .map { it.split("-") }
    val bidirectional = input.map { (a, b) -> listOf(b, a) } + input
    val links = bidirectional.groupBy( keySelector = { it[0] }, valueTransform = { it[1] } )

    println(links.partOne(listOf("start")).size)
    println(links.partTwo(listOf("start")).size)
}

Compiled from "result.kt"
public final class day12.ResultKt {
  public static final java.util.List<java.util.List<java.lang.String>> partOne(java.util.Map<java.lang.String, ? extends java.util.List<java.lang.String>>, java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String path
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      16: ldc           #26                 // String end
      18: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      21: ifeq          29
      24: aload_1
      25: invokestatic  #34                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      28: areturn
      29: aload_0
      30: aload_1
      31: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      34: invokeinterface #40,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      39: dup
      40: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      43: checkcast     #46                 // class java/lang/Iterable
      46: astore_2
      47: nop
      48: iconst_0
      49: istore_3
      50: aload_2
      51: astore        4
      53: new           #48                 // class java/util/ArrayList
      56: dup
      57: invokespecial #52                 // Method java/util/ArrayList."<init>":()V
      60: checkcast     #54                 // class java/util/Collection
      63: astore        5
      65: iconst_0
      66: istore        6
      68: aload         4
      70: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      75: astore        7
      77: aload         7
      79: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      84: ifeq          160
      87: aload         7
      89: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      94: astore        8
      96: aload         8
      98: checkcast     #70                 // class java/lang/String
     101: astore        9
     103: iconst_0
     104: istore        10
     106: aload         9
     108: getstatic     #76                 // Field java/util/Locale.ROOT:Ljava/util/Locale;
     111: invokevirtual #80                 // Method java/lang/String.toUpperCase:(Ljava/util/Locale;)Ljava/lang/String;
     114: dup
     115: ldc           #82                 // String toUpperCase(...)
     117: invokestatic  #85                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     120: aload         9
     122: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     125: ifne          139
     128: aload_1
     129: aload         9
     131: invokeinterface #91,  2           // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     136: ifne          143
     139: iconst_1
     140: goto          144
     143: iconst_0
     144: ifeq          77
     147: aload         5
     149: aload         8
     151: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     156: pop
     157: goto          77
     160: aload         5
     162: checkcast     #87                 // class java/util/List
     165: nop
     166: checkcast     #46                 // class java/lang/Iterable
     169: astore_2
     170: nop
     171: iconst_0
     172: istore_3
     173: aload_2
     174: astore        4
     176: new           #48                 // class java/util/ArrayList
     179: dup
     180: aload_2
     181: bipush        10
     183: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     186: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
     189: checkcast     #54                 // class java/util/Collection
     192: astore        5
     194: iconst_0
     195: istore        6
     197: aload         4
     199: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     204: astore        7
     206: aload         7
     208: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     213: ifeq          264
     216: aload         7
     218: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     223: astore        8
     225: aload         5
     227: aload         8
     229: checkcast     #70                 // class java/lang/String
     232: astore        9
     234: astore        11
     236: iconst_0
     237: istore        10
     239: aload_0
     240: aload_1
     241: checkcast     #54                 // class java/util/Collection
     244: aload         9
     246: invokestatic  #105                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     249: invokestatic  #107                // Method partOne:(Ljava/util/Map;Ljava/util/List;)Ljava/util/List;
     252: aload         11
     254: swap
     255: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     260: pop
     261: goto          206
     264: aload         5
     266: checkcast     #87                 // class java/util/List
     269: nop
     270: checkcast     #46                 // class java/lang/Iterable
     273: invokestatic  #111                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     276: areturn

  public static final java.util.List<java.util.List<java.lang.String>> partTwo(java.util.Map<java.lang.String, ? extends java.util.List<java.lang.String>>, java.util.List<java.lang.String>, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String path
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      16: ldc           #26                 // String end
      18: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      21: ifeq          29
      24: aload_1
      25: invokestatic  #34                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      28: areturn
      29: aload_0
      30: aload_1
      31: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      34: invokeinterface #40,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      39: dup
      40: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      43: checkcast     #46                 // class java/lang/Iterable
      46: astore_3
      47: nop
      48: iconst_0
      49: istore        4
      51: aload_3
      52: astore        5
      54: new           #48                 // class java/util/ArrayList
      57: dup
      58: invokespecial #52                 // Method java/util/ArrayList."<init>":()V
      61: checkcast     #54                 // class java/util/Collection
      64: astore        6
      66: iconst_0
      67: istore        7
      69: aload         5
      71: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      76: astore        8
      78: aload         8
      80: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      85: ifeq          186
      88: aload         8
      90: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      95: astore        9
      97: aload         9
      99: checkcast     #70                 // class java/lang/String
     102: astore        10
     104: iconst_0
     105: istore        11
     107: aload         10
     109: getstatic     #76                 // Field java/util/Locale.ROOT:Ljava/util/Locale;
     112: invokevirtual #80                 // Method java/lang/String.toUpperCase:(Ljava/util/Locale;)Ljava/lang/String;
     115: dup
     116: ldc           #82                 // String toUpperCase(...)
     118: invokestatic  #85                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     121: aload         10
     123: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     126: ifne          165
     129: aload_1
     130: aload         10
     132: invokeinterface #91,  2           // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     137: ifeq          165
     140: aload         10
     142: ldc           #139                // String start
     144: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     147: ifne          169
     150: aload_1
     151: aload         10
     153: invokeinterface #91,  2           // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     158: ifeq          169
     161: aload_2
     162: ifnonnull     169
     165: iconst_1
     166: goto          170
     169: iconst_0
     170: ifeq          78
     173: aload         6
     175: aload         9
     177: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     182: pop
     183: goto          78
     186: aload         6
     188: checkcast     #87                 // class java/util/List
     191: nop
     192: checkcast     #46                 // class java/lang/Iterable
     195: astore_3
     196: nop
     197: iconst_0
     198: istore        4
     200: aload_3
     201: astore        5
     203: new           #48                 // class java/util/ArrayList
     206: dup
     207: aload_3
     208: bipush        10
     210: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     213: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
     216: checkcast     #54                 // class java/util/Collection
     219: astore        6
     221: iconst_0
     222: istore        7
     224: aload         5
     226: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     231: astore        8
     233: aload         8
     235: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     240: ifeq          330
     243: aload         8
     245: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     250: astore        9
     252: aload         6
     254: aload         9
     256: checkcast     #70                 // class java/lang/String
     259: astore        10
     261: astore        12
     263: iconst_0
     264: istore        11
     266: aload_0
     267: aload_1
     268: checkcast     #54                 // class java/util/Collection
     271: aload         10
     273: invokestatic  #105                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     276: aload         10
     278: getstatic     #76                 // Field java/util/Locale.ROOT:Ljava/util/Locale;
     281: invokevirtual #142                // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
     284: dup
     285: ldc           #144                // String toLowerCase(...)
     287: invokestatic  #85                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     290: aload         10
     292: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     295: ifeq          314
     298: aload_1
     299: aload         10
     301: invokeinterface #91,  2           // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     306: ifeq          314
     309: aload         10
     311: goto          315
     314: aload_2
     315: invokestatic  #146                // Method partTwo:(Ljava/util/Map;Ljava/util/List;Ljava/lang/String;)Ljava/util/List;
     318: aload         12
     320: swap
     321: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     326: pop
     327: goto          233
     330: aload         6
     332: checkcast     #87                 // class java/util/List
     335: nop
     336: checkcast     #46                 // class java/lang/Iterable
     339: invokestatic  #111                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     342: areturn

  public static java.util.List partTwo$default(java.util.Map, java.util.List, java.lang.String, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: aconst_null
       7: astore_2
       8: aload_0
       9: aload_1
      10: aload_2
      11: invokestatic  #146                // Method partTwo:(Ljava/util/Map;Ljava/util/List;Ljava/lang/String;)Ljava/util/List;
      14: areturn

  public static final void main();
    Code:
       0: new           #155                // class java/io/File
       3: dup
       4: ldc           #157                // String src/day12/input.txt
       6: invokespecial #160                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #166                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #46                 // class java/lang/Iterable
      18: astore_1
      19: nop
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #48                 // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #54                 // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          125
      63: aload         6
      65: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        7
      72: aload         4
      74: aload         7
      76: checkcast     #70                 // class java/lang/String
      79: astore        8
      81: astore        18
      83: iconst_0
      84: istore        9
      86: aload         8
      88: checkcast     #168                // class java/lang/CharSequence
      91: iconst_1
      92: anewarray     #70                 // class java/lang/String
      95: astore        10
      97: aload         10
      99: iconst_0
     100: ldc           #170                // String -
     102: aastore
     103: aload         10
     105: iconst_0
     106: iconst_0
     107: bipush        6
     109: aconst_null
     110: invokestatic  #176                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     113: aload         18
     115: swap
     116: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          53
     125: aload         4
     127: checkcast     #87                 // class java/util/List
     130: nop
     131: astore_0
     132: aload_0
     133: checkcast     #46                 // class java/lang/Iterable
     136: astore_2
     137: iconst_0
     138: istore_3
     139: aload_2
     140: astore        4
     142: new           #48                 // class java/util/ArrayList
     145: dup
     146: aload_2
     147: bipush        10
     149: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     152: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
     155: checkcast     #54                 // class java/util/Collection
     158: astore        5
     160: iconst_0
     161: istore        6
     163: aload         4
     165: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     170: astore        7
     172: aload         7
     174: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     179: ifeq          266
     182: aload         7
     184: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     189: astore        8
     191: aload         5
     193: aload         8
     195: checkcast     #87                 // class java/util/List
     198: astore        9
     200: astore        18
     202: iconst_0
     203: istore        10
     205: aload         9
     207: iconst_0
     208: invokeinterface #179,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     213: checkcast     #70                 // class java/lang/String
     216: astore        11
     218: aload         9
     220: iconst_1
     221: invokeinterface #179,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     226: checkcast     #70                 // class java/lang/String
     229: astore        12
     231: iconst_2
     232: anewarray     #70                 // class java/lang/String
     235: astore        13
     237: aload         13
     239: iconst_0
     240: aload         12
     242: aastore
     243: aload         13
     245: iconst_1
     246: aload         11
     248: aastore
     249: aload         13
     251: invokestatic  #182                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     254: aload         18
     256: swap
     257: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     262: pop
     263: goto          172
     266: aload         5
     268: checkcast     #87                 // class java/util/List
     271: nop
     272: checkcast     #54                 // class java/util/Collection
     275: aload_0
     276: checkcast     #46                 // class java/lang/Iterable
     279: invokestatic  #185                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     282: astore_1
     283: aload_1
     284: checkcast     #46                 // class java/lang/Iterable
     287: astore_3
     288: iconst_0
     289: istore        4
     291: aload_3
     292: astore        5
     294: new           #187                // class java/util/LinkedHashMap
     297: dup
     298: invokespecial #188                // Method java/util/LinkedHashMap."<init>":()V
     301: checkcast     #36                 // class java/util/Map
     304: astore        6
     306: iconst_0
     307: istore        7
     309: aload         5
     311: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     316: astore        8
     318: aload         8
     320: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     325: ifeq          460
     328: aload         8
     330: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     335: astore        9
     337: aload         9
     339: checkcast     #87                 // class java/util/List
     342: astore        10
     344: iconst_0
     345: istore        11
     347: aload         10
     349: iconst_0
     350: invokeinterface #179,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     355: checkcast     #70                 // class java/lang/String
     358: astore        12
     360: aload         6
     362: astore        13
     364: iconst_0
     365: istore        14
     367: aload         13
     369: aload         12
     371: invokeinterface #40,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     376: astore        15
     378: aload         15
     380: ifnonnull     415
     383: iconst_0
     384: istore        16
     386: new           #48                 // class java/util/ArrayList
     389: dup
     390: invokespecial #52                 // Method java/util/ArrayList."<init>":()V
     393: checkcast     #87                 // class java/util/List
     396: astore        16
     398: aload         13
     400: aload         12
     402: aload         16
     404: invokeinterface #192,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     409: pop
     410: aload         16
     412: goto          417
     415: aload         15
     417: nop
     418: checkcast     #87                 // class java/util/List
     421: astore        10
     423: aload         10
     425: aload         9
     427: checkcast     #87                 // class java/util/List
     430: astore        11
     432: astore        18
     434: iconst_0
     435: istore        17
     437: aload         11
     439: iconst_1
     440: invokeinterface #179,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     445: checkcast     #70                 // class java/lang/String
     448: aload         18
     450: swap
     451: invokeinterface #193,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     456: pop
     457: goto          318
     460: aload         6
     462: nop
     463: astore_2
     464: aload_2
     465: ldc           #139                // String start
     467: invokestatic  #34                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     470: invokestatic  #107                // Method partOne:(Ljava/util/Map;Ljava/util/List;)Ljava/util/List;
     473: invokeinterface #197,  1          // InterfaceMethod java/util/List.size:()I
     478: istore_3
     479: getstatic     #203                // Field java/lang/System.out:Ljava/io/PrintStream;
     482: iload_3
     483: invokevirtual #208                // Method java/io/PrintStream.println:(I)V
     486: aload_2
     487: ldc           #139                // String start
     489: invokestatic  #34                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     492: aconst_null
     493: iconst_2
     494: aconst_null
     495: invokestatic  #210                // Method partTwo$default:(Ljava/util/Map;Ljava/util/List;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/List;
     498: invokeinterface #197,  1          // InterfaceMethod java/util/List.size:()I
     503: istore_3
     504: getstatic     #203                // Field java/lang/System.out:Ljava/io/PrintStream;
     507: iload_3
     508: invokevirtual #208                // Method java/io/PrintStream.println:(I)V
     511: return

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