package com.codelicia.advent2021

import java.util.Stack

class Day09(private val input: List<String>) {

    private fun parseHeightmap(xs: List<String>): List<List<Int>> =
        xs.map { it.toCharArray().map(Char::digitToInt) }

    private fun <T> List<List<T>>.getLocation(p: Pair<Int, Int>): T? =
        this.getOrNull(p.first)?.getOrNull(p.second)

    private fun Pair<Int, Int>.adjacentLocations() =
        listOf(
            this.first - 1 to this.second,
            this.first + 1 to this.second,
            this.first     to this.second + 1,
            this.first     to this.second - 1
        )

    private fun Stack<Int>.riskLevel(): Int =
        this.size + this.sum()

    fun part1(): Int {
        val heightmap = parseHeightmap(input)
        val lowPoints = Stack<Int>()

        heightmap.forEachIndexed { y, row ->
            row.forEachIndexed { x, cell ->
                var currentCellIsLower = true
                for (adjacent in (y to x).adjacentLocations()) {
                    val adjacentCell = heightmap.getLocation(adjacent)
                    if (adjacentCell != null && adjacentCell <= cell) currentCellIsLower = false
                }

                if (currentCellIsLower) lowPoints.add(cell)
            }
        }

        return lowPoints.riskLevel()
    }

    fun part2(): Int {
        val heightmap = parseHeightmap(input)
        val basins = mutableListOf<MutableList<Int>>()

        heightmap.forEachIndexed { y, row ->
            row.forEachIndexed { x, cell ->
                var currentCellIsLower = true
                for (adjacent in (y to x).adjacentLocations()) {
                    val adjacentCell = heightmap.getLocation(adjacent)
                    if (adjacentCell != null && adjacentCell < cell) currentCellIsLower = false
                }

                if (currentCellIsLower) {
                    basins.add(findSmallerFrom(heightmap, y to x, mutableSetOf())!!)
                }
            }
        }

        return basins.map { it.size }.sortedDescending().take(3).reduce {
            x, y -> x * y
        }
    }

    private fun findSmallerFrom(heightmap: List<List<Int>>, p: Pair<Int, Int>, visited: MutableSet<Pair<Int, Int>>): MutableList<Int>? {

        val cell = heightmap.getLocation(p) ?: return null

        val lowPoints = mutableListOf<Int>()

        lowPoints.add(cell)
        visited.add(p)
        for (adjacent in p.adjacentLocations()) {
            val adjacentCell = heightmap.getLocation(adjacent)
            if (adjacentCell != null && adjacentCell > cell && adjacentCell != 9 && false == visited.contains(adjacent)) {
                val x = findSmallerFrom(heightmap, adjacent, visited)
                if (x != null) {
                    lowPoints.addAll(x)
                }
            }
        }

        return lowPoints
    }
}

Compiled from "Day09.kt"
public final class com.codelicia.advent2021.Day09 {
  private final java.util.List<java.lang.String> input;

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

