package org.aoc2021

import java.nio.file.Files
import java.nio.file.Path

object Day14 {
    private const val iterationsPart1 = 10
    private const val iterationsPart2 = 40

    private fun solve(lines: List<String>, iterations: Int): Long {
        val start = lines[0]

        val rules = lines.drop(2).map { it.split(" -> ") }.associate { it[0] to it[1] }

        val startMap = start.windowed(2).groupBy { it }.mapValues { (_, values) -> values.size.toLong() }

        val processed = (1..iterations).fold(startMap) { polymer, _ ->
            doIteration(polymer, rules)
        }

        val countsByChar = processed.entries.flatMap { (pair, count) -> listOf( pair[0] to count, pair[1] to count ) }
            .groupBy(Pair<Char, Long>::first, Pair<Char, Long>::second)
            .mapValues { (_, counts) -> counts.sum() }
            .mapValues { (c, count) ->
                if (c == start.first() || c == start.last()) {
                    if (start.first() == start.last()) {
                        (count + 2) / 2
                    } else {
                        (count + 1) / 2
                    }
                } else {
                    count / 2
                }
            }

        return countsByChar.values.maxOrNull()!! - countsByChar.values.minOrNull()!!
    }

    private fun doIteration(polymer: Map<String, Long>, rules: Map<String, String>): Map<String, Long> {
        val newMap = mutableMapOf<String, Long>()
        polymer.forEach { (pair, count) ->
            val rule = rules[pair]
            if (rule != null) {
                newMap.merge(pair[0] + rule, count) { a, b -> a + b }
                newMap.merge(rule + pair[1], count) { a, b -> a + b }
            } else {
                newMap.merge(pair, count) { a, b -> a + b }
            }
        }
        return newMap.toMap()
    }

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

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

  private static final int iterationsPart1;

  private static final int iterationsPart2;

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

