package com.codelicia.advent2021

import java.util.*
import kotlin.math.min

class Day15(val input: String) {
    // Split the input string into a 2D grid of integers
    private val grid = input.split("\n").map { it ->
        it.toCharArray().map { it.digitToInt() }
    }

    private val maxRow = grid.lastIndex
    private val maxColumn = grid.last().lastIndex

    fun part1(): Int {
        val dp = Array(maxRow + 1) { IntArray(maxColumn + 1) { Int.MAX_VALUE } }
        dp[0][0] = 0

        for (i in 0..maxRow) {
            for (j in 0..maxColumn) {
                if (i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + grid[i][j])
                if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + grid[i][j])
            }
        }

        return dp[maxRow][maxColumn]
    }

    fun part2(): Int {
        val heap: PriorityQueue<Node> = PriorityQueue()
        heap.add(Node(0, 0, 0))

        val g = enlargeMap().split("\n").map { it ->
            it.toCharArray().map { it.digitToInt() }
        }

        val visited: MutableSet<Pair<Int, Int>> = mutableSetOf()

        while (heap.isNotEmpty()) {
            val node = heap.poll()
            val cost = node.cost
            val x = node.x
            val y = node.y
            if (x == g.lastIndex && y == g.last().lastIndex) {
                return cost
            }
            if (x to y in visited) continue

            visited.add(x to y)

            for ((nx, ny) in listOf(x to y-1, x to y+1, x-1 to y, x+1 to y)) {
                if (nx < 0 || ny < 0 || nx > g.lastIndex || ny > g.last().lastIndex) continue
                if (nx to ny in visited) continue
                heap.add(Node(cost + g[nx][ny], nx, ny))
            }
        }

        error("Could not find the shortest path")
    }

    fun Int.inc(i: Int): Int = if (this + i > 9) (this + i) % 9 else this+i

    fun enlargeMap(): String {
        // pad right
        var s : String = ""
        for (i in 0..maxRow) {
            repeat(5) {
                repeatIdx -> s += grid[i].map { it.inc(repeatIdx) }.joinToString("")
            }
            s += "\n"
        }

        // pad bottom
        repeat(4) { rp ->
            var paddedGrid = s.split("\n").map { it -> it.toCharArray().map { it.digitToInt() } }

            for (i in 0..maxRow) {
                s += paddedGrid[i].map { it.inc(rp+1) }.joinToString("") + "\n"
            }
        }

        return s.trim()
    }

    private class Node(val cost: Int, val x: Int, val y: Int) : Comparable<Node> {
        override fun compareTo(other: Node): Int = cost.compareTo(other.cost)
    }
}

Compiled from "Day15.kt"
public final class com.codelicia.advent2021.Day15 {
  private final java.lang.String input;

  private final java.util.List<java.util.List<java.lang.Integer>> grid;

  private final int maxRow;

  private final int maxColumn;