  private final java.util.List<java.util.List<java.lang.Integer>> parseHeightmap(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #29                 // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: astore        4
      10: new           #31                 // class java/util/ArrayList
      13: dup
      14: aload_2
      15: bipush        10
      17: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      20: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #42                 // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        6
      31: aload         4
      33: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        7
      40: aload         7
      42: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          187
      50: aload         7
      52: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        8
      59: aload         5
      61: aload         8
      63: checkcast     #58                 // class java/lang/String
      66: astore        9
      68: astore        22
      70: iconst_0
      71: istore        10
      73: aload         9
      75: invokevirtual #62                 // Method java/lang/String.toCharArray:()[C
      78: dup
      79: ldc           #64                 // String toCharArray(...)
      81: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      84: astore        11
      86: nop
      87: iconst_0
      88: istore        12
      90: aload         11
      92: astore        13
      94: new           #31                 // class java/util/ArrayList
      97: dup
      98: aload         11
     100: arraylength
     101: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
     104: checkcast     #42                 // class java/util/Collection
     107: astore        14
     109: iconst_0
     110: istore        15
     112: iconst_0
     113: istore        16
     115: aload         13
     117: arraylength
     118: istore        17
     120: iload         16
     122: iload         17
     124: if_icmpge     168
     127: aload         13
     129: iload         16
     131: caload
     132: istore        18
     134: aload         14
     136: iload         18
     138: istore        19
     140: astore        20
     142: iconst_0
     143: istore        21
     145: iload         19
     147: invokestatic  #73                 // Method kotlin/text/CharsKt.digitToInt:(C)I
     150: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     153: aload         20
     155: swap
     156: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     161: pop
     162: iinc          16, 1
     165: goto          120
     168: aload         14
     170: checkcast     #85                 // class java/util/List
     173: nop
     174: nop
     175: aload         22
     177: swap
     178: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     183: pop
     184: goto          40
     187: aload         5
     189: checkcast     #85                 // class java/util/List
     192: nop
     193: areturn

  private final <T> T getLocation(java.util.List<? extends java.util.List<? extends T>>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_1
       1: aload_2
       2: invokevirtual #112                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: checkcast     #114                // class java/lang/Number
       8: invokevirtual #118                // Method java/lang/Number.intValue:()I
      11: invokestatic  #122                // Method kotlin/collections/CollectionsKt.getOrNull:(Ljava/util/List;I)Ljava/lang/Object;
      14: checkcast     #85                 // class java/util/List
      17: dup
      18: ifnull        37
      21: aload_2
      22: invokevirtual #125                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      25: checkcast     #114                // class java/lang/Number
      28: invokevirtual #118                // Method java/lang/Number.intValue:()I
      31: invokestatic  #122                // Method kotlin/collections/CollectionsKt.getOrNull:(Ljava/util/List;I)Ljava/lang/Object;
      34: goto          39
      37: pop
      38: aconst_null
      39: areturn

  private final java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>> adjacentLocations(kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: iconst_4
       1: anewarray     #109                // class kotlin/Pair
       4: astore_2
       5: aload_2
       6: iconst_0
       7: aload_1
       8: invokevirtual #112                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      11: checkcast     #114                // class java/lang/Number
      14: invokevirtual #118                // Method java/lang/Number.intValue:()I
      17: iconst_1
      18: isub
      19: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      22: aload_1
      23: invokevirtual #125                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      26: invokestatic  #137                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      29: aastore
      30: aload_2
      31: iconst_1
      32: aload_1
      33: invokevirtual #112                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      36: checkcast     #114                // class java/lang/Number
      39: invokevirtual #118                // Method java/lang/Number.intValue:()I
      42: iconst_1
      43: iadd
      44: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: aload_1
      48: invokevirtual #125                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      51: invokestatic  #137                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      54: aastore
      55: aload_2
      56: iconst_2
      57: aload_1
      58: invokevirtual #112                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      61: aload_1
      62: invokevirtual #125                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      65: checkcast     #114                // class java/lang/Number
      68: invokevirtual #118                // Method java/lang/Number.intValue:()I
      71: iconst_1
      72: iadd
      73: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      76: invokestatic  #137                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      79: aastore
      80: aload_2
      81: iconst_3
      82: aload_1
      83: invokevirtual #112                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      86: aload_1
      87: invokevirtual #125                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      90: checkcast     #114                // class java/lang/Number
      93: invokevirtual #118                // Method java/lang/Number.intValue:()I
      96: iconst_1
      97: isub
      98: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     101: invokestatic  #137                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     104: aastore
     105: aload_2
     106: invokestatic  #141                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     109: areturn

  private final int riskLevel(java.util.Stack<java.lang.Integer>);
    Code:
       0: aload_1
       1: invokevirtual #150                // Method java/util/Stack.size:()I
       4: aload_1
       5: checkcast     #29                 // class java/lang/Iterable
       8: invokestatic  #154                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      11: iadd
      12: ireturn

  public final int part1();
    Code:
       0: aload_0
       1: aload_0
       2: getfield      #22                 // Field input:Ljava/util/List;
       5: invokespecial #159                // Method parseHeightmap:(Ljava/util/List;)Ljava/util/List;
       8: astore_1
       9: new           #147                // class java/util/Stack
      12: dup
      13: invokespecial #160                // Method java/util/Stack."<init>":()V
      16: astore_2
      17: aload_1
      18: checkcast     #29                 // class java/lang/Iterable
      21: astore_3
      22: iconst_0
      23: istore        4
      25: iconst_0
      26: istore        5
      28: aload_3
      29: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      34: astore        6
      36: aload         6
      38: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          265
      46: aload         6
      48: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        7
      55: iload         5
      57: iinc          5, 1
      60: istore        8
      62: iload         8
      64: ifge          70
      67: invokestatic  #163                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      70: iload         8
      72: aload         7
      74: checkcast     #85                 // class java/util/List
      77: astore        9
      79: istore        10
      81: iconst_0
      82: istore        11
      84: aload         9
      86: checkcast     #29                 // class java/lang/Iterable
      89: astore        12
      91: iconst_0
      92: istore        13
      94: iconst_0
      95: istore        14
      97: aload         12
      99: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     104: astore        15
     106: aload         15
     108: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     113: ifeq          259
     116: aload         15
     118: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     123: astore        16
     125: iload         14
     127: iinc          14, 1
     130: istore        17
     132: iload         17
     134: ifge          140
     137: invokestatic  #163                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     140: iload         17
     142: aload         16
     144: checkcast     #114                // class java/lang/Number
     147: invokevirtual #118                // Method java/lang/Number.intValue:()I
     150: istore        18
     152: istore        19
     154: iconst_0
     155: istore        20
     157: iconst_1
     158: istore        21
     160: aload_0
     161: iload         10
     163: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     166: iload         19
     168: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     171: invokestatic  #137                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     174: invokespecial #165                // Method adjacentLocations:(Lkotlin/Pair;)Ljava/util/List;
     177: invokeinterface #166,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     182: astore        22
     184: aload         22
     186: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     191: ifeq          239
     194: aload         22
     196: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     201: checkcast     #109                // class kotlin/Pair
     204: astore        23
     206: aload_0
     207: aload_1
     208: aload         23
     210: invokespecial #168                // Method getLocation:(Ljava/util/List;Lkotlin/Pair;)Ljava/lang/Object;
     213: checkcast     #75                 // class java/lang/Integer
     216: astore        24
     218: aload         24
     220: ifnull        184
     223: aload         24
     225: invokevirtual #169                // Method java/lang/Integer.intValue:()I
     228: iload         18
     230: if_icmpgt     184
     233: iconst_0
     234: istore        21
     236: goto          184
     239: iload         21
     241: ifeq          254
     244: aload_2
     245: iload         18
     247: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     250: invokevirtual #170                // Method java/util/Stack.add:(Ljava/lang/Object;)Z
     253: pop
     254: nop
     255: nop
     256: goto          106
     259: nop
     260: nop
     261: nop
     262: goto          36
     265: nop
     266: aload_0
     267: aload_2
     268: invokespecial #172                // Method riskLevel:(Ljava/util/Stack;)I
     271: ireturn

  public final int part2();
    Code:
       0: aload_0
       1: aload_0
       2: getfield      #22                 // Field input:Ljava/util/List;
       5: invokespecial #159                // Method parseHeightmap:(Ljava/util/List;)Ljava/util/List;
       8: astore_1
       9: new           #31                 // class java/util/ArrayList
      12: dup
      13: invokespecial #191                // Method java/util/ArrayList."<init>":()V
      16: checkcast     #85                 // class java/util/List
      19: astore_2
      20: aload_1
      21: checkcast     #29                 // class java/lang/Iterable
      24: astore_3
      25: iconst_0
      26: istore        4
      28: iconst_0
      29: istore        5
      31: aload_3
      32: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        6
      39: aload         6
      41: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          297
      49: aload         6
      51: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        7
      58: iload         5
      60: iinc          5, 1
      63: istore        8
      65: iload         8
      67: ifge          73
      70: invokestatic  #163                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      73: iload         8
      75: aload         7
      77: checkcast     #85                 // class java/util/List
      80: astore        9
      82: istore        10
      84: iconst_0
      85: istore        11
      87: aload         9
      89: checkcast     #29                 // class java/lang/Iterable
      92: astore        12
      94: iconst_0
      95: istore        13
      97: iconst_0
      98: istore        14
     100: aload         12
     102: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     107: astore        15
     109: aload         15
     111: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     116: ifeq          291
     119: aload         15
     121: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     126: astore        16
     128: iload         14
     130: iinc          14, 1
     133: istore        17
     135: iload         17
     137: ifge          143
     140: invokestatic  #163                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     143: iload         17
     145: aload         16
     147: checkcast     #114                // class java/lang/Number
     150: invokevirtual #118                // Method java/lang/Number.intValue:()I
     153: istore        18
     155: istore        19
     157: iconst_0
     158: istore        20
     160: iconst_1
     161: istore        21
     163: aload_0
     164: iload         10
     166: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     169: iload         19
     171: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     174: invokestatic  #137                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     177: invokespecial #165                // Method adjacentLocations:(Lkotlin/Pair;)Ljava/util/List;
     180: invokeinterface #166,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     185: astore        22
     187: aload         22
     189: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     194: ifeq          242
     197: aload         22
     199: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     204: checkcast     #109                // class kotlin/Pair
     207: astore        23
     209: aload_0
     210: aload_1
     211: aload         23
     213: invokespecial #168                // Method getLocation:(Ljava/util/List;Lkotlin/Pair;)Ljava/lang/Object;
     216: checkcast     #75                 // class java/lang/Integer
     219: astore        24
     221: aload         24
     223: ifnull        187
     226: aload         24
     228: invokevirtual #169                // Method java/lang/Integer.intValue:()I
     231: iload         18
     233: if_icmpge     187
     236: iconst_0
     237: istore        21
     239: goto          187
     242: iload         21
     244: ifeq          286
     247: aload_2
     248: aload_0
     249: aload_1
     250: iload         10
     252: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     255: iload         19
     257: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     260: invokestatic  #137                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     263: new           #193                // class java/util/LinkedHashSet
     266: dup
     267: invokespecial #194                // Method java/util/LinkedHashSet."<init>":()V
     270: checkcast     #196                // class java/util/Set
     273: invokespecial #200                // Method findSmallerFrom:(Ljava/util/List;Lkotlin/Pair;Ljava/util/Set;)Ljava/util/List;
     276: dup
     277: invokestatic  #204                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     280: invokeinterface #205,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     285: pop
     286: nop
     287: nop
     288: goto          109
     291: nop
     292: nop
     293: nop
     294: goto          39
     297: nop
     298: aload_2
     299: checkcast     #29                 // class java/lang/Iterable
     302: astore_3
     303: iconst_0
     304: istore        4
     306: aload_3
     307: astore        5
     309: new           #31                 // class java/util/ArrayList
     312: dup
     313: aload_3
     314: bipush        10
     316: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     319: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
     322: checkcast     #42                 // class java/util/Collection
     325: astore        6
     327: iconst_0
     328: istore        7
     330: aload         5
     332: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     337: astore        8
     339: aload         8
     341: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     346: ifeq          394
     349: aload         8
     351: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     356: astore        9
     358: aload         6
     360: aload         9
     362: checkcast     #85                 // class java/util/List
     365: astore        10
     367: astore        25
     369: iconst_0
     370: istore        11
     372: aload         10
     374: invokeinterface #206,  1          // InterfaceMethod java/util/List.size:()I
     379: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     382: aload         25
     384: swap
     385: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     390: pop
     391: goto          339
     394: aload         6
     396: checkcast     #85                 // class java/util/List
     399: nop
     400: checkcast     #29                 // class java/lang/Iterable
     403: invokestatic  #210                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     406: checkcast     #29                 // class java/lang/Iterable
     409: iconst_3
     410: invokestatic  #214                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     413: checkcast     #29                 // class java/lang/Iterable
     416: astore_3
     417: iconst_0
     418: istore        4
     420: aload_3
     421: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     426: astore        5
     428: aload         5
     430: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     435: ifne          448
     438: new           #216                // class java/lang/UnsupportedOperationException
     441: dup
     442: ldc           #218                // String Empty collection can\'t be reduced.
     444: invokespecial #221                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     447: athrow
     448: aload         5
     450: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     455: astore        6
     457: aload         5
     459: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     464: ifeq          508
     467: aload         6
     469: aload         5
     471: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     476: checkcast     #114                // class java/lang/Number
     479: invokevirtual #118                // Method java/lang/Number.intValue:()I
     482: istore        7
     484: checkcast     #114                // class java/lang/Number
     487: invokevirtual #118                // Method java/lang/Number.intValue:()I
     490: istore        8
     492: iconst_0
     493: istore        9
     495: iload         8
     497: iload         7
     499: imul
     500: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     503: astore        6
     505: goto          457
     508: aload         6
     510: checkcast     #114                // class java/lang/Number
     513: invokevirtual #118                // Method java/lang/Number.intValue:()I
     516: ireturn

  private final java.util.List<java.lang.Integer> findSmallerFrom(java.util.List<? extends java.util.List<java.lang.Integer>>, kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokespecial #168                // Method getLocation:(Ljava/util/List;Lkotlin/Pair;)Ljava/lang/Object;
       6: checkcast     #75                 // class java/lang/Integer
       9: dup
      10: ifnull        19
      13: invokevirtual #169                // Method java/lang/Integer.intValue:()I
      16: goto          22
      19: pop
      20: aconst_null
      21: areturn
      22: istore        4
      24: new           #31                 // class java/util/ArrayList
      27: dup
      28: invokespecial #191                // Method java/util/ArrayList."<init>":()V
      31: checkcast     #85                 // class java/util/List
      34: astore        5
      36: aload         5
      38: iload         4
      40: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      43: invokeinterface #205,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      48: pop
      49: aload_3
      50: aload_2
      51: invokeinterface #233,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      56: pop
      57: aload_0
      58: aload_2
      59: invokespecial #165                // Method adjacentLocations:(Lkotlin/Pair;)Ljava/util/List;
      62: invokeinterface #166,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      67: astore        6
      69: aload         6
      71: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          175
      79: aload         6
      81: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: checkcast     #109                // class kotlin/Pair
      89: astore        7
      91: aload_0
      92: aload_1
      93: aload         7
      95: invokespecial #168                // Method getLocation:(Ljava/util/List;Lkotlin/Pair;)Ljava/lang/Object;
      98: checkcast     #75                 // class java/lang/Integer
     101: astore        8
     103: aload         8
     105: ifnull        69
     108: aload         8
     110: invokevirtual #169                // Method java/lang/Integer.intValue:()I
     113: iload         4
     115: if_icmple     69
     118: aload         8
     120: bipush        9
     122: istore        9
     124: invokevirtual #169                // Method java/lang/Integer.intValue:()I
     127: iload         9
     129: if_icmpeq     69
     132: iconst_0
     133: aload_3
     134: aload         7
     136: invokeinterface #236,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     141: if_icmpne     69
     144: aload_0
     145: aload_1
     146: aload         7
     148: aload_3
     149: invokespecial #200                // Method findSmallerFrom:(Ljava/util/List;Lkotlin/Pair;Ljava/util/Set;)Ljava/util/List;
     152: astore        9
     154: aload         9
     156: ifnull        69
     159: aload         5
     161: aload         9
     163: checkcast     #42                 // class java/util/Collection
     166: invokeinterface #240,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     171: pop
     172: goto          69
     175: aload         5
     177: areturn
}


package com.codelicia.advent2021

import java.util.Stack

class Day10(private val input: List<String>) {

    private val scoreTable: Map<String, Long> = mapOf(
        ")" to 3L,
        "]" to 57L,
        "}" to 1197L,
        ">" to 25137L,
    )

    private val scoreTableForIncomplete: Map<String, Long> = mapOf(
        "(" to 1L,
        "[" to 2L,
        "{" to 3L,
        "<" to 4L,
    )

    private val openChar = listOf("(", "[", "{", "<")
    private val closeChar = listOf(")", "]", "}", ">")

    fun part1(): Long {
        val queue = input.map { line -> ArrayDeque(line.split("")) }

        val order = ArrayDeque<String>()
        var points = 0L

        for (line in queue) {
            for (char in line.indices) {
                val lineChar = line[char]
                if (lineChar.isBlank()) continue

                if (openChar.contains(lineChar)) {
                    order.add(lineChar)
                } else {
                    val removed = order.removeLast()

                    if (openChar.zip(closeChar).first { it.first == removed }.second != lineChar) {
                        points += scoreTable[lineChar]!!
                    }
                }
            }
        }

        return points
    }

    fun part2(): Long {
        val queue = input.map { line -> ArrayDeque(line.split("")) }
        val closing = Stack<Long>()

        for (line in queue) {
            val order = ArrayDeque<String>()

            var error = false
            for (char in line.indices) {
                val lineChar = line[char]
                if (lineChar.isBlank() || error == true) continue

                if (openChar.contains(lineChar)) {
                    order.add(lineChar)
                } else {
                    val removed = order.removeLast()

                    if (openChar.zip(closeChar).first { it.first == removed }.second != lineChar) {
                        error = true
                        continue
                    }
                }
            }

            if (order.isNotEmpty() && error == false) {
                order.reversed().fold(0L) { acc, s ->
                    (acc * 5) + scoreTableForIncomplete[s]!!
                }
                    .also { closing.add(it) }
            }
        }
        closing.sort()

        return closing[closing.size.floorDiv(2)]
    }
}

Compiled from "Day10.kt"
public final class com.codelicia.advent2021.Day10 {
  private final java.util.List<java.lang.String> input;

  private final java.util.Map<java.lang.String, java.lang.Long> scoreTable;

  private final java.util.Map<java.lang.String, java.lang.Long> scoreTableForIncomplete;

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

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

  public com.codelicia.advent2021.Day10(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #22                 // Field input:Ljava/util/List;
      15: aload_0
      16: iconst_4
      17: anewarray     #24                 // class kotlin/Pair
      20: astore_2
      21: aload_2
      22: iconst_0
      23: ldc           #26                 // String )
      25: ldc2_w        #27                 // long 3l
      28: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      31: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      34: aastore
      35: aload_2
      36: iconst_1
      37: ldc           #42                 // String ]
      39: ldc2_w        #43                 // long 57l
      42: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      45: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      48: aastore
      49: aload_2
      50: iconst_2
      51: ldc           #46                 // String }
      53: ldc2_w        #47                 // long 1197l
      56: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      59: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      62: aastore
      63: aload_2
      64: iconst_3
      65: ldc           #50                 // String >
      67: ldc2_w        #51                 // long 25137l
      70: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      73: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      76: aastore
      77: aload_2
      78: invokestatic  #58                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      81: putfield      #62                 // Field scoreTable:Ljava/util/Map;
      84: aload_0
      85: iconst_4
      86: anewarray     #24                 // class kotlin/Pair
      89: astore_2
      90: aload_2
      91: iconst_0
      92: ldc           #64                 // String (
      94: lconst_1
      95: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      98: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     101: aastore
     102: aload_2
     103: iconst_1
     104: ldc           #66                 // String [
     106: ldc2_w        #67                 // long 2l
     109: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     112: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     115: aastore
     116: aload_2
     117: iconst_2
     118: ldc           #70                 // String {
     120: ldc2_w        #27                 // long 3l
     123: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     126: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     129: aastore
     130: aload_2
     131: iconst_3
     132: ldc           #72                 // String <
     134: ldc2_w        #73                 // long 4l
     137: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     140: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     143: aastore
     144: aload_2
     145: invokestatic  #58                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     148: putfield      #77                 // Field scoreTableForIncomplete:Ljava/util/Map;
     151: aload_0
     152: iconst_4
     153: anewarray     #79                 // class java/lang/String
     156: astore_2
     157: aload_2
     158: iconst_0
     159: ldc           #64                 // String (
     161: aastore
     162: aload_2
     163: iconst_1
     164: ldc           #66                 // String [
     166: aastore
     167: aload_2
     168: iconst_2
     169: ldc           #70                 // String {
     171: aastore
     172: aload_2
     173: iconst_3
     174: ldc           #72                 // String <
     176: aastore
     177: aload_2
     178: invokestatic  #85                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     181: putfield      #88                 // Field openChar:Ljava/util/List;
     184: aload_0
     185: iconst_4
     186: anewarray     #79                 // class java/lang/String
     189: astore_2
     190: aload_2
     191: iconst_0
     192: ldc           #26                 // String )
     194: aastore
     195: aload_2
     196: iconst_1
     197: ldc           #42                 // String ]
     199: aastore
     200: aload_2
     201: iconst_2
     202: ldc           #46                 // String }
     204: aastore
     205: aload_2
     206: iconst_3
     207: ldc           #50                 // String >
     209: aastore
     210: aload_2
     211: invokestatic  #85                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     214: putfield      #91                 // Field closeChar:Ljava/util/List;
     217: return

  public final long part1();
    Code:
       0: aload_0
       1: getfield      #22                 // Field input:Ljava/util/List;
       4: checkcast     #97                 // class java/lang/Iterable
       7: astore_2
       8: iconst_0
       9: istore_3
      10: aload_2
      11: astore        4
      13: new           #99                 // class java/util/ArrayList
      16: dup
      17: aload_2
      18: bipush        10
      20: invokestatic  #103                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      23: invokespecial #106                // Method java/util/ArrayList."<init>":(I)V
      26: checkcast     #108                // class java/util/Collection
      29: astore        5
      31: iconst_0
      32: istore        6
      34: aload         4
      36: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore        7
      43: aload         7
      45: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          125
      53: aload         7
      55: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        8
      62: aload         5
      64: aload         8
      66: checkcast     #79                 // class java/lang/String
      69: astore        9
      71: astore        17
      73: iconst_0
      74: istore        10
      76: new           #124                // class kotlin/collections/ArrayDeque
      79: dup
      80: aload         9
      82: checkcast     #126                // class java/lang/CharSequence
      85: iconst_1
      86: anewarray     #79                 // class java/lang/String
      89: astore        11
      91: aload         11
      93: iconst_0
      94: ldc           #128                // String
      96: aastore
      97: aload         11
      99: iconst_0
     100: iconst_0
     101: bipush        6
     103: aconst_null
     104: invokestatic  #134                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     107: checkcast     #108                // class java/util/Collection
     110: invokespecial #137                // Method kotlin/collections/ArrayDeque."<init>":(Ljava/util/Collection;)V
     113: aload         17
     115: swap
     116: invokeinterface #141,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          43
     125: aload         5
     127: checkcast     #143                // class java/util/List
     130: nop
     131: astore_1
     132: new           #124                // class kotlin/collections/ArrayDeque
     135: dup
     136: invokespecial #144                // Method kotlin/collections/ArrayDeque."<init>":()V
     139: astore_2
     140: lconst_0
     141: lstore_3
     142: aload_1
     143: invokeinterface #145,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     148: astore        5
     150: aload         5
     152: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     157: ifeq          385
     160: aload         5
     162: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     167: checkcast     #124                // class kotlin/collections/ArrayDeque
     170: astore        6
     172: iconst_0
     173: istore        7
     175: aload         6
     177: checkcast     #108                // class java/util/Collection
     180: invokeinterface #149,  1          // InterfaceMethod java/util/Collection.size:()I
     185: istore        8
     187: iload         7
     189: iload         8
     191: if_icmpge     150
     194: aload         6
     196: iload         7
     198: invokevirtual #153                // Method kotlin/collections/ArrayDeque.get:(I)Ljava/lang/Object;
     201: checkcast     #79                 // class java/lang/String
     204: astore        9
     206: aload         9
     208: checkcast     #126                // class java/lang/CharSequence
     211: invokestatic  #157                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
     214: ifne          379
     217: aload_0
     218: getfield      #88                 // Field openChar:Ljava/util/List;
     221: aload         9
     223: invokeinterface #160,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     228: ifeq          241
     231: aload_2
     232: aload         9
     234: invokevirtual #161                // Method kotlin/collections/ArrayDeque.add:(Ljava/lang/Object;)Z
     237: pop
     238: goto          379
     241: aload_2
     242: invokevirtual #164                // Method kotlin/collections/ArrayDeque.removeLast:()Ljava/lang/Object;
     245: checkcast     #79                 // class java/lang/String
     248: astore        10
     250: aload_0
     251: getfield      #88                 // Field openChar:Ljava/util/List;
     254: checkcast     #97                 // class java/lang/Iterable
     257: aload_0
     258: getfield      #91                 // Field closeChar:Ljava/util/List;
     261: checkcast     #97                 // class java/lang/Iterable
     264: invokestatic  #168                // Method kotlin/collections/CollectionsKt.zip:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
     267: checkcast     #97                 // class java/lang/Iterable
     270: astore        11
     272: iconst_0
     273: istore        12
     275: aload         11
     277: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     282: astore        13
     284: aload         13
     286: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     291: ifeq          331
     294: aload         13
     296: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     301: astore        14
     303: aload         14
     305: checkcast     #24                 // class kotlin/Pair
     308: astore        15
     310: iconst_0
     311: istore        16
     313: aload         15
     315: invokevirtual #171                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     318: aload         10
     320: invokestatic  #175                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     323: ifeq          284
     326: aload         14
     328: goto          341
     331: new           #177                // class java/util/NoSuchElementException
     334: dup
     335: ldc           #179                // String Collection contains no element matching the predicate.
     337: invokespecial #182                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     340: athrow
     341: checkcast     #24                 // class kotlin/Pair
     344: invokevirtual #185                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     347: aload         9
     349: invokestatic  #175                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     352: ifne          379
     355: lload_3
     356: aload_0
     357: getfield      #62                 // Field scoreTable:Ljava/util/Map;
     360: aload         9
     362: invokeinterface #190,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     367: dup
     368: invokestatic  #194                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     371: checkcast     #196                // class java/lang/Number
     374: invokevirtual #199                // Method java/lang/Number.longValue:()J
     377: ladd
     378: lstore_3
     379: iinc          7, 1
     382: goto          187
     385: lload_3
     386: lreturn

  public final long part2();
    Code:
       0: aload_0
       1: getfield      #22                 // Field input:Ljava/util/List;
       4: checkcast     #97                 // class java/lang/Iterable
       7: astore_2
       8: iconst_0
       9: istore_3
      10: aload_2
      11: astore        4
      13: new           #99                 // class java/util/ArrayList
      16: dup
      17: aload_2
      18: bipush        10
      20: invokestatic  #103                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      23: invokespecial #106                // Method java/util/ArrayList."<init>":(I)V
      26: checkcast     #108                // class java/util/Collection
      29: astore        5
      31: iconst_0
      32: istore        6
      34: aload         4
      36: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore        7
      43: aload         7
      45: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          125
      53: aload         7
      55: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        9
      62: aload         5
      64: aload         9
      66: checkcast     #79                 // class java/lang/String
      69: astore        11
      71: astore        20
      73: iconst_0
      74: istore        12
      76: new           #124                // class kotlin/collections/ArrayDeque
      79: dup
      80: aload         11
      82: checkcast     #126                // class java/lang/CharSequence
      85: iconst_1
      86: anewarray     #79                 // class java/lang/String
      89: astore        14
      91: aload         14
      93: iconst_0
      94: ldc           #128                // String
      96: aastore
      97: aload         14
      99: iconst_0
     100: iconst_0
     101: bipush        6
     103: aconst_null
     104: invokestatic  #134                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     107: checkcast     #108                // class java/util/Collection
     110: invokespecial #137                // Method kotlin/collections/ArrayDeque."<init>":(Ljava/util/Collection;)V
     113: aload         20
     115: swap
     116: invokeinterface #141,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          43
     125: aload         5
     127: checkcast     #143                // class java/util/List
     130: nop
     131: astore_1
     132: new           #229                // class java/util/Stack
     135: dup
     136: invokespecial #230                // Method java/util/Stack."<init>":()V
     139: astore_2
     140: aload_1
     141: invokeinterface #145,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     146: astore_3
     147: aload_3
     148: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     153: ifeq          533
     156: aload_3
     157: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     162: checkcast     #124                // class kotlin/collections/ArrayDeque
     165: astore        4
     167: new           #124                // class kotlin/collections/ArrayDeque
     170: dup
     171: invokespecial #144                // Method kotlin/collections/ArrayDeque."<init>":()V
     174: astore        5
     176: iconst_0
     177: istore        6
     179: iconst_0
     180: istore        7
     182: aload         4
     184: checkcast     #108                // class java/util/Collection
     187: invokeinterface #149,  1          // InterfaceMethod java/util/Collection.size:()I
     192: istore        9
     194: iload         7
     196: iload         9
     198: if_icmpge     383
     201: aload         4
     203: iload         7
     205: invokevirtual #153                // Method kotlin/collections/ArrayDeque.get:(I)Ljava/lang/Object;
     208: checkcast     #79                 // class java/lang/String
     211: astore        11
     213: aload         11
     215: checkcast     #126                // class java/lang/CharSequence
     218: invokestatic  #157                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
     221: ifne          377
     224: iload         6
     226: iconst_1
     227: if_icmpne     233
     230: goto          377
     233: aload_0
     234: getfield      #88                 // Field openChar:Ljava/util/List;
     237: aload         11
     239: invokeinterface #160,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     244: ifeq          258
     247: aload         5
     249: aload         11
     251: invokevirtual #161                // Method kotlin/collections/ArrayDeque.add:(Ljava/lang/Object;)Z
     254: pop
     255: goto          377
     258: aload         5
     260: invokevirtual #164                // Method kotlin/collections/ArrayDeque.removeLast:()Ljava/lang/Object;
     263: checkcast     #79                 // class java/lang/String
     266: astore        12
     268: aload_0
     269: getfield      #88                 // Field openChar:Ljava/util/List;
     272: checkcast     #97                 // class java/lang/Iterable
     275: aload_0
     276: getfield      #91                 // Field closeChar:Ljava/util/List;
     279: checkcast     #97                 // class java/lang/Iterable
     282: invokestatic  #168                // Method kotlin/collections/CollectionsKt.zip:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
     285: checkcast     #97                 // class java/lang/Iterable
     288: astore        14
     290: iconst_0
     291: istore        15
     293: aload         14
     295: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     300: astore        16
     302: aload         16
     304: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     309: ifeq          349
     312: aload         16
     314: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     319: astore        17
     321: aload         17
     323: checkcast     #24                 // class kotlin/Pair
     326: astore        18
     328: iconst_0
     329: istore        19
     331: aload         18
     333: invokevirtual #171                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     336: aload         12
     338: invokestatic  #175                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     341: ifeq          302
     344: aload         17
     346: goto          359
     349: new           #177                // class java/util/NoSuchElementException
     352: dup
     353: ldc           #179                // String Collection contains no element matching the predicate.
     355: invokespecial #182                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     358: athrow
     359: checkcast     #24                 // class kotlin/Pair
     362: invokevirtual #185                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     365: aload         11
     367: invokestatic  #175                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     370: ifne          377
     373: iconst_1
     374: istore        6
     376: nop
     377: iinc          7, 1
     380: goto          194
     383: aload         5
     385: checkcast     #108                // class java/util/Collection
     388: invokeinterface #233,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     393: ifne          400
     396: iconst_1
     397: goto          401
     400: iconst_0
     401: ifeq          147
     404: iload         6
     406: ifne          147
     409: aload         5
     411: checkcast     #97                 // class java/lang/Iterable
     414: invokestatic  #237                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     417: checkcast     #97                 // class java/lang/Iterable
     420: astore        7
     422: lconst_0
     423: lstore        9
     425: iconst_0
     426: istore        11
     428: lload         9
     430: lstore        12
     432: aload         7
     434: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     439: astore        14
     441: aload         14
     443: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     448: ifeq          506
     451: aload         14
     453: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     458: astore        15
     460: lload         12
     462: aload         15
     464: checkcast     #79                 // class java/lang/String
     467: astore        16
     469: lstore        17
     471: iconst_0
     472: istore        19
     474: lload         17
     476: iconst_5
     477: i2l
     478: lmul
     479: aload_0
     480: getfield      #77                 // Field scoreTableForIncomplete:Ljava/util/Map;
     483: aload         16
     485: invokeinterface #190,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     490: dup
     491: invokestatic  #194                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     494: checkcast     #196                // class java/lang/Number
     497: invokevirtual #199                // Method java/lang/Number.longValue:()J
     500: ladd
     501: lstore        12
     503: goto          441
     506: lload         12
     508: lstore        7
     510: lload         7
     512: lstore        9
     514: iconst_0
     515: istore        12
     517: aload_2
     518: lload         9
     520: invokestatic  #34                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     523: invokevirtual #238                // Method java/util/Stack.add:(Ljava/lang/Object;)Z
     526: pop
     527: lload         7
     529: pop2
     530: goto          147
     533: aload_2
     534: checkcast     #143                // class java/util/List
     537: invokestatic  #241                // Method kotlin/collections/CollectionsKt.sort:(Ljava/util/List;)V
     540: aload_2
     541: aload_2
     542: invokevirtual #242                // Method java/util/Stack.size:()I
     545: istore        4
     547: iconst_2
     548: istore        5
     550: iload         4
     552: iload         5
     554: idiv
     555: istore        6
     557: iload         4
     559: iload         5
     561: ixor
     562: ifge          578
     565: iload         6
     567: iload         5
     569: imul
     570: iload         4
     572: if_icmpeq     578
     575: iinc          6, -1
     578: iload         6
     580: invokevirtual #243                // Method java/util/Stack.get:(I)Ljava/lang/Object;
     583: dup
     584: ldc           #245                // String get(...)
     586: invokestatic  #248                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     589: checkcast     #196                // class java/lang/Number
     592: invokevirtual #199                // Method java/lang/Number.longValue:()J
     595: lreturn
}


package com.codelicia.advent2021

import java.util.Stack

class Day12(mapOfTheRemainingCaves: List<String>) {

    data class Vertex(val label: String)

    private val map = mapOfTheRemainingCaves
        .map { cave -> cave.split("-") }
        .map { cave -> cave.first() to cave.last() }

    private val graph = buildMap<Vertex, MutableList<Vertex>> {
        for (i in map) {
            this.putIfAbsent(Vertex(i.first), mutableListOf())
            this.putIfAbsent(Vertex(i.second), mutableListOf())
            this[Vertex(i.first)]!!.add(Vertex(i.second))
            this[Vertex(i.second)]!!.add(Vertex(i.first))
        }
    }

    fun part1(): Int = solve(fun(_) = true)

    fun part2(): Int {
        return solve(fun(visited: HashMap<String, Int>): Boolean {
            return visited.toMap().filter { it.value > 1 }.filter { it.key.lowercase() == it.key }.values.isNotEmpty()
        })
    }

    private fun solve(predicate: (HashMap<String, Int>) -> Boolean): Int {
        val queue = Stack<Vertex>()
        queue.add(Vertex("start"))

        val results = mutableListOf<String>()

        while (queue.isNotEmpty()) bfs(graph, predicate, queue, results, "start")

        return results.size
    }

    private fun bfs(
        graph: Map<Vertex, MutableList<Vertex>>,
        predicate: (HashMap<String, Int>) -> Boolean,
        queue: Stack<Vertex>,
        results: MutableList<String>,
        path: String,
        visited: HashMap<String, Int> = hashMapOf()
    ) {
        val vertex = queue.pop()
        if (vertex.label == "end") {
            results.add(path)
            return
        }

        val count = visited.getOrElse(vertex.label) { 0 }
        visited[vertex.label] = count + 1

        val neighbours = graph[vertex]!!
        for (neighbour in neighbours) {
            if (neighbour.label != "start") {
                val satisfiesPredicate = predicate(visited)

                if (neighbour.label.lowercase() == neighbour.label && visited.contains(neighbour.label) && satisfiesPredicate == true) continue

                queue.add(neighbour)
                bfs(graph, predicate, queue, results, "$path,${neighbour.label}", HashMap(visited))
            }
        }
    }
}

Compiled from "Day12.kt"
public final class com.codelicia.advent2021.Day12 {
  private final java.util.List<kotlin.Pair<java.lang.String, java.lang.String>> map;

  private final java.util.Map<com.codelicia.advent2021.Day12$Vertex, java.util.List<com.codelicia.advent2021.Day12$Vertex>> graph;

  public com.codelicia.advent2021.Day12(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #10                 // String mapOfTheRemainingCaves
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: checkcast     #21                 // class java/lang/Iterable
      15: astore_2
      16: astore        12
      18: iconst_0
      19: istore_3
      20: aload_2
      21: astore        4
      23: new           #23                 // class java/util/ArrayList
      26: dup
      27: aload_2
      28: bipush        10
      30: invokestatic  #29                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #32                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #34                 // class java/util/Collection
      39: astore        5
      41: iconst_0
      42: istore        6
      44: aload         4
      46: invokeinterface #38,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        7
      53: aload         7
      55: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          125
      63: aload         7
      65: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        8
      72: aload         5
      74: aload         8
      76: checkcast     #50                 // class java/lang/String
      79: astore        9
      81: astore        13
      83: iconst_0
      84: istore        10
      86: aload         9
      88: checkcast     #52                 // class java/lang/CharSequence
      91: iconst_1
      92: anewarray     #50                 // class java/lang/String
      95: astore        11
      97: aload         11
      99: iconst_0
     100: ldc           #54                 // String -
     102: aastore
     103: aload         11
     105: iconst_0
     106: iconst_0
     107: bipush        6
     109: aconst_null
     110: invokestatic  #60                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     113: aload         13
     115: swap
     116: invokeinterface #64,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          53
     125: aload         5
     127: checkcast     #66                 // class java/util/List
     130: nop
     131: aload         12
     133: swap
     134: checkcast     #21                 // class java/lang/Iterable
     137: astore_2
     138: astore        12
     140: iconst_0
     141: istore_3
     142: aload_2
     143: astore        4
     145: new           #23                 // class java/util/ArrayList
     148: dup
     149: aload_2
     150: bipush        10
     152: invokestatic  #29                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     155: invokespecial #32                 // Method java/util/ArrayList."<init>":(I)V
     158: checkcast     #34                 // class java/util/Collection
     161: astore        5
     163: iconst_0
     164: istore        6
     166: aload         4
     168: invokeinterface #38,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     173: astore        7
     175: aload         7
     177: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     182: ifeq          233
     185: aload         7
     187: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     192: astore        8
     194: aload         5
     196: aload         8
     198: checkcast     #66                 // class java/util/List
     201: astore        9
     203: astore        13
     205: iconst_0
     206: istore        10
     208: aload         9
     210: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     213: aload         9
     215: invokestatic  #73                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     218: invokestatic  #79                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     221: aload         13
     223: swap
     224: invokeinterface #64,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     229: pop
     230: goto          175
     233: aload         5
     235: checkcast     #66                 // class java/util/List
     238: nop
     239: aload         12
     241: swap
     242: putfield      #83                 // Field map:Ljava/util/List;
     245: aload_0
     246: invokestatic  #89                 // Method kotlin/collections/MapsKt.createMapBuilder:()Ljava/util/Map;
     249: astore_2
     250: aload_2
     251: astore_3
     252: astore        12
     254: iconst_0
     255: istore        4
     257: aload_0
     258: getfield      #83                 // Field map:Ljava/util/List;
     261: invokeinterface #90,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     266: astore        5
     268: aload         5
     270: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     275: ifeq          455
     278: aload         5
     280: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     285: checkcast     #92                 // class kotlin/Pair
     288: astore        6
     290: aload_3
     291: new           #94                 // class com/codelicia/advent2021/Day12$Vertex
     294: dup
     295: aload         6
     297: invokevirtual #97                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     300: checkcast     #50                 // class java/lang/String
     303: invokespecial #100                // Method com/codelicia/advent2021/Day12$Vertex."<init>":(Ljava/lang/String;)V
     306: new           #23                 // class java/util/ArrayList
     309: dup
     310: invokespecial #101                // Method java/util/ArrayList."<init>":()V
     313: checkcast     #66                 // class java/util/List
     316: invokeinterface #107,  3          // InterfaceMethod java/util/Map.putIfAbsent:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     321: pop
     322: aload_3
     323: new           #94                 // class com/codelicia/advent2021/Day12$Vertex
     326: dup
     327: aload         6
     329: invokevirtual #110                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     332: checkcast     #50                 // class java/lang/String
     335: invokespecial #100                // Method com/codelicia/advent2021/Day12$Vertex."<init>":(Ljava/lang/String;)V
     338: new           #23                 // class java/util/ArrayList
     341: dup
     342: invokespecial #101                // Method java/util/ArrayList."<init>":()V
     345: checkcast     #66                 // class java/util/List
     348: invokeinterface #107,  3          // InterfaceMethod java/util/Map.putIfAbsent:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     353: pop
     354: aload_3
     355: new           #94                 // class com/codelicia/advent2021/Day12$Vertex
     358: dup
     359: aload         6
     361: invokevirtual #97                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     364: checkcast     #50                 // class java/lang/String
     367: invokespecial #100                // Method com/codelicia/advent2021/Day12$Vertex."<init>":(Ljava/lang/String;)V
     370: invokeinterface #114,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     375: dup
     376: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     379: checkcast     #66                 // class java/util/List
     382: new           #94                 // class com/codelicia/advent2021/Day12$Vertex
     385: dup
     386: aload         6
     388: invokevirtual #110                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     391: checkcast     #50                 // class java/lang/String
     394: invokespecial #100                // Method com/codelicia/advent2021/Day12$Vertex."<init>":(Ljava/lang/String;)V
     397: invokeinterface #119,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     402: pop
     403: aload_3
     404: new           #94                 // class com/codelicia/advent2021/Day12$Vertex
     407: dup
     408: aload         6
     410: invokevirtual #110                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     413: checkcast     #50                 // class java/lang/String
     416: invokespecial #100                // Method com/codelicia/advent2021/Day12$Vertex."<init>":(Ljava/lang/String;)V
     419: invokeinterface #114,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     424: dup
     425: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     428: checkcast     #66                 // class java/util/List
     431: new           #94                 // class com/codelicia/advent2021/Day12$Vertex
     434: dup
     435: aload         6
     437: invokevirtual #97                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     440: checkcast     #50                 // class java/lang/String
     443: invokespecial #100                // Method com/codelicia/advent2021/Day12$Vertex."<init>":(Ljava/lang/String;)V
     446: invokeinterface #119,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     451: pop
     452: goto          268
     455: nop
     456: aload         12
     458: aload_2
     459: invokestatic  #123                // Method kotlin/collections/MapsKt.build:(Ljava/util/Map;)Ljava/util/Map;
     462: putfield      #127                // Field graph:Ljava/util/Map;
     465: return

  public final int part1();
    Code:
       0: aload_0
       1: invokedynamic #168,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
       6: invokespecial #172                // Method solve:(Lkotlin/jvm/functions/Function1;)I
       9: ireturn

  public final int part2();
    Code:
       0: aload_0
       1: invokedynamic #178,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
       6: invokespecial #172                // Method solve:(Lkotlin/jvm/functions/Function1;)I
       9: ireturn

  private final int solve(kotlin.jvm.functions.Function1<? super java.util.HashMap<java.lang.String, java.lang.Integer>, java.lang.Boolean>);
    Code:
       0: new           #181                // class java/util/Stack
       3: dup
       4: invokespecial #182                // Method java/util/Stack."<init>":()V
       7: astore_2
       8: aload_2
       9: new           #94                 // class com/codelicia/advent2021/Day12$Vertex
      12: dup
      13: ldc           #184                // String start
      15: invokespecial #100                // Method com/codelicia/advent2021/Day12$Vertex."<init>":(Ljava/lang/String;)V
      18: invokevirtual #185                // Method java/util/Stack.add:(Ljava/lang/Object;)Z
      21: pop
      22: new           #23                 // class java/util/ArrayList
      25: dup
      26: invokespecial #101                // Method java/util/ArrayList."<init>":()V
      29: checkcast     #66                 // class java/util/List
      32: astore_3
      33: aload_2
      34: checkcast     #34                 // class java/util/Collection
      37: invokeinterface #188,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      42: ifne          49
      45: iconst_1
      46: goto          50
      49: iconst_0
      50: ifeq          73
      53: aload_0
      54: aload_0
      55: getfield      #127                // Field graph:Ljava/util/Map;
      58: aload_1
      59: aload_2
      60: aload_3
      61: ldc           #184                // String start
      63: aconst_null
      64: bipush        32
      66: aconst_null
      67: invokestatic  #192                // Method bfs$default:(Lcom/codelicia/advent2021/Day12;Ljava/util/Map;Lkotlin/jvm/functions/Function1;Ljava/util/Stack;Ljava/util/List;Ljava/lang/String;Ljava/util/HashMap;ILjava/lang/Object;)V
      70: goto          33
      73: aload_3
      74: invokeinterface #195,  1          // InterfaceMethod java/util/List.size:()I
      79: ireturn

  private final void bfs(java.util.Map<com.codelicia.advent2021.Day12$Vertex, ? extends java.util.List<com.codelicia.advent2021.Day12$Vertex>>, kotlin.jvm.functions.Function1<? super java.util.HashMap<java.lang.String, java.lang.Integer>, java.lang.Boolean>, java.util.Stack<com.codelicia.advent2021.Day12$Vertex>, java.util.List<java.lang.String>, java.lang.String, java.util.HashMap<java.lang.String, java.lang.Integer>);
    Code:
       0: aload_3
       1: invokevirtual #206                // Method java/util/Stack.pop:()Ljava/lang/Object;
       4: checkcast     #94                 // class com/codelicia/advent2021/Day12$Vertex
       7: astore        7
       9: aload         7
      11: invokevirtual #210                // Method com/codelicia/advent2021/Day12$Vertex.getLabel:()Ljava/lang/String;
      14: ldc           #212                // String end
      16: invokestatic  #216                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      19: ifeq          33
      22: aload         4
      24: aload         5
      26: invokeinterface #119,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      31: pop
      32: return
      33: aload         6
      35: checkcast     #103                // class java/util/Map
      38: astore        9
      40: aload         7
      42: invokevirtual #210                // Method com/codelicia/advent2021/Day12$Vertex.getLabel:()Ljava/lang/String;
      45: aload         9
      47: swap
      48: invokeinterface #114,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      53: dup
      54: ifnonnull     66
      57: pop
      58: iconst_0
      59: istore        11
      61: iconst_0
      62: invokestatic  #222                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: nop
      66: checkcast     #224                // class java/lang/Number
      69: invokevirtual #227                // Method java/lang/Number.intValue:()I
      72: istore        8
      74: aload         6
      76: checkcast     #103                // class java/util/Map
      79: aload         7
      81: invokevirtual #210                // Method com/codelicia/advent2021/Day12$Vertex.getLabel:()Ljava/lang/String;
      84: iload         8
      86: iconst_1
      87: iadd
      88: invokestatic  #222                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: invokeinterface #230,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      96: pop
      97: aload_1
      98: aload         7
     100: invokeinterface #114,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     105: dup
     106: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     109: checkcast     #66                 // class java/util/List
     112: astore        9
     114: aload         9
     116: invokeinterface #90,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     121: astore        10
     123: aload         10
     125: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     130: ifeq          285
     133: aload         10
     135: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     140: checkcast     #94                 // class com/codelicia/advent2021/Day12$Vertex
     143: astore        11
     145: aload         11
     147: invokevirtual #210                // Method com/codelicia/advent2021/Day12$Vertex.getLabel:()Ljava/lang/String;
     150: ldc           #184                // String start
     152: invokestatic  #216                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     155: ifne          123
     158: aload_2
     159: aload         6
     161: invokeinterface #234,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     166: checkcast     #236                // class java/lang/Boolean
     169: invokevirtual #239                // Method java/lang/Boolean.booleanValue:()Z
     172: istore        12
     174: aload         11
     176: invokevirtual #210                // Method com/codelicia/advent2021/Day12$Vertex.getLabel:()Ljava/lang/String;
     179: getstatic     #245                // Field java/util/Locale.ROOT:Ljava/util/Locale;
     182: invokevirtual #249                // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
     185: dup
     186: ldc           #251                // String toLowerCase(...)
     188: invokestatic  #254                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     191: aload         11
     193: invokevirtual #210                // Method com/codelicia/advent2021/Day12$Vertex.getLabel:()Ljava/lang/String;
     196: invokestatic  #216                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     199: ifeq          226
     202: aload         6
     204: checkcast     #103                // class java/util/Map
     207: aload         11
     209: invokevirtual #210                // Method com/codelicia/advent2021/Day12$Vertex.getLabel:()Ljava/lang/String;
     212: invokeinterface #257,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     217: ifeq          226
     220: iload         12
     222: iconst_1
     223: if_icmpeq     123
     226: aload_3
     227: aload         11
     229: invokevirtual #185                // Method java/util/Stack.add:(Ljava/lang/Object;)Z
     232: pop
     233: aload_0
     234: aload_1
     235: aload_2
     236: aload_3
     237: aload         4
     239: new           #259                // class java/lang/StringBuilder
     242: dup
     243: invokespecial #260                // Method java/lang/StringBuilder."<init>":()V
     246: aload         5
     248: invokevirtual #264                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     251: bipush        44
     253: invokevirtual #267                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     256: aload         11
     258: invokevirtual #210                // Method com/codelicia/advent2021/Day12$Vertex.getLabel:()Ljava/lang/String;
     261: invokevirtual #264                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     264: invokevirtual #270                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     267: new           #272                // class java/util/HashMap
     270: dup
     271: aload         6
     273: checkcast     #103                // class java/util/Map
     276: invokespecial #275                // Method java/util/HashMap."<init>":(Ljava/util/Map;)V
     279: invokespecial #277                // Method bfs:(Ljava/util/Map;Lkotlin/jvm/functions/Function1;Ljava/util/Stack;Ljava/util/List;Ljava/lang/String;Ljava/util/HashMap;)V
     282: goto          123
     285: return

  static void bfs$default(com.codelicia.advent2021.Day12, java.util.Map, kotlin.jvm.functions.Function1, java.util.Stack, java.util.List, java.lang.String, java.util.HashMap, int, java.lang.Object);
    Code:
       0: iload         7
       2: bipush        32
       4: iand
       5: ifeq          17
       8: new           #272                // class java/util/HashMap
      11: dup
      12: invokespecial #289                // Method java/util/HashMap."<init>":()V
      15: astore        6
      17: aload_0
      18: aload_1
      19: aload_2
      20: aload_3
      21: aload         4
      23: aload         5
      25: aload         6
      27: invokespecial #277                // Method bfs:(Ljava/util/Map;Lkotlin/jvm/functions/Function1;Ljava/util/Stack;Ljava/util/List;Ljava/lang/String;Ljava/util/HashMap;)V
      30: return

  private static final boolean part1$lambda$3(java.util.HashMap<java.lang.String, java.lang.Integer>);
    Code:
       0: iconst_1
       1: ireturn

  private static final boolean part2$lambda$6(java.util.HashMap<java.lang.String, java.lang.Integer>);
    Code:
       0: aload_0
       1: checkcast     #103                // class java/util/Map
       4: invokestatic  #293                // Method kotlin/collections/MapsKt.toMap:(Ljava/util/Map;)Ljava/util/Map;
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #295                // class java/util/LinkedHashMap
      15: dup
      16: invokespecial #296                // Method java/util/LinkedHashMap."<init>":()V
      19: checkcast     #103                // class java/util/Map
      22: astore        4
      24: iconst_0
      25: istore        5
      27: aload_3
      28: invokeinterface #300,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      33: invokeinterface #303,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      38: astore        6
      40: aload         6
      42: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          119
      50: aload         6
      52: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: checkcast     #305                // class java/util/Map$Entry
      60: astore        7
      62: aload         7
      64: astore        8
      66: iconst_0
      67: istore        9
      69: aload         8
      71: invokeinterface #308,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      76: checkcast     #224                // class java/lang/Number
      79: invokevirtual #227                // Method java/lang/Number.intValue:()I
      82: iconst_1
      83: if_icmple     90
      86: iconst_1
      87: goto          91
      90: iconst_0
      91: ifeq          40
      94: aload         4
      96: aload         7
      98: invokeinterface #311,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     103: aload         7
     105: invokeinterface #308,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     110: invokeinterface #230,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     115: pop
     116: goto          40
     119: aload         4
     121: nop
     122: astore_1
     123: nop
     124: iconst_0
     125: istore_2
     126: aload_1
     127: astore_3
     128: new           #295                // class java/util/LinkedHashMap
     131: dup
     132: invokespecial #296                // Method java/util/LinkedHashMap."<init>":()V
     135: checkcast     #103                // class java/util/Map
     138: astore        4
     140: iconst_0
     141: istore        5
     143: aload_3
     144: invokeinterface #300,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     149: invokeinterface #303,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     154: astore        6
     156: aload         6
     158: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     163: ifeq          245
     166: aload         6
     168: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     173: checkcast     #305                // class java/util/Map$Entry
     176: astore        7
     178: aload         7
     180: astore        8
     182: iconst_0
     183: istore        9
     185: aload         8
     187: invokeinterface #311,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     192: checkcast     #50                 // class java/lang/String
     195: getstatic     #245                // Field java/util/Locale.ROOT:Ljava/util/Locale;
     198: invokevirtual #249                // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
     201: dup
     202: ldc           #251                // String toLowerCase(...)
     204: invokestatic  #254                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     207: aload         8
     209: invokeinterface #311,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     214: invokestatic  #216                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     217: ifeq          156
     220: aload         4
     222: aload         7
     224: invokeinterface #311,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     229: aload         7
     231: invokeinterface #308,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     236: invokeinterface #230,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     241: pop
     242: goto          156
     245: aload         4
     247: nop
     248: invokeinterface #315,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     253: invokeinterface #188,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     258: ifne          265
     261: iconst_1
     262: goto          266
     265: iconst_0
     266: ireturn
}

Compiled from "Day12.kt"
public final class com.codelicia.advent2021.Day12$Vertex {
  private final java.lang.String label;

  public com.codelicia.advent2021.Day12$Vertex(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String label
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #21                 // Field label:Ljava/lang/String;
      15: return

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

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

  public final com.codelicia.advent2021.Day12$Vertex copy(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String label
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class com/codelicia/advent2021/Day12$Vertex
       9: dup
      10: aload_1
      11: invokespecial #30                 // Method "<init>":(Ljava/lang/String;)V
      14: areturn

  public static com.codelicia.advent2021.Day12$Vertex copy$default(com.codelicia.advent2021.Day12$Vertex, java.lang.String, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #21                 // Field label:Ljava/lang/String;
      10: astore_1
      11: aload_0
      12: aload_1
      13: invokevirtual #34                 // Method copy:(Ljava/lang/String;)Lcom/codelicia/advent2021/Day12$Vertex;
      16: areturn

  public java.lang.String toString();
    Code:
       0: new           #37                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #38                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #40                 // String Vertex(label=
       9: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #21                 // Field label:Ljava/lang/String;
      16: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)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      #21                 // Field label:Ljava/lang/String;
       4: invokevirtual #55                 // Method java/lang/String.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 com/codelicia/advent2021/Day12$Vertex
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class com/codelicia/advent2021/Day12$Vertex
      20: astore_2
      21: aload_0
      22: getfield      #21                 // Field label:Ljava/lang/String;
      25: aload_2
      26: getfield      #21                 // Field label:Ljava/lang/String;
      29: invokestatic  #62                 // 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
}