  private final long solve(java.util.List<java.lang.String>, int);
    Code:
       0: aload_1
       1: iconst_0
       2: invokeinterface #19,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #21                 // class java/lang/String
      10: astore_3
      11: aload_1
      12: checkcast     #23                 // class java/lang/Iterable
      15: iconst_2
      16: invokestatic  #29                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      19: checkcast     #23                 // class java/lang/Iterable
      22: astore        5
      24: iconst_0
      25: istore        6
      27: aload         5
      29: astore        7
      31: new           #31                 // class java/util/ArrayList
      34: dup
      35: aload         5
      37: bipush        10
      39: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      42: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #40                 // class java/util/Collection
      48: astore        8
      50: iconst_0
      51: istore        9
      53: aload         7
      55: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      60: astore        10
      62: aload         10
      64: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      69: ifeq          134
      72: aload         10
      74: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      79: astore        11
      81: aload         8
      83: aload         11
      85: checkcast     #21                 // class java/lang/String
      88: astore        12
      90: astore        25
      92: iconst_0
      93: istore        13
      95: aload         12
      97: checkcast     #56                 // class java/lang/CharSequence
     100: iconst_1
     101: anewarray     #21                 // class java/lang/String
     104: astore        14
     106: aload         14
     108: iconst_0
     109: ldc           #58                 // String  ->
     111: aastore
     112: aload         14
     114: iconst_0
     115: iconst_0
     116: bipush        6
     118: aconst_null
     119: invokestatic  #64                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     122: aload         25
     124: swap
     125: invokeinterface #68,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     130: pop
     131: goto          62
     134: aload         8
     136: checkcast     #15                 // class java/util/List
     139: nop
     140: checkcast     #23                 // class java/lang/Iterable
     143: astore        5
     145: nop
     146: iconst_0
     147: istore        6
     149: aload         5
     151: bipush        10
     153: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     156: invokestatic  #74                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     159: bipush        16
     161: invokestatic  #80                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     164: istore        7
     166: aload         5
     168: astore        8
     170: new           #82                 // class java/util/LinkedHashMap
     173: dup
     174: iload         7
     176: invokespecial #83                 // Method java/util/LinkedHashMap."<init>":(I)V
     179: checkcast     #85                 // class java/util/Map
     182: astore        9
     184: iconst_0
     185: istore        10
     187: aload         8
     189: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     194: astore        11
     196: aload         11
     198: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     203: ifeq          271
     206: aload         11
     208: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     213: astore        12
     215: aload         9
     217: astore        13
     219: aload         12
     221: checkcast     #15                 // class java/util/List
     224: astore        14
     226: iconst_0
     227: istore        15
     229: aload         14
     231: iconst_0
     232: invokeinterface #19,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     237: aload         14
     239: iconst_1
     240: invokeinterface #19,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     245: invokestatic  #91                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     248: astore        14
     250: aload         13
     252: aload         14
     254: invokevirtual #96                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     257: aload         14
     259: invokevirtual #99                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     262: invokeinterface #103,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     267: pop
     268: goto          196
     271: aload         9
     273: nop
     274: astore        4
     276: aload_3
     277: checkcast     #56                 // class java/lang/CharSequence
     280: iconst_2
     281: iconst_0
     282: iconst_0
     283: bipush        6
     285: aconst_null
     286: invokestatic  #107                // Method kotlin/text/StringsKt.windowed$default:(Ljava/lang/CharSequence;IIZILjava/lang/Object;)Ljava/util/List;
     289: checkcast     #23                 // class java/lang/Iterable
     292: astore        6
     294: iconst_0
     295: istore        7
     297: aload         6
     299: astore        8
     301: new           #82                 // class java/util/LinkedHashMap
     304: dup
     305: invokespecial #108                // Method java/util/LinkedHashMap."<init>":()V
     308: checkcast     #85                 // class java/util/Map
     311: astore        9
     313: iconst_0
     314: istore        10
     316: aload         8
     318: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     323: astore        11
     325: aload         11
     327: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     332: ifeq          434
     335: aload         11
     337: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     342: astore        12
     344: aload         12
     346: checkcast     #21                 // class java/lang/String
     349: astore        13
     351: iconst_0
     352: istore        14
     354: aload         13
     356: astore        15
     358: aload         9
     360: astore        16
     362: iconst_0
     363: istore        17
     365: aload         16
     367: aload         15
     369: invokeinterface #111,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     374: astore        18
     376: aload         18
     378: ifnonnull     413
     381: iconst_0
     382: istore        19
     384: new           #31                 // class java/util/ArrayList
     387: dup
     388: invokespecial #112                // Method java/util/ArrayList."<init>":()V
     391: checkcast     #15                 // class java/util/List
     394: astore        19
     396: aload         16
     398: aload         15
     400: aload         19
     402: invokeinterface #103,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     407: pop
     408: aload         19
     410: goto          415
     413: aload         18
     415: nop
     416: checkcast     #15                 // class java/util/List
     419: astore        13
     421: aload         13
     423: aload         12
     425: invokeinterface #113,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     430: pop
     431: goto          325
     434: aload         9
     436: nop
     437: astore        6
     439: nop
     440: iconst_0
     441: istore        7
     443: aload         6
     445: astore        8
     447: new           #82                 // class java/util/LinkedHashMap
     450: dup
     451: aload         6
     453: invokeinterface #117,  1          // InterfaceMethod java/util/Map.size:()I
     458: invokestatic  #74                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     461: invokespecial #83                 // Method java/util/LinkedHashMap."<init>":(I)V
     464: checkcast     #85                 // class java/util/Map
     467: astore        9
     469: iconst_0
     470: istore        10
     472: aload         8
     474: invokeinterface #121,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     479: checkcast     #23                 // class java/lang/Iterable
     482: astore        11
     484: iconst_0
     485: istore        12
     487: aload         11
     489: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     494: astore        13
     496: aload         13
     498: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     503: ifeq          593
     506: aload         13
     508: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     513: astore        14
     515: aload         9
     517: aload         14
     519: checkcast     #123                // class java/util/Map$Entry
     522: astore        15
     524: astore        16
     526: iconst_0
     527: istore        17
     529: aload         15
     531: invokeinterface #126,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     536: aload         16
     538: swap
     539: aload         14
     541: checkcast     #123                // class java/util/Map$Entry
     544: astore        18
     546: astore        26
     548: astore        25
     550: iconst_0
     551: istore        19
     553: aload         18
     555: invokeinterface #129,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     560: checkcast     #15                 // class java/util/List
     563: astore        20
     565: aload         20
     567: invokeinterface #130,  1          // InterfaceMethod java/util/List.size:()I
     572: i2l
     573: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     576: astore        27
     578: aload         25
     580: aload         26
     582: aload         27
     584: invokeinterface #103,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     589: pop
     590: goto          496
     593: aload         9
     595: nop
     596: nop
     597: astore        5
     599: new           #138                // class kotlin/ranges/IntRange
     602: dup
     603: iconst_1
     604: iload_2
     605: invokespecial #141                // Method kotlin/ranges/IntRange."<init>":(II)V
     608: checkcast     #23                 // class java/lang/Iterable
     611: astore        7
     613: iconst_0
     614: istore        8
     616: aload         5
     618: astore        9
     620: aload         7
     622: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     627: astore        10
     629: aload         10
     631: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     636: ifeq          671
     639: aload         10
     641: checkcast     #143                // class kotlin/collections/IntIterator
     644: invokevirtual #146                // Method kotlin/collections/IntIterator.nextInt:()I
     647: istore        11
     649: aload         9
     651: astore        13
     653: iconst_0
     654: istore        14
     656: getstatic     #149                // Field INSTANCE:Lorg/aoc2021/Day14;
     659: aload         13
     661: aload         4
     663: invokespecial #153                // Method doIteration:(Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
     666: astore        9
     668: goto          629
     671: aload         9
     673: astore        6
     675: aload         6
     677: invokeinterface #121,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     682: checkcast     #23                 // class java/lang/Iterable
     685: astore        8
     687: iconst_0
     688: istore        9
     690: aload         8
     692: astore        10
     694: new           #31                 // class java/util/ArrayList
     697: dup
     698: invokespecial #112                // Method java/util/ArrayList."<init>":()V
     701: checkcast     #40                 // class java/util/Collection
     704: astore        11
     706: iconst_0
     707: istore        12
     709: aload         10
     711: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     716: astore        13
     718: aload         13
     720: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     725: ifeq          843
     728: aload         13
     730: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     735: astore        14
     737: aload         14
     739: checkcast     #123                // class java/util/Map$Entry
     742: astore        15
     744: iconst_0
     745: istore        16
     747: aload         15
     749: invokeinterface #126,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     754: checkcast     #21                 // class java/lang/String
     757: astore        17
     759: aload         15
     761: invokeinterface #129,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     766: checkcast     #155                // class java/lang/Number
     769: invokevirtual #159                // Method java/lang/Number.longValue:()J
     772: lstore        18
     774: iconst_2
     775: anewarray     #93                 // class kotlin/Pair
     778: astore        20
     780: aload         20
     782: iconst_0
     783: aload         17
     785: iconst_0
     786: invokevirtual #163                // Method java/lang/String.charAt:(I)C
     789: invokestatic  #168                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     792: lload         18
     794: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     797: invokestatic  #91                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     800: aastore
     801: aload         20
     803: iconst_1
     804: aload         17
     806: iconst_1
     807: invokevirtual #163                // Method java/lang/String.charAt:(I)C
     810: invokestatic  #168                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     813: lload         18
     815: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     818: invokestatic  #91                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     821: aastore
     822: aload         20
     824: invokestatic  #172                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     827: checkcast     #23                 // class java/lang/Iterable
     830: astore        15
     832: aload         11
     834: aload         15
     836: invokestatic  #176                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     839: pop
     840: goto          718
     843: aload         11
     845: checkcast     #15                 // class java/util/List
     848: nop
     849: checkcast     #23                 // class java/lang/Iterable
     852: astore        8
     854: nop
     855: iconst_0
     856: istore        9
     858: aload         8
     860: astore        10
     862: new           #82                 // class java/util/LinkedHashMap
     865: dup
     866: invokespecial #108                // Method java/util/LinkedHashMap."<init>":()V
     869: checkcast     #85                 // class java/util/Map
     872: astore        11
     874: iconst_0
     875: istore        12
     877: aload         10
     879: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     884: astore        13
     886: aload         13
     888: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     893: ifeq          1034
     896: aload         13
     898: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     903: astore        14
     905: aload         14
     907: checkcast     #93                 // class kotlin/Pair
     910: astore        15
     912: iconst_0
     913: istore        16
     915: aload         15
     917: invokevirtual #96                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     920: checkcast     #165                // class java/lang/Character
     923: invokevirtual #180                // Method java/lang/Character.charValue:()C
     926: invokestatic  #168                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     929: astore        17
     931: aload         11
     933: astore        18
     935: iconst_0
     936: istore        19
     938: aload         18
     940: aload         17
     942: invokeinterface #111,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     947: astore        20
     949: aload         20
     951: ifnonnull     986
     954: iconst_0
     955: istore        21
     957: new           #31                 // class java/util/ArrayList
     960: dup
     961: invokespecial #112                // Method java/util/ArrayList."<init>":()V
     964: checkcast     #15                 // class java/util/List
     967: astore        21
     969: aload         18
     971: aload         17
     973: aload         21
     975: invokeinterface #103,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     980: pop
     981: aload         21
     983: goto          988
     986: aload         20
     988: nop
     989: checkcast     #15                 // class java/util/List
     992: astore        15
     994: aload         15
     996: aload         14
     998: checkcast     #93                 // class kotlin/Pair
    1001: astore        16
    1003: astore        25
    1005: iconst_0
    1006: istore        22
    1008: aload         16
    1010: invokevirtual #99                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
    1013: checkcast     #155                // class java/lang/Number
    1016: invokevirtual #159                // Method java/lang/Number.longValue:()J
    1019: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1022: aload         25
    1024: swap
    1025: invokeinterface #113,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
    1030: pop
    1031: goto          886
    1034: aload         11
    1036: nop
    1037: astore        8
    1039: nop
    1040: iconst_0
    1041: istore        9
    1043: aload         8
    1045: astore        10
    1047: new           #82                 // class java/util/LinkedHashMap
    1050: dup
    1051: aload         8
    1053: invokeinterface #117,  1          // InterfaceMethod java/util/Map.size:()I
    1058: invokestatic  #74                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
    1061: invokespecial #83                 // Method java/util/LinkedHashMap."<init>":(I)V
    1064: checkcast     #85                 // class java/util/Map
    1067: astore        11
    1069: iconst_0
    1070: istore        12
    1072: aload         10
    1074: invokeinterface #121,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
    1079: checkcast     #23                 // class java/lang/Iterable
    1082: astore        13
    1084: iconst_0
    1085: istore        14
    1087: aload         13
    1089: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
    1094: astore        15
    1096: aload         15
    1098: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1103: ifeq          1193
    1106: aload         15
    1108: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1113: astore        16
    1115: aload         11
    1117: aload         16
    1119: checkcast     #123                // class java/util/Map$Entry
    1122: astore        17
    1124: astore        18
    1126: iconst_0
    1127: istore        19
    1129: aload         17
    1131: invokeinterface #126,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
    1136: aload         18
    1138: swap
    1139: aload         16
    1141: checkcast     #123                // class java/util/Map$Entry
    1144: astore        20
    1146: astore        26
    1148: astore        25
    1150: iconst_0
    1151: istore        21
    1153: aload         20
    1155: invokeinterface #129,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
    1160: checkcast     #15                 // class java/util/List
    1163: astore        22
    1165: aload         22
    1167: checkcast     #23                 // class java/lang/Iterable
    1170: invokestatic  #184                // Method kotlin/collections/CollectionsKt.sumOfLong:(Ljava/lang/Iterable;)J
    1173: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1176: astore        27
    1178: aload         25
    1180: aload         26
    1182: aload         27
    1184: invokeinterface #103,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    1189: pop
    1190: goto          1096
    1193: aload         11
    1195: nop
    1196: nop
    1197: astore        8
    1199: nop
    1200: iconst_0
    1201: istore        9
    1203: aload         8
    1205: astore        10
    1207: new           #82                 // class java/util/LinkedHashMap
    1210: dup
    1211: aload         8
    1213: invokeinterface #117,  1          // InterfaceMethod java/util/Map.size:()I
    1218: invokestatic  #74                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
    1221: invokespecial #83                 // Method java/util/LinkedHashMap."<init>":(I)V
    1224: checkcast     #85                 // class java/util/Map
    1227: astore        11
    1229: iconst_0
    1230: istore        12
    1232: aload         10
    1234: invokeinterface #121,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
    1239: checkcast     #23                 // class java/lang/Iterable
    1242: astore        13
    1244: iconst_0
    1245: istore        14
    1247: aload         13
    1249: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
    1254: astore        15
    1256: aload         15
    1258: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1263: ifeq          1431
    1266: aload         15
    1268: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1273: astore        16
    1275: aload         11
    1277: aload         16
    1279: checkcast     #123                // class java/util/Map$Entry
    1282: astore        17
    1284: astore        18
    1286: iconst_0
    1287: istore        19
    1289: aload         17
    1291: invokeinterface #126,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
    1296: aload         18
    1298: swap
    1299: aload         16
    1301: checkcast     #123                // class java/util/Map$Entry
    1304: astore        20
    1306: astore        26
    1308: astore        25
    1310: iconst_0
    1311: istore        21
    1313: aload         20
    1315: invokeinterface #126,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
    1320: checkcast     #165                // class java/lang/Character
    1323: invokevirtual #180                // Method java/lang/Character.charValue:()C
    1326: istore        22
    1328: aload         20
    1330: invokeinterface #129,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
    1335: checkcast     #155                // class java/lang/Number
    1338: invokevirtual #159                // Method java/lang/Number.longValue:()J
    1341: lstore        23
    1343: iload         22
    1345: aload_3
    1346: checkcast     #56                 // class java/lang/CharSequence
    1349: invokestatic  #188                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
    1352: if_icmpeq     1367
    1355: iload         22
    1357: aload_3
    1358: checkcast     #56                 // class java/lang/CharSequence
    1361: invokestatic  #191                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
    1364: if_icmpne     1405
    1367: aload_3
    1368: checkcast     #56                 // class java/lang/CharSequence
    1371: invokestatic  #188                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
    1374: aload_3
    1375: checkcast     #56                 // class java/lang/CharSequence
    1378: invokestatic  #191                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
    1381: if_icmpne     1395
    1384: lload         23
    1386: iconst_2
    1387: i2l
    1388: ladd
    1389: iconst_2
    1390: i2l
    1391: ldiv
    1392: goto          1410
    1395: lload         23
    1397: lconst_1
    1398: ladd
    1399: iconst_2
    1400: i2l
    1401: ldiv
    1402: goto          1410
    1405: lload         23
    1407: iconst_2
    1408: i2l
    1409: ldiv
    1410: nop
    1411: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1414: astore        27
    1416: aload         25
    1418: aload         26
    1420: aload         27
    1422: invokeinterface #103,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    1427: pop
    1428: goto          1256
    1431: aload         11
    1433: nop
    1434: nop
    1435: astore        7
    1437: aload         7
    1439: invokeinterface #195,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
    1444: checkcast     #23                 // class java/lang/Iterable
    1447: invokestatic  #199                // Method kotlin/collections/CollectionsKt.maxOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
    1450: dup
    1451: invokestatic  #205                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
    1454: checkcast     #155                // class java/lang/Number
    1457: invokevirtual #159                // Method java/lang/Number.longValue:()J
    1460: aload         7
    1462: invokeinterface #195,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
    1467: checkcast     #23                 // class java/lang/Iterable
    1470: invokestatic  #208                // Method kotlin/collections/CollectionsKt.minOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
    1473: dup
    1474: invokestatic  #205                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
    1477: checkcast     #155                // class java/lang/Number
    1480: invokevirtual #159                // Method java/lang/Number.longValue:()J
    1483: lsub
    1484: lreturn