  public com.codelicia.advent2021.Day15(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String input
       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 input:Ljava/lang/String;
      15: aload_0
      16: aload_0
      17: getfield      #21                 // Field input:Ljava/lang/String;
      20: checkcast     #23                 // class java/lang/CharSequence
      23: iconst_1
      24: anewarray     #25                 // class java/lang/String
      27: astore_2
      28: aload_2
      29: iconst_0
      30: ldc           #27                 // String \n
      32: aastore
      33: aload_2
      34: iconst_0
      35: iconst_0
      36: bipush        6
      38: aconst_null
      39: invokestatic  #33                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      42: checkcast     #35                 // class java/lang/Iterable
      45: astore_2
      46: astore        22
      48: iconst_0
      49: istore_3
      50: aload_2
      51: astore        4
      53: new           #37                 // class java/util/ArrayList
      56: dup
      57: aload_2
      58: bipush        10
      60: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      63: invokespecial #46                 // Method java/util/ArrayList."<init>":(I)V
      66: checkcast     #48                 // class java/util/Collection
      69: astore        5
      71: iconst_0
      72: istore        6
      74: aload         4
      76: invokeinterface #52,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      81: astore        7
      83: aload         7
      85: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      90: ifeq          230
      93: aload         7
      95: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     100: astore        8
     102: aload         5
     104: aload         8
     106: checkcast     #25                 // class java/lang/String
     109: astore        9
     111: astore        23
     113: iconst_0
     114: istore        10
     116: aload         9
     118: invokevirtual #66                 // Method java/lang/String.toCharArray:()[C
     121: dup
     122: ldc           #68                 // String toCharArray(...)
     124: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     127: astore        11
     129: nop
     130: iconst_0
     131: istore        12
     133: aload         11
     135: astore        13
     137: new           #37                 // class java/util/ArrayList
     140: dup
     141: aload         11
     143: arraylength
     144: invokespecial #46                 // Method java/util/ArrayList."<init>":(I)V
     147: checkcast     #48                 // class java/util/Collection
     150: astore        14
     152: iconst_0
     153: istore        15
     155: iconst_0
     156: istore        16
     158: aload         13
     160: arraylength
     161: istore        17
     163: iload         16
     165: iload         17
     167: if_icmpge     211
     170: aload         13
     172: iload         16
     174: caload
     175: istore        18
     177: aload         14
     179: iload         18
     181: istore        19
     183: astore        20
     185: iconst_0
     186: istore        21
     188: iload         19
     190: invokestatic  #77                 // Method kotlin/text/CharsKt.digitToInt:(C)I
     193: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     196: aload         20
     198: swap
     199: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     204: pop
     205: iinc          16, 1
     208: goto          163
     211: aload         14
     213: checkcast     #89                 // class java/util/List
     216: nop
     217: nop
     218: aload         23
     220: swap
     221: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     226: pop
     227: goto          83
     230: aload         5
     232: checkcast     #89                 // class java/util/List
     235: nop
     236: aload         22
     238: swap
     239: putfield      #93                 // Field grid:Ljava/util/List;
     242: aload_0
     243: aload_0
     244: getfield      #93                 // Field grid:Ljava/util/List;
     247: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     250: putfield      #101                // Field maxRow:I
     253: aload_0
     254: aload_0
     255: getfield      #93                 // Field grid:Ljava/util/List;
     258: invokestatic  #105                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     261: checkcast     #89                 // class java/util/List
     264: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     267: putfield      #108                // Field maxColumn:I
     270: return

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

  public final int part1();
    Code:
       0: iconst_0
       1: istore_2
       2: aload_0
       3: getfield      #101                // Field maxRow:I
       6: iconst_1
       7: iadd
       8: istore_3
       9: iload_3
      10: anewarray     #131                // class "[I"
      13: astore        4
      15: iload_2
      16: iload_3
      17: if_icmpge     85
      20: iload_2
      21: istore        5
      23: aload         4
      25: iload         5
      27: iconst_0
      28: istore        6
      30: aload_0
      31: getfield      #108                // Field maxColumn:I
      34: iconst_1
      35: iadd
      36: istore        7
      38: iload         7
      40: newarray       int
      42: astore        8
      44: istore        11
      46: astore        10
      48: iload         6
      50: iload         7
      52: if_icmpge     72
      55: iload         6
      57: istore        9
      59: aload         8
      61: iload         9
      63: ldc           #132                // int 2147483647
      65: iastore
      66: iinc          6, 1
      69: goto          48
      72: aload         10
      74: iload         11
      76: aload         8
      78: aastore
      79: iinc          2, 1
      82: goto          15
      85: aload         4
      87: astore_1
      88: aload_1
      89: iconst_0
      90: aaload
      91: iconst_0
      92: iconst_0
      93: iastore
      94: iconst_0
      95: istore_2
      96: aload_0
      97: getfield      #101                // Field maxRow:I
     100: istore_3
     101: iload_2
     102: iload_3
     103: if_icmpgt     255
     106: iconst_0
     107: istore        4
     109: aload_0
     110: getfield      #108                // Field maxColumn:I
     113: istore        5
     115: iload         4
     117: iload         5
     119: if_icmpgt     244
     122: iload_2
     123: ifle          176
     126: aload_1
     127: iload_2
     128: aaload
     129: iload         4
     131: aload_1
     132: iload_2
     133: aaload
     134: iload         4
     136: iaload
     137: aload_1
     138: iload_2
     139: iconst_1
     140: isub
     141: aaload
     142: iload         4
     144: iaload
     145: aload_0
     146: getfield      #93                 // Field grid:Ljava/util/List;
     149: iload_2
     150: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     155: checkcast     #89                 // class java/util/List
     158: iload         4
     160: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     165: checkcast     #138                // class java/lang/Number
     168: invokevirtual #141                // Method java/lang/Number.intValue:()I
     171: iadd
     172: invokestatic  #147                // Method java/lang/Math.min:(II)I
     175: iastore
     176: iload         4
     178: ifle          231
     181: aload_1
     182: iload_2
     183: aaload
     184: iload         4
     186: aload_1
     187: iload_2
     188: aaload
     189: iload         4
     191: iaload
     192: aload_1
     193: iload_2
     194: aaload
     195: iload         4
     197: iconst_1
     198: isub
     199: iaload
     200: aload_0
     201: getfield      #93                 // Field grid:Ljava/util/List;
     204: iload_2
     205: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     210: checkcast     #89                 // class java/util/List
     213: iload         4
     215: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     220: checkcast     #138                // class java/lang/Number
     223: invokevirtual #141                // Method java/lang/Number.intValue:()I
     226: iadd
     227: invokestatic  #147                // Method java/lang/Math.min:(II)I
     230: iastore
     231: iload         4
     233: iload         5
     235: if_icmpeq     244
     238: iinc          4, 1
     241: goto          122
     244: iload_2
     245: iload_3
     246: if_icmpeq     255
     249: iinc          2, 1
     252: goto          106
     255: aload_1
     256: aload_0
     257: getfield      #101                // Field maxRow:I
     260: aaload
     261: aload_0
     262: getfield      #108                // Field maxColumn:I
     265: iaload
     266: ireturn

  public final int part2();
    Code:
       0: new           #155                // class java/util/PriorityQueue
       3: dup
       4: invokespecial #156                // Method java/util/PriorityQueue."<init>":()V
       7: astore_1
       8: aload_1
       9: new           #158                // class com/codelicia/advent2021/Day15$Node
      12: dup
      13: iconst_0
      14: iconst_0
      15: iconst_0
      16: invokespecial #161                // Method com/codelicia/advent2021/Day15$Node."<init>":(III)V
      19: invokevirtual #162                // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
      22: pop
      23: aload_0
      24: invokevirtual #165                // Method enlargeMap:()Ljava/lang/String;
      27: checkcast     #23                 // class java/lang/CharSequence
      30: iconst_1
      31: anewarray     #25                 // class java/lang/String
      34: astore_3
      35: aload_3
      36: iconst_0
      37: ldc           #27                 // String \n
      39: aastore
      40: aload_3
      41: iconst_0
      42: iconst_0
      43: bipush        6
      45: aconst_null
      46: invokestatic  #33                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      49: checkcast     #35                 // class java/lang/Iterable
      52: astore_3
      53: iconst_0
      54: istore        4
      56: aload_3
      57: astore        5
      59: new           #37                 // class java/util/ArrayList
      62: dup
      63: aload_3
      64: bipush        10
      66: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      69: invokespecial #46                 // Method java/util/ArrayList."<init>":(I)V
      72: checkcast     #48                 // class java/util/Collection
      75: astore        6
      77: iconst_0
      78: istore        7
      80: aload         5
      82: invokeinterface #52,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      87: astore        8
      89: aload         8
      91: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      96: ifeq          236
      99: aload         8
     101: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     106: astore        9
     108: aload         6
     110: aload         9
     112: checkcast     #25                 // class java/lang/String
     115: astore        10
     117: astore        23
     119: iconst_0
     120: istore        11
     122: aload         10
     124: invokevirtual #66                 // Method java/lang/String.toCharArray:()[C
     127: dup
     128: ldc           #68                 // String toCharArray(...)
     130: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     133: astore        12
     135: nop
     136: iconst_0
     137: istore        13
     139: aload         12
     141: astore        14
     143: new           #37                 // class java/util/ArrayList
     146: dup
     147: aload         12
     149: arraylength
     150: invokespecial #46                 // Method java/util/ArrayList."<init>":(I)V
     153: checkcast     #48                 // class java/util/Collection
     156: astore        15
     158: iconst_0
     159: istore        16
     161: iconst_0
     162: istore        17
     164: aload         14
     166: arraylength
     167: istore        18
     169: iload         17
     171: iload         18
     173: if_icmpge     217
     176: aload         14
     178: iload         17
     180: caload
     181: istore        19
     183: aload         15
     185: iload         19
     187: istore        20
     189: astore        21
     191: iconst_0
     192: istore        22
     194: iload         20
     196: invokestatic  #77                 // Method kotlin/text/CharsKt.digitToInt:(C)I
     199: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     202: aload         21
     204: swap
     205: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     210: pop
     211: iinc          17, 1
     214: goto          169
     217: aload         15
     219: checkcast     #89                 // class java/util/List
     222: nop
     223: nop
     224: aload         23
     226: swap
     227: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     232: pop
     233: goto          89
     236: aload         6
     238: checkcast     #89                 // class java/util/List
     241: nop
     242: astore_2
     243: new           #167                // class java/util/LinkedHashSet
     246: dup
     247: invokespecial #168                // Method java/util/LinkedHashSet."<init>":()V
     250: checkcast     #170                // class java/util/Set
     253: astore_3
     254: aload_1
     255: checkcast     #48                 // class java/util/Collection
     258: invokeinterface #173,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     263: ifne          270
     266: iconst_1
     267: goto          271
     270: iconst_0
     271: ifeq          620
     274: aload_1
     275: invokevirtual #176                // Method java/util/PriorityQueue.poll:()Ljava/lang/Object;
     278: checkcast     #158                // class com/codelicia/advent2021/Day15$Node
     281: astore        4
     283: aload         4
     285: invokevirtual #179                // Method com/codelicia/advent2021/Day15$Node.getCost:()I
     288: istore        5
     290: aload         4
     292: invokevirtual #182                // Method com/codelicia/advent2021/Day15$Node.getX:()I
     295: istore        6
     297: aload         4
     299: invokevirtual #185                // Method com/codelicia/advent2021/Day15$Node.getY:()I
     302: istore        7
     304: iload         6
     306: aload_2
     307: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     310: if_icmpne     331
     313: iload         7
     315: aload_2
     316: invokestatic  #105                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     319: checkcast     #89                 // class java/util/List
     322: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     325: if_icmpne     331
     328: iload         5
     330: ireturn
     331: aload_3
     332: iload         6
     334: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     337: iload         7
     339: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     342: invokestatic  #191                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     345: invokeinterface #194,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     350: ifne          254
     353: aload_3
     354: iload         6
     356: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     359: iload         7
     361: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     364: invokestatic  #191                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     367: invokeinterface #195,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     372: pop
     373: iconst_4
     374: anewarray     #197                // class kotlin/Pair
     377: astore        9
     379: aload         9
     381: iconst_0
     382: iload         6
     384: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     387: iload         7
     389: iconst_1
     390: isub
     391: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     394: invokestatic  #191                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     397: aastore
     398: aload         9
     400: iconst_1
     401: iload         6
     403: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     406: iload         7
     408: iconst_1
     409: iadd
     410: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     413: invokestatic  #191                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     416: aastore
     417: aload         9
     419: iconst_2
     420: iload         6
     422: iconst_1
     423: isub
     424: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     427: iload         7
     429: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     432: invokestatic  #191                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     435: aastore
     436: aload         9
     438: iconst_3
     439: iload         6
     441: iconst_1
     442: iadd
     443: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     446: iload         7
     448: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     451: invokestatic  #191                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     454: aastore
     455: aload         9
     457: invokestatic  #201                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     460: invokeinterface #202,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     465: astore        8
     467: aload         8
     469: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     474: ifeq          254
     477: aload         8
     479: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     484: checkcast     #197                // class kotlin/Pair
     487: astore        9
     489: aload         9
     491: invokevirtual #205                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     494: checkcast     #138                // class java/lang/Number
     497: invokevirtual #141                // Method java/lang/Number.intValue:()I
     500: istore        10
     502: aload         9
     504: invokevirtual #208                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     507: checkcast     #138                // class java/lang/Number
     510: invokevirtual #141                // Method java/lang/Number.intValue:()I
     513: istore        11
     515: iload         10
     517: iflt          467
     520: iload         11
     522: iflt          467
     525: iload         10
     527: aload_2
     528: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     531: if_icmpgt     467
     534: iload         11
     536: aload_2
     537: invokestatic  #105                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     540: checkcast     #89                 // class java/util/List
     543: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     546: if_icmple     552
     549: goto          467
     552: aload_3
     553: iload         10
     555: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     558: iload         11
     560: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     563: invokestatic  #191                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     566: invokeinterface #194,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     571: ifne          467
     574: aload_1
     575: new           #158                // class com/codelicia/advent2021/Day15$Node
     578: dup
     579: iload         5
     581: aload_2
     582: iload         10
     584: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     589: checkcast     #89                 // class java/util/List
     592: iload         11
     594: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     599: checkcast     #138                // class java/lang/Number
     602: invokevirtual #141                // Method java/lang/Number.intValue:()I
     605: iadd
     606: iload         10
     608: iload         11
     610: invokespecial #161                // Method com/codelicia/advent2021/Day15$Node."<init>":(III)V
     613: invokevirtual #162                // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
     616: pop
     617: goto          467
     620: new           #210                // class java/lang/IllegalStateException
     623: dup
     624: ldc           #212                // String Could not find the shortest path
     626: invokevirtual #215                // Method java/lang/Object.toString:()Ljava/lang/String;
     629: invokespecial #217                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     632: athrow

  public final int inc(int, int);
    Code:
       0: iload_1
       1: iload_2
       2: iadd
       3: bipush        9
       5: if_icmple     17
       8: iload_1
       9: iload_2
      10: iadd
      11: bipush        9
      13: irem
      14: goto          20
      17: iload_1
      18: iload_2
      19: iadd
      20: ireturn

  public final java.lang.String enlargeMap();
    Code:
       0: aconst_null
       1: astore_1
       2: ldc           #235                // String
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_0
       8: getfield      #101                // Field maxRow:I
      11: istore_3
      12: iload_2
      13: iload_3
      14: if_icmpgt     235
      17: iconst_5
      18: istore        4
      20: iconst_0
      21: istore        5
      23: iload         5
      25: iload         4
      27: if_icmpge     204
      30: iload         5
      32: istore        6
      34: iconst_0
      35: istore        7
      37: new           #237                // class java/lang/StringBuilder
      40: dup
      41: invokespecial #238                // Method java/lang/StringBuilder."<init>":()V
      44: aload_1
      45: invokevirtual #242                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      48: aload_0
      49: getfield      #93                 // Field grid:Ljava/util/List;
      52: iload_2
      53: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      58: checkcast     #35                 // class java/lang/Iterable
      61: astore        8
      63: astore        9
      65: iconst_0
      66: istore        11
      68: aload         8
      70: astore        12
      72: new           #37                 // class java/util/ArrayList
      75: dup
      76: aload         8
      78: bipush        10
      80: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      83: invokespecial #46                 // Method java/util/ArrayList."<init>":(I)V
      86: checkcast     #48                 // class java/util/Collection
      89: astore        13
      91: iconst_0
      92: istore        14
      94: aload         12
      96: invokeinterface #52,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     101: astore        15
     103: aload         15
     105: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     110: ifeq          162
     113: aload         15
     115: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     120: astore        16
     122: aload         13
     124: aload         16
     126: checkcast     #138                // class java/lang/Number
     129: invokevirtual #141                // Method java/lang/Number.intValue:()I
     132: istore        17
     134: astore        18
     136: iconst_0
     137: istore        19
     139: aload_0
     140: iload         17
     142: iload         6
     144: invokevirtual #244                // Method inc:(II)I
     147: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     150: aload         18
     152: swap
     153: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     158: pop
     159: goto          103
     162: aload         13
     164: checkcast     #89                 // class java/util/List
     167: nop
     168: aload         9
     170: swap
     171: checkcast     #35                 // class java/lang/Iterable
     174: ldc           #235                // String
     176: checkcast     #23                 // class java/lang/CharSequence
     179: aconst_null
     180: aconst_null
     181: iconst_0
     182: aconst_null
     183: aconst_null
     184: bipush        62
     186: aconst_null
     187: invokestatic  #248                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     190: invokevirtual #242                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     193: invokevirtual #249                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     196: astore_1
     197: nop
     198: iinc          5, 1
     201: goto          23
     204: new           #237                // class java/lang/StringBuilder
     207: dup
     208: invokespecial #238                // Method java/lang/StringBuilder."<init>":()V
     211: aload_1
     212: invokevirtual #242                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     215: bipush        10
     217: invokevirtual #252                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     220: invokevirtual #249                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     223: astore_1
     224: iload_2
     225: iload_3
     226: if_icmpeq     235
     229: iinc          2, 1
     232: goto          17
     235: iconst_4
     236: istore_2
     237: iconst_0
     238: istore_3
     239: iload_3
     240: iload_2
     241: if_icmpge     676
     244: iload_3
     245: istore        4
     247: iconst_0
     248: istore        5
     250: aload_1
     251: checkcast     #23                 // class java/lang/CharSequence
     254: iconst_1
     255: anewarray     #25                 // class java/lang/String
     258: astore        6
     260: aload         6
     262: iconst_0
     263: ldc           #27                 // String \n
     265: aastore
     266: aload         6
     268: iconst_0
     269: iconst_0
     270: bipush        6
     272: aconst_null
     273: invokestatic  #33                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     276: checkcast     #35                 // class java/lang/Iterable
     279: astore        6
     281: iconst_0
     282: istore        7
     284: aload         6
     286: astore        8
     288: new           #37                 // class java/util/ArrayList
     291: dup
     292: aload         6
     294: bipush        10
     296: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     299: invokespecial #46                 // Method java/util/ArrayList."<init>":(I)V
     302: checkcast     #48                 // class java/util/Collection
     305: astore        9
     307: iconst_0
     308: istore        10
     310: aload         8
     312: invokeinterface #52,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     317: astore        11
     319: aload         11
     321: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     326: ifeq          466
     329: aload         11
     331: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     336: astore        12
     338: aload         9
     340: aload         12
     342: checkcast     #25                 // class java/lang/String
     345: astore        13
     347: astore        14
     349: iconst_0
     350: istore        15
     352: aload         13
     354: invokevirtual #66                 // Method java/lang/String.toCharArray:()[C
     357: dup
     358: ldc           #68                 // String toCharArray(...)
     360: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     363: astore        16
     365: nop
     366: iconst_0
     367: istore        17
     369: aload         16
     371: astore        18
     373: new           #37                 // class java/util/ArrayList
     376: dup
     377: aload         16
     379: arraylength
     380: invokespecial #46                 // Method java/util/ArrayList."<init>":(I)V
     383: checkcast     #48                 // class java/util/Collection
     386: astore        19
     388: iconst_0
     389: istore        20
     391: iconst_0
     392: istore        21
     394: aload         18
     396: arraylength
     397: istore        22
     399: iload         21
     401: iload         22
     403: if_icmpge     447
     406: aload         18
     408: iload         21
     410: caload
     411: istore        23
     413: aload         19
     415: iload         23
     417: istore        24
     419: astore        25
     421: iconst_0
     422: istore        26
     424: iload         24
     426: invokestatic  #77                 // Method kotlin/text/CharsKt.digitToInt:(C)I
     429: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     432: aload         25
     434: swap
     435: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     440: pop
     441: iinc          21, 1
     444: goto          399
     447: aload         19
     449: checkcast     #89                 // class java/util/List
     452: nop
     453: nop
     454: aload         14
     456: swap
     457: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     462: pop
     463: goto          319
     466: aload         9
     468: checkcast     #89                 // class java/util/List
     471: nop
     472: astore        27
     474: iconst_0
     475: istore        6
     477: aload_0
     478: getfield      #101                // Field maxRow:I
     481: istore        7
     483: iload         6
     485: iload         7
     487: if_icmpgt     669
     490: new           #237                // class java/lang/StringBuilder
     493: dup
     494: invokespecial #238                // Method java/lang/StringBuilder."<init>":()V
     497: aload_1
     498: invokevirtual #242                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     501: aload         27
     503: iload         6
     505: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     510: checkcast     #35                 // class java/lang/Iterable
     513: astore        8
     515: astore        28
     517: iconst_0
     518: istore        9
     520: aload         8
     522: astore        10
     524: new           #37                 // class java/util/ArrayList
     527: dup
     528: aload         8
     530: bipush        10
     532: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     535: invokespecial #46                 // Method java/util/ArrayList."<init>":(I)V
     538: checkcast     #48                 // class java/util/Collection
     541: astore        11
     543: iconst_0
     544: istore        12
     546: aload         10
     548: invokeinterface #52,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     553: astore        13
     555: aload         13
     557: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     562: ifeq          616
     565: aload         13
     567: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     572: astore        15
     574: aload         11
     576: aload         15
     578: checkcast     #138                // class java/lang/Number
     581: invokevirtual #141                // Method java/lang/Number.intValue:()I
     584: istore        16
     586: astore        29
     588: iconst_0
     589: istore        17
     591: aload_0
     592: iload         16
     594: iload         4
     596: iconst_1
     597: iadd
     598: invokevirtual #244                // Method inc:(II)I
     601: invokestatic  #83                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     604: aload         29
     606: swap
     607: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     612: pop
     613: goto          555
     616: aload         11
     618: checkcast     #89                 // class java/util/List
     621: nop
     622: aload         28
     624: swap
     625: checkcast     #35                 // class java/lang/Iterable
     628: ldc           #235                // String
     630: checkcast     #23                 // class java/lang/CharSequence
     633: aconst_null
     634: aconst_null
     635: iconst_0
     636: aconst_null
     637: aconst_null
     638: bipush        62
     640: aconst_null
     641: invokestatic  #248                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     644: invokevirtual #242                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     647: bipush        10
     649: invokevirtual #252                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     652: invokevirtual #249                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     655: astore_1
     656: iload         6
     658: iload         7
     660: if_icmpeq     669
     663: iinc          6, 1
     666: goto          490
     669: nop
     670: iinc          3, 1
     673: goto          239
     676: aload_1
     677: checkcast     #23                 // class java/lang/CharSequence
     680: invokestatic  #256                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     683: invokevirtual #215                // Method java/lang/Object.toString:()Ljava/lang/String;
     686: areturn
}

Compiled from "Day15.kt"
final class com.codelicia.advent2021.Day15$Node implements java.lang.Comparable<com.codelicia.advent2021.Day15$Node> {
  private final int cost;