  private final java.util.Map<java.lang.String, java.lang.Long> doIteration(java.util.Map<java.lang.String, java.lang.Long>, java.util.Map<java.lang.String, java.lang.String>);
    Code:
       0: new           #82                 // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #108                // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #85                 // class java/util/Map
      10: astore_3
      11: aload_1
      12: astore        4
      14: iconst_0
      15: istore        5
      17: aload         4
      19: invokeinterface #121,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      24: invokeinterface #288,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      29: astore        6
      31: aload         6
      33: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      38: ifeq          238
      41: aload         6
      43: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      48: checkcast     #123                // class java/util/Map$Entry
      51: astore        7
      53: aload         7
      55: astore        8
      57: iconst_0
      58: istore        9
      60: aload         8
      62: invokeinterface #126,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      67: checkcast     #21                 // class java/lang/String
      70: astore        10
      72: aload         8
      74: invokeinterface #129,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      79: checkcast     #155                // class java/lang/Number
      82: invokevirtual #159                // Method java/lang/Number.longValue:()J
      85: lstore        11
      87: aload_2
      88: aload         10
      90: invokeinterface #111,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      95: checkcast     #21                 // class java/lang/String
      98: astore        13
     100: aload         13
     102: ifnull        206
     105: aload_3
     106: aload         10
     108: iconst_0
     109: invokevirtual #163                // Method java/lang/String.charAt:(I)C
     112: istore        14
     114: new           #290                // class java/lang/StringBuilder
     117: dup
     118: invokespecial #291                // Method java/lang/StringBuilder."<init>":()V
     121: iload         14
     123: invokevirtual #295                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     126: aload         13
     128: invokevirtual #298                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     131: invokevirtual #302                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     134: lload         11
     136: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     139: invokedynamic #320,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
     144: invokedynamic #331,  0            // InvokeDynamic #1:apply:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiFunction;
     149: invokeinterface #335,  4          // InterfaceMethod java/util/Map.merge:(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;
     154: pop
     155: aload_3
     156: new           #290                // class java/lang/StringBuilder
     159: dup
     160: invokespecial #291                // Method java/lang/StringBuilder."<init>":()V
     163: aload         13
     165: invokevirtual #298                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     168: aload         10
     170: iconst_1
     171: invokevirtual #163                // Method java/lang/String.charAt:(I)C
     174: invokevirtual #295                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     177: invokevirtual #302                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     180: lload         11
     182: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     185: invokedynamic #340,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function2;
     190: invokedynamic #345,  0            // InvokeDynamic #3:apply:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiFunction;
     195: invokeinterface #335,  4          // InterfaceMethod java/util/Map.merge:(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;
     200: checkcast     #132                // class java/lang/Long
     203: goto          232
     206: aload_3
     207: aload         10
     209: lload         11
     211: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     214: invokedynamic #350,  0            // InvokeDynamic #4:invoke:()Lkotlin/jvm/functions/Function2;
     219: invokedynamic #355,  0            // InvokeDynamic #5:apply:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiFunction;
     224: invokeinterface #335,  4          // InterfaceMethod java/util/Map.merge:(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;
     229: checkcast     #132                // class java/lang/Long
     232: pop
     233: nop
     234: nop
     235: goto          31
     238: nop
     239: aload_3
     240: invokestatic  #359                // Method kotlin/collections/MapsKt.toMap:(Ljava/util/Map;)Ljava/util/Map;
     243: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc_w         #370                // String args
       4: invokestatic  #374                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: ldc_w         #376                // String input14.txt
      10: iconst_0
      11: anewarray     #21                 // class java/lang/String
      14: invokestatic  #382                // InterfaceMethod java/nio/file/Path.of:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
      17: getstatic     #388                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      20: invokestatic  #394                // Method java/nio/file/Files.readAllLines:(Ljava/nio/file/Path;Ljava/nio/charset/Charset;)Ljava/util/List;
      23: astore_1
      24: getstatic     #149                // Field INSTANCE:Lorg/aoc2021/Day14;
      27: aload_1
      28: invokestatic  #205                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      31: aload_1
      32: bipush        10
      34: invokespecial #396                // Method solve:(Ljava/util/List;I)J
      37: lstore_2
      38: getstatic     #402                // Field java/lang/System.out:Ljava/io/PrintStream;
      41: lload_2
      42: invokevirtual #408                // Method java/io/PrintStream.println:(J)V
      45: getstatic     #149                // Field INSTANCE:Lorg/aoc2021/Day14;
      48: aload_1
      49: bipush        40
      51: invokespecial #396                // Method solve:(Ljava/util/List;I)J
      54: lstore        4
      56: getstatic     #402                // Field java/lang/System.out:Ljava/io/PrintStream;
      59: lload         4
      61: invokevirtual #408                // Method java/io/PrintStream.println:(J)V
      64: return

  private static final java.lang.Long doIteration$lambda$15$lambda$9(java.lang.Long, java.lang.Long);
    Code:
       0: aload_0
       1: ldc_w         #413                // String a
       4: invokestatic  #374                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: ldc_w         #415                // String b
      11: invokestatic  #374                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_0
      15: invokevirtual #416                // Method java/lang/Long.longValue:()J
      18: aload_1
      19: invokevirtual #416                // Method java/lang/Long.longValue:()J
      22: ladd
      23: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      26: areturn

  private static final java.lang.Long doIteration$lambda$15$lambda$10(kotlin.jvm.functions.Function2, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokeinterface #421,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
       8: checkcast     #132                // class java/lang/Long
      11: areturn

  private static final java.lang.Long doIteration$lambda$15$lambda$11(java.lang.Long, java.lang.Long);
    Code:
       0: aload_0
       1: ldc_w         #413                // String a
       4: invokestatic  #374                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: ldc_w         #415                // String b
      11: invokestatic  #374                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_0
      15: invokevirtual #416                // Method java/lang/Long.longValue:()J
      18: aload_1
      19: invokevirtual #416                // Method java/lang/Long.longValue:()J
      22: ladd
      23: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      26: areturn

  private static final java.lang.Long doIteration$lambda$15$lambda$12(kotlin.jvm.functions.Function2, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokeinterface #421,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
       8: checkcast     #132                // class java/lang/Long
      11: areturn

  private static final java.lang.Long doIteration$lambda$15$lambda$13(java.lang.Long, java.lang.Long);
    Code:
       0: aload_0
       1: ldc_w         #413                // String a
       4: invokestatic  #374                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: ldc_w         #415                // String b
      11: invokestatic  #374                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_0
      15: invokevirtual #416                // Method java/lang/Long.longValue:()J
      18: aload_1
      19: invokevirtual #416                // Method java/lang/Long.longValue:()J
      22: ladd
      23: invokestatic  #136                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      26: areturn

  private static final java.lang.Long doIteration$lambda$15$lambda$14(kotlin.jvm.functions.Function2, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokeinterface #421,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
       8: checkcast     #132                // class java/lang/Long
      11: areturn

  static {};
    Code:
       0: new           #2                  // class org/aoc2021/Day14
       3: dup
       4: invokespecial #426                // Method "<init>":()V
       7: putstatic     #149                // Field INSTANCE:Lorg/aoc2021/Day14;
      10: return
}


package org.aoc2021

import java.nio.file.Files
import java.nio.file.Path

class Board(boardLines: List<String>) {
    companion object {
        const val boardSize = 5
    }

    private val board: List<List<Int>>
    private val chosenNumbers: Array<Array<Boolean>> = Array(boardSize) { Array(boardSize) { false } }
    private val numberToPosition: Map<Int, Pair<Int, Int>>

    init {
        board = boardLines.drop(1).map { line ->
            line.split(Regex(" +")).filter(String::isNotBlank).map(String::toInt)
        }
        numberToPosition = board.flatMapIndexed { i, row ->
            row.mapIndexed { j, number -> number to (i to j) }
        }.toMap()
    }

    fun processNumber(number: Int) {
        numberToPosition[number]?.let { (i, j) ->
            chosenNumbers[i][j] = true
        }
    }

    private fun checkRows(): Boolean {
        return chosenNumbers.any { row ->
            row.all { it }
        }
    }

    private fun checkColumns(): Boolean {
        return (0 until boardSize).any { j ->
            (0 until boardSize).all { i ->
                chosenNumbers[i][j]
            }
        }
    }

    fun checkWin() = checkRows() || checkColumns()

    fun sumUnmarkedNumbers(): Int {
        return board.mapIndexed { i, row ->
            row.filterIndexed { j, _ -> !chosenNumbers[i][j] }.sum()
        }.sum()
    }
}

object Day4 {
    private fun solvePart1(filename: String): Int {
        val lines = Files.readAllLines(Path.of(filename), Charsets.UTF_8)

        val chosenNumbers = lines[0].split(",").map(String::toInt)
        val boards = parseBoards(lines)

        chosenNumbers.forEach { chosenNumber ->
            boards.forEach { board ->
                board.processNumber(chosenNumber)
                if (board.checkWin()) {
                    return chosenNumber * board.sumUnmarkedNumbers()
                }
            }
        }

        throw IllegalArgumentException("no winning boards found")
    }

    private fun solvePart2(filename: String): Int {
        val lines = Files.readAllLines(Path.of(filename), Charsets.UTF_8)

        val chosenNumbers = lines[0].split(",").map(String::toInt)
        val boards = parseBoards(lines)

        return findSolution(chosenNumbers, boards)
    }

    private fun parseBoards(lines: List<String>): List<Board> {
        return lines.drop(1).chunked(Board.boardSize + 1, ::Board)
    }

    private tailrec fun findSolution(chosenNumbers: List<Int>, boards: List<Board>): Int {
        val chosenNumber = chosenNumbers[0]

        boards.forEach { board ->
            board.processNumber(chosenNumber)
        }

        if (boards.size == 1 && boards[0].checkWin()) {
            return chosenNumber * boards[0].sumUnmarkedNumbers()
        }

        val remainingBoards = boards.filterNot(Board::checkWin)
        return findSolution(chosenNumbers.drop(1), remainingBoards)
    }

    @JvmStatic
    fun main(args: Array<String>) {
        val filename = "input4.txt"
        val solution1 = solvePart1(filename)
        println(solution1)
        val solution2 = solvePart2(filename)
        println(solution2)
    }
}

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

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

  private final int solvePart1(java.lang.String);
    Code:
       0: aload_1
       1: iconst_0
       2: anewarray     #14                 // class java/lang/String
       5: invokestatic  #20                 // InterfaceMethod java/nio/file/Path.of:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
       8: getstatic     #26                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      11: invokestatic  #32                 // Method java/nio/file/Files.readAllLines:(Ljava/nio/file/Path;Ljava/nio/charset/Charset;)Ljava/util/List;
      14: astore_2
      15: aload_2
      16: iconst_0
      17: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      22: dup
      23: ldc           #40                 // String get(...)
      25: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      28: checkcast     #48                 // class java/lang/CharSequence
      31: iconst_1
      32: anewarray     #14                 // class java/lang/String
      35: astore        4
      37: aload         4
      39: iconst_0
      40: ldc           #50                 // String ,
      42: aastore
      43: aload         4
      45: iconst_0
      46: iconst_0
      47: bipush        6
      49: aconst_null
      50: invokestatic  #56                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      53: checkcast     #58                 // class java/lang/Iterable
      56: astore        4
      58: iconst_0
      59: istore        5
      61: aload         4
      63: astore        6
      65: new           #60                 // class java/util/ArrayList
      68: dup
      69: aload         4
      71: bipush        10
      73: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      76: invokespecial #69                 // Method java/util/ArrayList."<init>":(I)V
      79: checkcast     #71                 // class java/util/Collection
      82: astore        7
      84: iconst_0
      85: istore        8
      87: aload         6
      89: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      94: astore        9
      96: aload         9
      98: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     103: ifeq          150
     106: aload         9
     108: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     113: astore        10
     115: aload         7
     117: aload         10
     119: checkcast     #14                 // class java/lang/String
     122: astore        11
     124: astore        17
     126: iconst_0
     127: istore        12
     129: aload         11
     131: invokestatic  #90                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     134: nop
     135: invokestatic  #94                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: aload         17
     140: swap
     141: invokeinterface #98,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     146: pop
     147: goto          96
     150: aload         7
     152: checkcast     #34                 // class java/util/List
     155: nop
     156: astore_3
     157: aload_0
     158: aload_2
     159: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     162: aload_2
     163: invokespecial #106                // Method parseBoards:(Ljava/util/List;)Ljava/util/List;
     166: astore        4
     168: aload_3
     169: checkcast     #58                 // class java/lang/Iterable
     172: astore        5
     174: iconst_0
     175: istore        6
     177: aload         5
     179: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     184: astore        7
     186: aload         7
     188: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     193: ifeq          301
     196: aload         7
     198: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     203: astore        8
     205: aload         8
     207: checkcast     #108                // class java/lang/Number
     210: invokevirtual #112                // Method java/lang/Number.intValue:()I
     213: istore        9
     215: iconst_0
     216: istore        10
     218: aload         4
     220: checkcast     #58                 // class java/lang/Iterable
     223: astore        11
     225: iconst_0
     226: istore        12
     228: aload         11
     230: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     235: astore        13
     237: aload         13
     239: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     244: ifeq          295
     247: aload         13
     249: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     254: astore        14
     256: aload         14
     258: checkcast     #114                // class org/aoc2021/Board
     261: astore        15
     263: iconst_0
     264: istore        16
     266: aload         15
     268: iload         9
     270: invokevirtual #117                // Method org/aoc2021/Board.processNumber:(I)V
     273: aload         15
     275: invokevirtual #120                // Method org/aoc2021/Board.checkWin:()Z
     278: ifeq          290
     281: iload         9
     283: aload         15
     285: invokevirtual #123                // Method org/aoc2021/Board.sumUnmarkedNumbers:()I
     288: imul
     289: ireturn
     290: nop
     291: nop
     292: goto          237
     295: nop
     296: nop
     297: nop
     298: goto          186
     301: nop
     302: new           #125                // class java/lang/IllegalArgumentException
     305: dup
     306: ldc           #127                // String no winning boards found
     308: invokespecial #130                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     311: athrow

  private final int solvePart2(java.lang.String);
    Code:
       0: aload_1
       1: iconst_0
       2: anewarray     #14                 // class java/lang/String
       5: invokestatic  #20                 // InterfaceMethod java/nio/file/Path.of:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
       8: getstatic     #26                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      11: invokestatic  #32                 // Method java/nio/file/Files.readAllLines:(Ljava/nio/file/Path;Ljava/nio/charset/Charset;)Ljava/util/List;
      14: astore_2
      15: aload_2
      16: iconst_0
      17: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      22: dup
      23: ldc           #40                 // String get(...)
      25: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      28: checkcast     #48                 // class java/lang/CharSequence
      31: iconst_1
      32: anewarray     #14                 // class java/lang/String
      35: astore        4
      37: aload         4
      39: iconst_0
      40: ldc           #50                 // String ,
      42: aastore
      43: aload         4
      45: iconst_0
      46: iconst_0
      47: bipush        6
      49: aconst_null
      50: invokestatic  #56                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      53: checkcast     #58                 // class java/lang/Iterable
      56: astore        4
      58: iconst_0
      59: istore        5
      61: aload         4
      63: astore        6
      65: new           #60                 // class java/util/ArrayList
      68: dup
      69: aload         4
      71: bipush        10
      73: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      76: invokespecial #69                 // Method java/util/ArrayList."<init>":(I)V
      79: checkcast     #71                 // class java/util/Collection
      82: astore        7
      84: iconst_0
      85: istore        8
      87: aload         6
      89: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      94: astore        9
      96: aload         9
      98: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     103: ifeq          150
     106: aload         9
     108: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     113: astore        10
     115: aload         7
     117: aload         10
     119: checkcast     #14                 // class java/lang/String
     122: astore        11
     124: astore        13
     126: iconst_0
     127: istore        12
     129: aload         11
     131: invokestatic  #90                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     134: nop
     135: invokestatic  #94                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: aload         13
     140: swap
     141: invokeinterface #98,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     146: pop
     147: goto          96
     150: aload         7
     152: checkcast     #34                 // class java/util/List
     155: nop
     156: astore_3
     157: aload_0
     158: aload_2
     159: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     162: aload_2
     163: invokespecial #106                // Method parseBoards:(Ljava/util/List;)Ljava/util/List;
     166: astore        4
     168: aload_0
     169: aload_3
     170: aload         4
     172: invokespecial #161                // Method findSolution:(Ljava/util/List;Ljava/util/List;)I
     175: ireturn

  private final java.util.List<org.aoc2021.Board> parseBoards(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #58                 // class java/lang/Iterable
       4: iconst_1
       5: invokestatic  #167                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
       8: checkcast     #58                 // class java/lang/Iterable
      11: bipush        6
      13: getstatic     #173                // Field org/aoc2021/Day4$parseBoards$1.INSTANCE:Lorg/aoc2021/Day4$parseBoards$1;
      16: checkcast     #175                // class kotlin/jvm/functions/Function1
      19: invokestatic  #179                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;ILkotlin/jvm/functions/Function1;)Ljava/util/List;
      22: areturn

  private final int findSolution(java.util.List<java.lang.Integer>, java.util.List<org.aoc2021.Board>);
    Code:
       0: aload_0
       1: astore_3
       2: aload_1
       3: iconst_0
       4: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       9: checkcast     #108                // class java/lang/Number
      12: invokevirtual #112                // Method java/lang/Number.intValue:()I
      15: istore        4
      17: aload_2
      18: checkcast     #58                 // class java/lang/Iterable
      21: astore        5
      23: iconst_0
      24: istore        6
      26: aload         5
      28: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        7
      35: aload         7
      37: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          76
      45: aload         7
      47: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        8
      54: aload         8
      56: checkcast     #114                // class org/aoc2021/Board
      59: astore        9
      61: iconst_0
      62: istore        10
      64: aload         9
      66: iload         4
      68: invokevirtual #117                // Method org/aoc2021/Board.processNumber:(I)V
      71: nop
      72: nop
      73: goto          35
      76: nop
      77: aload_2
      78: invokeinterface #183,  1          // InterfaceMethod java/util/List.size:()I
      83: iconst_1
      84: if_icmpne     120
      87: aload_2
      88: iconst_0
      89: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      94: checkcast     #114                // class org/aoc2021/Board
      97: invokevirtual #120                // Method org/aoc2021/Board.checkWin:()Z
     100: ifeq          120
     103: iload         4
     105: aload_2
     106: iconst_0
     107: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     112: checkcast     #114                // class org/aoc2021/Board
     115: invokevirtual #123                // Method org/aoc2021/Board.sumUnmarkedNumbers:()I
     118: imul
     119: ireturn
     120: aload_2
     121: checkcast     #58                 // class java/lang/Iterable
     124: astore        6
     126: iconst_0
     127: istore        7
     129: aload         6
     131: astore        8
     133: new           #60                 // class java/util/ArrayList
     136: dup
     137: invokespecial #184                // Method java/util/ArrayList."<init>":()V
     140: checkcast     #71                 // class java/util/Collection
     143: astore        9
     145: iconst_0
     146: istore        10
     148: aload         8
     150: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     155: astore        11
     157: aload         11
     159: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     164: ifeq          207
     167: aload         11
     169: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     174: astore        12
     176: aload         12
     178: checkcast     #114                // class org/aoc2021/Board
     181: astore        13
     183: iconst_0
     184: istore        14
     186: aload         13
     188: invokevirtual #120                // Method org/aoc2021/Board.checkWin:()Z
     191: ifne          157
     194: aload         9
     196: aload         12
     198: invokeinterface #98,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     203: pop
     204: goto          157
     207: aload         9
     209: checkcast     #34                 // class java/util/List
     212: nop
     213: astore        5
     215: aload_3
     216: astore        6
     218: aload_1
     219: checkcast     #58                 // class java/lang/Iterable
     222: iconst_1
     223: invokestatic  #167                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     226: astore        7
     228: aload         6
     230: astore_3
     231: aload         7
     233: astore_1
     234: aload         5
     236: astore_2
     237: goto          2

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #198                // String args
       3: invokestatic  #201                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #203                // String input4.txt
       8: astore_1
       9: getstatic     #205                // Field INSTANCE:Lorg/aoc2021/Day4;
      12: aload_1
      13: invokespecial #207                // Method solvePart1:(Ljava/lang/String;)I
      16: istore_2
      17: getstatic     #213                // Field java/lang/System.out:Ljava/io/PrintStream;
      20: iload_2
      21: invokevirtual #218                // Method java/io/PrintStream.println:(I)V
      24: getstatic     #205                // Field INSTANCE:Lorg/aoc2021/Day4;
      27: aload_1
      28: invokespecial #220                // Method solvePart2:(Ljava/lang/String;)I
      31: istore_3
      32: getstatic     #213                // Field java/lang/System.out:Ljava/io/PrintStream;
      35: iload_3
      36: invokevirtual #218                // Method java/io/PrintStream.println:(I)V
      39: return

  static {};
    Code:
       0: new           #2                  // class org/aoc2021/Day4
       3: dup
       4: invokespecial #225                // Method "<init>":()V
       7: putstatic     #205                // Field INSTANCE:Lorg/aoc2021/Day4;
      10: return
}

Compiled from "Day4.kt"
final class org.aoc2021.Day4$parseBoards$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.util.List<? extends java.lang.String>, org.aoc2021.Board> {
  public static final org.aoc2021.Day4$parseBoards$1 INSTANCE;

  org.aoc2021.Day4$parseBoards$1();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class org/aoc2021/Board
       4: ldc           #12                 // String <init>
       6: ldc           #14                 // String <init>(Ljava/util/List;)V
       8: iconst_0
       9: invokespecial #17                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final org.aoc2021.Board invoke(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #11                 // class org/aoc2021/Board
       9: dup
      10: aload_1
      11: invokespecial #33                 // Method org/aoc2021/Board."<init>":(Ljava/util/List;)V
      14: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #37                 // class java/util/List
       5: invokevirtual #39                 // Method invoke:(Ljava/util/List;)Lorg/aoc2021/Board;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class org/aoc2021/Day4$parseBoards$1
       3: dup
       4: invokespecial #44                 // Method "<init>":()V
       7: putstatic     #47                 // Field INSTANCE:Lorg/aoc2021/Day4$parseBoards$1;
      10: return
}


package org.aoc2021

import java.nio.file.Files
import java.nio.file.Path

object Day10 {
    private val values = mapOf(
        ')' to 3,
        ']' to 57,
        '}' to 1197,
        '>' to 25137,
    )

    private fun solvePart1(lines: List<String>): Int {
        return lines.sumOf { line ->
            doLine(line)
        }
    }

    private fun solvePart2(lines: List<String>): Long {
        val scores = lines.filter { doLine(it) == 0 }
            .map { line ->
                solveIncompleteLine(line)
            }
            .sorted()
        return scores[scores.size / 2]
    }

    private fun doLine(line: String): Int {
        val chars = mutableListOf<Char>()

        for (c in line) {
            if (c in setOf('(', '[', '{', '<')) {
                chars.add(c)
            } else if (chars.isEmpty()) {
                return values[c]!!
            } else {
                if (
                    (c == ')' && chars.last() != '(') ||
                    (c == ']' && chars.last() != '[') ||
                    (c == '}' && chars.last() != '{') ||
                    (c == '>' && chars.last() != '<')
                ) {
                    return values[c]!!
                }
                chars.removeLast()
            }
        }

        return 0
    }

    private fun solveIncompleteLine(line: String): Long {
        val chars = mutableListOf<Char>()

        for (c in line) {
            if (c in setOf('(', '[', '{', '<')) {
                chars.add(c)
            } else {
                chars.removeLast()
            }
        }

        return chars.reversed().fold(0L) { p, c ->
            5 * p + when (c) {
                '(' -> 1
                '[' -> 2
                '{' -> 3
                '<' -> 4
                else -> throw IllegalArgumentException("$c")
            }
        }
    }

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

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

  private static final java.util.Map<java.lang.Character, java.lang.Integer> values;

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

  private final int solvePart1(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #15                 // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: invokeinterface #19,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      13: astore        4
      15: aload         4
      17: invokeinterface #25,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      22: ifeq          66
      25: aload         4
      27: invokeinterface #29,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: astore        5
      34: iload_3
      35: aload         5
      37: checkcast     #31                 // class java/lang/String
      40: astore        6
      42: istore        8
      44: iconst_0
      45: istore        7
      47: getstatic     #34                 // Field INSTANCE:Lorg/aoc2021/Day10;
      50: aload         6
      52: invokespecial #38                 // Method doLine:(Ljava/lang/String;)I
      55: istore        9
      57: iload         8
      59: iload         9
      61: iadd
      62: istore_3
      63: goto          15
      66: iload_3
      67: ireturn

  private final long solvePart2(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #15                 // class java/lang/Iterable
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: astore        5
      11: new           #49                 // class java/util/ArrayList
      14: dup
      15: invokespecial #50                 // Method java/util/ArrayList."<init>":()V
      18: checkcast     #52                 // class java/util/Collection
      21: astore        6
      23: iconst_0
      24: istore        7
      26: aload         5
      28: invokeinterface #19,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        8
      35: aload         8
      37: invokeinterface #25,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          96
      45: aload         8
      47: invokeinterface #29,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        9
      54: aload         9
      56: checkcast     #31                 // class java/lang/String
      59: astore        10
      61: iconst_0
      62: istore        11
      64: getstatic     #34                 // Field INSTANCE:Lorg/aoc2021/Day10;
      67: aload         10
      69: invokespecial #38                 // Method doLine:(Ljava/lang/String;)I
      72: ifne          79
      75: iconst_1
      76: goto          80
      79: iconst_0
      80: ifeq          35
      83: aload         6
      85: aload         9
      87: invokeinterface #56,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      92: pop
      93: goto          35
      96: aload         6
      98: checkcast     #58                 // class java/util/List
     101: nop
     102: checkcast     #15                 // class java/lang/Iterable
     105: astore_3
     106: nop
     107: iconst_0
     108: istore        4
     110: aload_3
     111: astore        5
     113: new           #49                 // class java/util/ArrayList
     116: dup
     117: aload_3
     118: bipush        10
     120: invokestatic  #64                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     123: invokespecial #67                 // Method java/util/ArrayList."<init>":(I)V
     126: checkcast     #52                 // class java/util/Collection
     129: astore        6
     131: iconst_0
     132: istore        7
     134: aload         5
     136: invokeinterface #19,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     141: astore        8
     143: aload         8
     145: invokeinterface #25,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     150: ifeq          199
     153: aload         8
     155: invokeinterface #29,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     160: astore        9
     162: aload         6
     164: aload         9
     166: checkcast     #31                 // class java/lang/String
     169: astore        10
     171: astore        12
     173: iconst_0
     174: istore        11
     176: getstatic     #34                 // Field INSTANCE:Lorg/aoc2021/Day10;
     179: aload         10
     181: invokespecial #71                 // Method solveIncompleteLine:(Ljava/lang/String;)J
     184: invokestatic  #77                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     187: aload         12
     189: swap
     190: invokeinterface #56,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     195: pop
     196: goto          143
     199: aload         6
     201: checkcast     #58                 // class java/util/List
     204: nop
     205: checkcast     #15                 // class java/lang/Iterable
     208: invokestatic  #81                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     211: astore_2
     212: aload_2
     213: aload_2
     214: invokeinterface #85,  1           // InterfaceMethod java/util/List.size:()I
     219: iconst_2
     220: idiv
     221: invokeinterface #89,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     226: checkcast     #91                 // class java/lang/Number
     229: invokevirtual #95                 // Method java/lang/Number.longValue:()J
     232: lreturn

  private final int doLine(java.lang.String);
    Code:
       0: new           #49                 // class java/util/ArrayList
       3: dup
       4: invokespecial #50                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #58                 // class java/util/List
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_1
      14: invokevirtual #116                // Method java/lang/String.length:()I
      17: istore        4
      19: iload_3
      20: iload         4
      22: if_icmpge     271
      25: aload_1
      26: iload_3
      27: invokevirtual #120                // Method java/lang/String.charAt:(I)C
      30: istore        5
      32: iconst_4
      33: anewarray     #122                // class java/lang/Character
      36: astore        6
      38: aload         6
      40: iconst_0
      41: bipush        40
      43: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      46: aastore
      47: aload         6
      49: iconst_1
      50: bipush        91
      52: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      55: aastore
      56: aload         6
      58: iconst_2
      59: bipush        123
      61: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      64: aastore
      65: aload         6
      67: iconst_3
      68: bipush        60
      70: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      73: aastore
      74: aload         6
      76: invokestatic  #131                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      79: iload         5
      81: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      84: invokeinterface #136,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      89: ifeq          107
      92: aload_2
      93: iload         5
      95: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      98: invokeinterface #137,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     103: pop
     104: goto          265
     107: aload_2
     108: invokeinterface #140,  1          // InterfaceMethod java/util/List.isEmpty:()Z
     113: ifeq          140
     116: getstatic     #144                // Field values:Ljava/util/Map;
     119: iload         5
     121: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     124: invokeinterface #149,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     129: dup
     130: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     133: checkcast     #91                 // class java/lang/Number
     136: invokevirtual #158                // Method java/lang/Number.intValue:()I
     139: ireturn
     140: iload         5
     142: bipush        41
     144: if_icmpne     162
     147: aload_2
     148: invokestatic  #162                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     151: checkcast     #122                // class java/lang/Character
     154: invokevirtual #166                // Method java/lang/Character.charValue:()C
     157: bipush        40
     159: if_icmpne     228
     162: iload         5
     164: bipush        93
     166: if_icmpne     184
     169: aload_2
     170: invokestatic  #162                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     173: checkcast     #122                // class java/lang/Character
     176: invokevirtual #166                // Method java/lang/Character.charValue:()C
     179: bipush        91
     181: if_icmpne     228
     184: iload         5
     186: bipush        125
     188: if_icmpne     206
     191: aload_2
     192: invokestatic  #162                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     195: checkcast     #122                // class java/lang/Character
     198: invokevirtual #166                // Method java/lang/Character.charValue:()C
     201: bipush        123
     203: if_icmpne     228
     206: iload         5
     208: bipush        62
     210: if_icmpne     252
     213: aload_2
     214: invokestatic  #162                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     217: checkcast     #122                // class java/lang/Character
     220: invokevirtual #166                // Method java/lang/Character.charValue:()C
     223: bipush        60
     225: if_icmpeq     252
     228: getstatic     #144                // Field values:Ljava/util/Map;
     231: iload         5
     233: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     236: invokeinterface #149,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     241: dup
     242: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     245: checkcast     #91                 // class java/lang/Number
     248: invokevirtual #158                // Method java/lang/Number.intValue:()I
     251: ireturn
     252: aload_2
     253: invokeinterface #169,  1          // InterfaceMethod java/util/List.removeLast:()Ljava/lang/Object;
     258: astore        6
     260: aload         6
     262: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     265: iinc          3, 1
     268: goto          19
     271: iconst_0
     272: ireturn

  private final long solveIncompleteLine(java.lang.String);
    Code:
       0: new           #49                 // class java/util/ArrayList
       3: dup
       4: invokespecial #50                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #58                 // class java/util/List
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_1
      14: invokevirtual #116                // Method java/lang/String.length:()I
      17: istore        4
      19: iload_3
      20: iload         4
      22: if_icmpge     126
      25: aload_1
      26: iload_3
      27: invokevirtual #120                // Method java/lang/String.charAt:(I)C
      30: istore        6
      32: iconst_4
      33: anewarray     #122                // class java/lang/Character
      36: astore        7
      38: aload         7
      40: iconst_0
      41: bipush        40
      43: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      46: aastore
      47: aload         7
      49: iconst_1
      50: bipush        91
      52: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      55: aastore
      56: aload         7
      58: iconst_2
      59: bipush        123
      61: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      64: aastore
      65: aload         7
      67: iconst_3
      68: bipush        60
      70: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      73: aastore
      74: aload         7
      76: invokestatic  #131                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      79: iload         6
      81: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      84: invokeinterface #136,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      89: ifeq          107
      92: aload_2
      93: iload         6
      95: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      98: invokeinterface #137,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     103: pop
     104: goto          120
     107: aload_2
     108: invokeinterface #169,  1          // InterfaceMethod java/util/List.removeLast:()Ljava/lang/Object;
     113: astore        7
     115: aload         7
     117: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     120: iinc          3, 1
     123: goto          19
     126: aload_2
     127: checkcast     #15                 // class java/lang/Iterable
     130: invokestatic  #177                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     133: checkcast     #15                 // class java/lang/Iterable
     136: astore_3
     137: lconst_0
     138: lstore        4
     140: iconst_0
     141: istore        6
     143: lload         4
     145: lstore        7
     147: aload_3
     148: invokeinterface #19,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     153: astore        9
     155: aload         9
     157: invokeinterface #25,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     162: ifeq          277
     165: aload         9
     167: invokeinterface #29,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     172: astore        10
     174: lload         7
     176: aload         10
     178: checkcast     #122                // class java/lang/Character
     181: invokevirtual #166                // Method java/lang/Character.charValue:()C
     184: istore        11
     186: lstore        12
     188: iconst_0
     189: istore        14
     191: iconst_5
     192: i2l
     193: lload         12
     195: lmul
     196: iload         11
     198: lookupswitch  { // 4
                    40: 240
                    60: 252
                    91: 244
                   123: 248
               default: 256
          }
     240: iconst_1
     241: goto          269
     244: iconst_2
     245: goto          269
     248: iconst_3
     249: goto          269
     252: iconst_4
     253: goto          269
     256: new           #179                // class java/lang/IllegalArgumentException
     259: dup
     260: iload         11
     262: invokestatic  #182                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     265: invokespecial #185                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     268: athrow
     269: i2l
     270: ladd
     271: nop
     272: lstore        7
     274: goto          155
     277: lload         7
     279: lreturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #199                // String args
       3: invokestatic  #203                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #205                // String input10.txt
       8: iconst_0
       9: anewarray     #31                 // class java/lang/String
      12: invokestatic  #211                // InterfaceMethod java/nio/file/Path.of:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
      15: getstatic     #217                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      18: invokestatic  #223                // Method java/nio/file/Files.readAllLines:(Ljava/nio/file/Path;Ljava/nio/charset/Charset;)Ljava/util/List;
      21: astore_1
      22: getstatic     #34                 // Field INSTANCE:Lorg/aoc2021/Day10;
      25: aload_1
      26: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      29: aload_1
      30: invokespecial #225                // Method solvePart1:(Ljava/util/List;)I
      33: istore_2
      34: getstatic     #231                // Field java/lang/System.out:Ljava/io/PrintStream;
      37: iload_2
      38: invokevirtual #236                // Method java/io/PrintStream.println:(I)V
      41: getstatic     #34                 // Field INSTANCE:Lorg/aoc2021/Day10;
      44: aload_1
      45: invokespecial #238                // Method solvePart2:(Ljava/util/List;)J
      48: lstore_3
      49: getstatic     #231                // Field java/lang/System.out:Ljava/io/PrintStream;
      52: lload_3
      53: invokevirtual #241                // Method java/io/PrintStream.println:(J)V
      56: return

  static {};
    Code:
       0: new           #2                  // class org/aoc2021/Day10
       3: dup
       4: invokespecial #246                // Method "<init>":()V
       7: putstatic     #34                 // Field INSTANCE:Lorg/aoc2021/Day10;
      10: iconst_4
      11: anewarray     #248                // class kotlin/Pair
      14: astore_0
      15: aload_0
      16: iconst_0
      17: bipush        41
      19: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      22: iconst_3
      23: invokestatic  #253                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      26: invokestatic  #259                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      29: aastore
      30: aload_0
      31: iconst_1
      32: bipush        93
      34: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      37: bipush        57
      39: invokestatic  #253                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      42: invokestatic  #259                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      45: aastore
      46: aload_0
      47: iconst_2
      48: bipush        125
      50: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      53: sipush        1197
      56: invokestatic  #253                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: invokestatic  #259                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      62: aastore
      63: aload_0
      64: iconst_3
      65: bipush        62
      67: invokestatic  #125                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      70: sipush        25137
      73: invokestatic  #253                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      76: invokestatic  #259                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      79: aastore
      80: aload_0
      81: invokestatic  #265                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      84: putstatic     #144                // Field values:Ljava/util/Map;
      87: return
}