  private final int x;

  private final int y;

  public com.codelicia.advent2021.Day15$Node(int, int, int);
    Code:
       0: aload_0
       1: invokespecial #12                 // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #16                 // Field cost:I
       9: aload_0
      10: iload_2
      11: putfield      #19                 // Field x:I
      14: aload_0
      15: iload_3
      16: putfield      #22                 // Field y:I
      19: return

  public final int getCost();
    Code:
       0: aload_0
       1: getfield      #16                 // Field cost:I
       4: ireturn

  public final int getX();
    Code:
       0: aload_0
       1: getfield      #19                 // Field x:I
       4: ireturn

  public final int getY();
    Code:
       0: aload_0
       1: getfield      #22                 // Field y:I
       4: ireturn

  public int compareTo(com.codelicia.advent2021.Day15$Node);
    Code:
       0: aload_1
       1: ldc           #33                 // String other
       3: invokestatic  #39                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #16                 // Field cost:I
      10: aload_1
      11: getfield      #16                 // Field cost:I
      14: invokestatic  #43                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      17: ireturn

  public int compareTo(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #2                  // class com/codelicia/advent2021/Day15$Node
       5: invokevirtual #46                 // Method compareTo:(Lcom/codelicia/advent2021/Day15$Node;)I
       8: ireturn
}


package com.codelicia.advent2021

import java.util.SortedMap

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

    private val bitLength = input.first().length

    private fun List<Int>.toInt() =
        this.joinToString("").toInt(2)

    private fun List<Int>.gamma() = this.toInt()

    private fun List<Int>.epsilon() = this.map(::invertBit).toInt()

    private fun SortedMap<Int, Int>.bit(): Int =
        if (this.getValue(0) > this.getValue(1)) 0 else 1

    private fun SortedMap<Int, Int>.invBit(): Int =
        if (this.getValue(0) > this.getValue(1)) 1 else 0

    private fun Set<String>.countBits(n: Int): List<SortedMap<Int, Int>> =
        listOf(
            this.map { v -> v[n].digitToInt() }
                .groupingBy { it }
                .eachCount()
                .toSortedMap()
        )

    private val diagnosticReport = buildList {
        repeat(bitLength) { i ->
            val mostCommonBit = input
                .groupingBy { it[i].digitToInt() }
                .eachCount()
                .maxBy { it.value }
                .key

            add(mostCommonBit)
        }
    }

    private fun invertBit(n: Int) = if (n == 1) 0 else 1

    private fun calculateRating(
        remainingNumbers: Set<String>,
        predicate: (String, Int, List<SortedMap<Int, Int>>) -> Boolean,
        index: Int = 0,
    ): Int {
        if (remainingNumbers.count() == 1) return remainingNumbers.first().toInt(radix = 2)

        val sortedList = remainingNumbers.countBits(index)

        val filteredNumbers = remainingNumbers.filterNot { v -> predicate(v, index, sortedList) }.toSet()

        return calculateRating(filteredNumbers, predicate, index + 1)
    }

    fun part1(): Int = diagnosticReport.gamma() * diagnosticReport.epsilon()

    fun part2(): Int {

        val binaryNumbers = input.toSet()

        val co2ScrubberRating = calculateRating(
            binaryNumbers,
            { v, n, sl -> v[n].digitToInt() == sl[0].invBit() }
        )

        val oxygenGeneratorRating = calculateRating(
            binaryNumbers,
            { v, n, sl -> v[n].digitToInt() == sl[0].bit() }
        )

        return oxygenGeneratorRating * co2ScrubberRating
    }
}

Compiled from "_Collections.kt"
public final class com.codelicia.advent2021.Day03$countBits$$inlined$groupingBy$1 implements kotlin.collections.Grouping<java.lang.Integer, java.lang.Integer> {
  final java.lang.Iterable $this_groupingBy;

  public com.codelicia.advent2021.Day03$countBits$$inlined$groupingBy$1(java.lang.Iterable);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_groupingBy:Ljava/lang/Iterable;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public java.util.Iterator<java.lang.Integer> sourceIterator();
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_groupingBy:Ljava/lang/Iterable;
       4: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: areturn

  public java.lang.Integer keyOf(java.lang.Integer);
    Code:
       0: aload_1
       1: checkcast     #37                 // class java/lang/Number
       4: invokevirtual #41                 // Method java/lang/Number.intValue:()I
       7: istore_2
       8: iconst_0
       9: istore_3
      10: iload_2
      11: invokestatic  #47                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      14: areturn
}

Compiled from "_Collections.kt"
public final class com.codelicia.advent2021.Day03$diagnosticReport$lambda$5$lambda$4$$inlined$groupingBy$1 implements kotlin.collections.Grouping<java.lang.String, java.lang.Integer> {
  final java.lang.Iterable $this_groupingBy;

  final int $i$inlined;

  public com.codelicia.advent2021.Day03$diagnosticReport$lambda$5$lambda$4$$inlined$groupingBy$1(java.lang.Iterable, int);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #20                 // Field $this_groupingBy:Ljava/lang/Iterable;
       5: aload_0
       6: iload_2
       7: putfield      #22                 // Field $i$inlined:I
      10: aload_0
      11: invokespecial #25                 // Method java/lang/Object."<init>":()V
      14: return

  public java.util.Iterator<java.lang.String> sourceIterator();
    Code:
       0: aload_0
       1: getfield      #20                 // Field $this_groupingBy:Ljava/lang/Iterable;
       4: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: areturn

  public java.lang.Integer keyOf(java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #41                 // class java/lang/String
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: aload_0
       9: getfield      #22                 // Field $i$inlined:I
      12: invokevirtual #45                 // Method java/lang/String.charAt:(I)C
      15: invokestatic  #51                 // Method kotlin/text/CharsKt.digitToInt:(C)I
      18: invokestatic  #57                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      21: areturn
}

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

  private final int bitLength;

  private final java.util.List<java.lang.Integer> diagnosticReport;

  public com.codelicia.advent2021.Day03(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: aload_0
      17: getfield      #22                 // Field input:Ljava/util/List;
      20: invokestatic  #28                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      23: checkcast     #30                 // class java/lang/String
      26: invokevirtual #34                 // Method java/lang/String.length:()I
      29: putfield      #38                 // Field bitLength:I
      32: aload_0
      33: invokestatic  #42                 // Method kotlin/collections/CollectionsKt.createListBuilder:()Ljava/util/List;
      36: astore_2
      37: aload_2
      38: astore_3
      39: astore        18
      41: iconst_0
      42: istore        4
      44: aload_0
      45: getfield      #38                 // Field bitLength:I
      48: istore        5
      50: iconst_0
      51: istore        6
      53: iload         6
      55: iload         5
      57: if_icmpge     279
      60: iload         6
      62: istore        7
      64: iconst_0
      65: istore        8
      67: aload_0
      68: getfield      #22                 // Field input:Ljava/util/List;
      71: checkcast     #44                 // class java/lang/Iterable
      74: astore        9
      76: nop
      77: iconst_0
      78: istore        10
      80: new           #46                 // class com/codelicia/advent2021/Day03$diagnosticReport$lambda$5$lambda$4$$inlined$groupingBy$1
      83: dup
      84: aload         9
      86: iload         7
      88: invokespecial #49                 // Method com/codelicia/advent2021/Day03$diagnosticReport$lambda$5$lambda$4$$inlined$groupingBy$1."<init>":(Ljava/lang/Iterable;I)V
      91: checkcast     #51                 // class kotlin/collections/Grouping
      94: invokestatic  #57                 // Method kotlin/collections/GroupingKt.eachCount:(Lkotlin/collections/Grouping;)Ljava/util/Map;
      97: invokeinterface #63,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     102: checkcast     #44                 // class java/lang/Iterable
     105: astore        10
     107: aload         10
     109: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     114: astore        11
     116: aload         11
     118: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     123: ifne          134
     126: new           #75                 // class java/util/NoSuchElementException
     129: dup
     130: invokespecial #76                 // Method java/util/NoSuchElementException."<init>":()V
     133: athrow
     134: aload         11
     136: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     141: astore        12
     143: aload         11
     145: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     150: ifne          158
     153: aload         12
     155: goto          244
     158: aload         12
     160: checkcast     #82                 // class java/util/Map$Entry
     163: astore        13
     165: iconst_0
     166: istore        14
     168: aload         13
     170: invokeinterface #85,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     175: checkcast     #87                 // class java/lang/Number
     178: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     181: istore        13
     183: aload         11
     185: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     190: astore        14
     192: aload         14
     194: checkcast     #82                 // class java/util/Map$Entry
     197: astore        15
     199: iconst_0
     200: istore        16
     202: aload         15
     204: invokeinterface #85,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     209: checkcast     #87                 // class java/lang/Number
     212: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     215: istore        15
     217: iload         13
     219: iload         15
     221: if_icmpge     232
     224: aload         14
     226: astore        12
     228: iload         15
     230: istore        13
     232: aload         11
     234: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     239: ifne          183
     242: aload         12
     244: checkcast     #82                 // class java/util/Map$Entry
     247: invokeinterface #93,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     252: checkcast     #87                 // class java/lang/Number
     255: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     258: istore        17
     260: aload_3
     261: iload         17
     263: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     266: invokeinterface #105,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     271: pop
     272: nop
     273: iinc          6, 1
     276: goto          53
     279: nop
     280: aload         18
     282: aload_2
     283: invokestatic  #109                // Method kotlin/collections/CollectionsKt.build:(Ljava/util/List;)Ljava/util/List;
     286: putfield      #112                // Field diagnosticReport:Ljava/util/List;
     289: return

  private final int toInt(java.util.List<java.lang.Integer>);
    Code:
       0: aload_1
       1: checkcast     #44                 // class java/lang/Iterable
       4: ldc           #130                // String
       6: checkcast     #132                // class java/lang/CharSequence
       9: aconst_null
      10: aconst_null
      11: iconst_0
      12: aconst_null
      13: aconst_null
      14: bipush        62
      16: aconst_null
      17: invokestatic  #136                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      20: iconst_2
      21: invokestatic  #142                // Method kotlin/text/CharsKt.checkRadix:(I)I
      24: invokestatic  #146                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      27: ireturn

  private final int gamma(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_1
       2: invokespecial #150                // Method toInt:(Ljava/util/List;)I
       5: ireturn

  private final int epsilon(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #44                 // class java/lang/Iterable
       5: astore_2
       6: astore        11
       8: iconst_0
       9: istore_3
      10: aload_2
      11: astore        4
      13: new           #154                // class java/util/ArrayList
      16: dup
      17: aload_2
      18: bipush        10
      20: invokestatic  #158                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      23: invokespecial #161                // Method java/util/ArrayList."<init>":(I)V
      26: checkcast     #163                // class java/util/Collection
      29: astore        5
      31: iconst_0
      32: istore        6
      34: aload         4
      36: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore        7
      43: aload         7
      45: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          100
      53: aload         7
      55: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        8
      62: aload         5
      64: aload         8
      66: checkcast     #87                 // class java/lang/Number
      69: invokevirtual #90                 // Method java/lang/Number.intValue:()I
      72: istore        9
      74: astore        12
      76: iconst_0
      77: istore        10
      79: aload_0
      80: iload         9
      82: invokespecial #166                // Method invertBit:(I)I
      85: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: aload         12
      90: swap
      91: invokeinterface #167,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      96: pop
      97: goto          43
     100: aload         5
     102: checkcast     #101                // class java/util/List
     105: nop
     106: aload         11
     108: swap
     109: invokespecial #150                // Method toInt:(Ljava/util/List;)I
     112: ireturn

  private final int bit(java.util.SortedMap<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_1
       1: checkcast     #59                 // class java/util/Map
       4: iconst_0
       5: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       8: invokestatic  #186                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      11: checkcast     #87                 // class java/lang/Number
      14: invokevirtual #90                 // Method java/lang/Number.intValue:()I
      17: aload_1
      18: checkcast     #59                 // class java/util/Map
      21: iconst_1
      22: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: invokestatic  #186                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      28: checkcast     #87                 // class java/lang/Number
      31: invokevirtual #90                 // Method java/lang/Number.intValue:()I
      34: if_icmple     41
      37: iconst_0
      38: goto          42
      41: iconst_1
      42: ireturn

  private final int invBit(java.util.SortedMap<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_1
       1: checkcast     #59                 // class java/util/Map
       4: iconst_0
       5: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       8: invokestatic  #186                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      11: checkcast     #87                 // class java/lang/Number
      14: invokevirtual #90                 // Method java/lang/Number.intValue:()I
      17: aload_1
      18: checkcast     #59                 // class java/util/Map
      21: iconst_1
      22: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: invokestatic  #186                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      28: checkcast     #87                 // class java/lang/Number
      31: invokevirtual #90                 // Method java/lang/Number.intValue:()I
      34: if_icmple     41
      37: iconst_1
      38: goto          42
      41: iconst_0
      42: ireturn

  private final java.util.List<java.util.SortedMap<java.lang.Integer, java.lang.Integer>> countBits(java.util.Set<java.lang.String>, int);
    Code:
       0: aload_1
       1: checkcast     #44                 // class java/lang/Iterable
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: astore        5
      11: new           #154                // class java/util/ArrayList
      14: dup
      15: aload_3
      16: bipush        10
      18: invokestatic  #158                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #161                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #163                // class java/util/Collection
      27: astore        6
      29: iconst_0
      30: istore        7
      32: aload         5
      34: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        8
      41: aload         8
      43: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          98
      51: aload         8
      53: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        9
      60: aload         6
      62: aload         9
      64: checkcast     #30                 // class java/lang/String
      67: astore        10
      69: astore        12
      71: iconst_0
      72: istore        11
      74: aload         10
      76: iload_2
      77: invokevirtual #197                // Method java/lang/String.charAt:(I)C
      80: invokestatic  #201                // Method kotlin/text/CharsKt.digitToInt:(C)I
      83: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: aload         12
      88: swap
      89: invokeinterface #167,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      94: pop
      95: goto          41
      98: aload         6
     100: checkcast     #101                // class java/util/List
     103: nop
     104: checkcast     #44                 // class java/lang/Iterable
     107: astore_3
     108: nop
     109: iconst_0
     110: istore        4
     112: new           #203                // class com/codelicia/advent2021/Day03$countBits$$inlined$groupingBy$1
     115: dup
     116: aload_3
     117: invokespecial #206                // Method com/codelicia/advent2021/Day03$countBits$$inlined$groupingBy$1."<init>":(Ljava/lang/Iterable;)V
     120: checkcast     #51                 // class kotlin/collections/Grouping
     123: invokestatic  #57                 // Method kotlin/collections/GroupingKt.eachCount:(Lkotlin/collections/Grouping;)Ljava/util/Map;
     126: invokestatic  #210                // Method kotlin/collections/MapsKt.toSortedMap:(Ljava/util/Map;)Ljava/util/SortedMap;
     129: invokestatic  #214                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     132: areturn

  private final int invertBit(int);
    Code:
       0: iload_1
       1: iconst_1
       2: if_icmpne     9
       5: iconst_0
       6: goto          10
       9: iconst_1
      10: ireturn

  private final int calculateRating(java.util.Set<java.lang.String>, kotlin.jvm.functions.Function3<? super java.lang.String, ? super java.lang.Integer, ? super java.util.List<? extends java.util.SortedMap<java.lang.Integer, java.lang.Integer>>, java.lang.Boolean>, int);
    Code:
       0: aload_1
       1: checkcast     #163                // class java/util/Collection
       4: invokeinterface #228,  1          // InterfaceMethod java/util/Collection.size:()I
       9: iconst_1
      10: if_icmpne     31
      13: aload_1
      14: checkcast     #44                 // class java/lang/Iterable
      17: invokestatic  #231                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
      20: checkcast     #30                 // class java/lang/String
      23: iconst_2
      24: invokestatic  #142                // Method kotlin/text/CharsKt.checkRadix:(I)I
      27: invokestatic  #146                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      30: ireturn
      31: aload_0
      32: aload_1
      33: iload_3
      34: invokespecial #233                // Method countBits:(Ljava/util/Set;I)Ljava/util/List;
      37: astore        4
      39: aload_1
      40: checkcast     #44                 // class java/lang/Iterable
      43: astore        6
      45: iconst_0
      46: istore        7
      48: aload         6
      50: astore        8
      52: new           #154                // class java/util/ArrayList
      55: dup
      56: invokespecial #234                // Method java/util/ArrayList."<init>":()V
      59: checkcast     #163                // class java/util/Collection
      62: astore        9
      64: iconst_0
      65: istore        10
      67: aload         8
      69: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      74: astore        11
      76: aload         11
      78: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      83: ifeq          141
      86: aload         11
      88: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      93: astore        12
      95: aload         12
      97: checkcast     #30                 // class java/lang/String
     100: astore        13
     102: iconst_0
     103: istore        14
     105: aload_2
     106: aload         13
     108: iload_3
     109: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: aload         4
     114: invokeinterface #240,  4          // InterfaceMethod kotlin/jvm/functions/Function3.invoke:(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     119: checkcast     #242                // class java/lang/Boolean
     122: invokevirtual #245                // Method java/lang/Boolean.booleanValue:()Z
     125: ifne          76
     128: aload         9
     130: aload         12
     132: invokeinterface #167,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     137: pop
     138: goto          76
     141: aload         9
     143: checkcast     #101                // class java/util/List
     146: nop
     147: checkcast     #44                 // class java/lang/Iterable
     150: invokestatic  #249                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     153: astore        5
     155: aload_0
     156: aload         5
     158: aload_2
     159: iload_3
     160: iconst_1
     161: iadd
     162: invokespecial #251                // Method calculateRating:(Ljava/util/Set;Lkotlin/jvm/functions/Function3;I)I
     165: ireturn

  static int calculateRating$default(com.codelicia.advent2021.Day03, java.util.Set, kotlin.jvm.functions.Function3, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_4
       3: iand
       4: ifeq          9
       7: iconst_0
       8: istore_3
       9: aload_0
      10: aload_1
      11: aload_2
      12: iload_3
      13: invokespecial #251                // Method calculateRating:(Ljava/util/Set;Lkotlin/jvm/functions/Function3;I)I
      16: ireturn

  public final int part1();
    Code:
       0: aload_0
       1: aload_0
       2: getfield      #112                // Field diagnosticReport:Ljava/util/List;
       5: invokespecial #268                // Method gamma:(Ljava/util/List;)I
       8: aload_0
       9: aload_0
      10: getfield      #112                // Field diagnosticReport:Ljava/util/List;
      13: invokespecial #270                // Method epsilon:(Ljava/util/List;)I
      16: imul
      17: ireturn

  public final int part2();
    Code:
       0: aload_0
       1: getfield      #22                 // Field input:Ljava/util/List;
       4: checkcast     #44                 // class java/lang/Iterable
       7: invokestatic  #249                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
      10: astore_1
      11: aload_0
      12: aload_1
      13: aload_0
      14: invokedynamic #289,  0            // InvokeDynamic #0:invoke:(Lcom/codelicia/advent2021/Day03;)Lkotlin/jvm/functions/Function3;
      19: iconst_0
      20: iconst_4
      21: aconst_null
      22: invokestatic  #291                // Method calculateRating$default:(Lcom/codelicia/advent2021/Day03;Ljava/util/Set;Lkotlin/jvm/functions/Function3;IILjava/lang/Object;)I
      25: istore_2
      26: aload_0
      27: aload_1
      28: aload_0
      29: invokedynamic #296,  0            // InvokeDynamic #1:invoke:(Lcom/codelicia/advent2021/Day03;)Lkotlin/jvm/functions/Function3;
      34: iconst_0
      35: iconst_4
      36: aconst_null
      37: invokestatic  #291                // Method calculateRating$default:(Lcom/codelicia/advent2021/Day03;Ljava/util/Set;Lkotlin/jvm/functions/Function3;IILjava/lang/Object;)I
      40: istore_3
      41: iload_3
      42: iload_2
      43: imul
      44: ireturn

  private static final boolean part2$lambda$7(com.codelicia.advent2021.Day03, java.lang.String, int, java.util.List);
    Code:
       0: aload_1
       1: ldc_w         #300                // String v
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_3
       8: ldc_w         #302                // String sl
      11: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_1
      15: iload_2
      16: invokevirtual #197                // Method java/lang/String.charAt:(I)C
      19: invokestatic  #201                // Method kotlin/text/CharsKt.digitToInt:(C)I
      22: aload_0
      23: aload_3
      24: iconst_0
      25: invokeinterface #306,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      30: checkcast     #308                // class java/util/SortedMap
      33: invokespecial #310                // Method invBit:(Ljava/util/SortedMap;)I
      36: if_icmpne     43
      39: iconst_1
      40: goto          44
      43: iconst_0
      44: ireturn

  private static final boolean part2$lambda$8(com.codelicia.advent2021.Day03, java.lang.String, int, java.util.List);
    Code:
       0: aload_1
       1: ldc_w         #300                // String v
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_3
       8: ldc_w         #302                // String sl
      11: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_1
      15: iload_2
      16: invokevirtual #197                // Method java/lang/String.charAt:(I)C
      19: invokestatic  #201                // Method kotlin/text/CharsKt.digitToInt:(C)I
      22: aload_0
      23: aload_3
      24: iconst_0
      25: invokeinterface #306,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      30: checkcast     #308                // class java/util/SortedMap
      33: invokespecial #313                // Method bit:(Ljava/util/SortedMap;)I
      36: if_icmpne     43
      39: iconst_1
      40: goto          44
      43: iconst_0
      44: ireturn
}