package adventofcode.day03

import java.io.File

data class Point(val x: Int, val y: Int) {
    public fun moveLeft(distance: Int)= Point(x - distance, y)
    public fun moveRight(distance: Int)= Point(x + distance, y)
    public fun moveUp(distance: Int)= Point(x, y + distance)
    public fun moveDown(distance: Int)= Point(x, y - distance)

    public fun iterateLeft(distance: Int) = (1..distance).map { Point(x - it, y) }
    public fun iterateRight(distance: Int) = (1..distance).map { Point(x + it, y) }
    public fun iterateUp(distance: Int) = (1..distance).map { Point(x, y + it) }
    public fun iterateDown(distance: Int) = (1..distance).map { Point(x, y - it) }

    public fun manhattenDistance(p2: Point): Int =
        Math.abs(x - p2.x) + Math.abs(y - p2.y)
}

data class Line(val start: Point, val end: Point) {
    public fun hasPoint(p: Point): Boolean {
        val minX = Math.min(start.x, end.x)
        val maxX = Math.max(start.x, end.x)
        val minY = Math.min(start.y, end.y)
        val maxY = Math.max(start.y, end.y)

        return p.x >= minX && p.x <= maxX && p.y >= minY && p.y <= maxY
    }

    public fun intersects(other: Line): Point? {
        // Generate the intersection
        val intersection = if (end.y == start.y) {
            Point(other.start.x, start.y)
        } else {
            Point(start.x, other.start.y)
        }

        // Check if the intersection is on both lines
        if (other.hasPoint(intersection) && hasPoint(intersection)) {
            return intersection
        } else {
            return null
        }
    }
}

fun main(args: Array<String>) {
    val inputFile = if (args.size < 1) {
        System.err.println("Usage: adventofcode day03 <INPUT FILE>")
        System.exit(1)
        throw Exception("Whoop")
    } else {
        args[0]
    }

    val wires = File(inputFile).readLines().map(::parseItem)
    // println("[Part 1] Wire #1 ${wires[0]}")
    // println("[Part 1] Wire #2 ${wires[1]}")
    val intersections = (wires[0] intersect wires[1]).filterNot { it.x == 0 && it.y == 0 }
    val best = intersections.minBy {
        println("[Part 1] Intersection at $it")
        it.manhattenDistance(Point(0, 0))
    }

    if (best == null) {
        println("[Part 1] No intersection found.")
    } else {
        val distance = best.manhattenDistance(Point(0, 0))
        println("[Part 1] Closest intersection is $best (distance: $distance)")
    }

    // Now compute the best intersection by distance along the line
    val bestBySteps = intersections.map {
        // Add two to include the end points
        Pair(it, wires[0].indexOf(it) + wires[1].indexOf(it) + 2)
    }.minBy { it.second }

    if (bestBySteps == null) {
        println("[Part 2] No intersection found.")
    } else {
        println("[Part 2] Closest intersection is ${bestBySteps.first} (distance: ${bestBySteps.second})")
    }
}

fun parseItem(line: String): List<Point> {
    var prev = Point(0, 0)
    return line.split(",").flatMap {
        val start = prev
        val distance = it.substring(1).toInt()
        when (it[0]) {
            'L' -> {
                prev = start.moveLeft(distance)
                start.iterateLeft(distance)
            }
            'R' -> {
                prev = start.moveRight(distance)
                start.iterateRight(distance)
            }
            'D' -> {
                prev = start.moveDown(distance)
                start.iterateDown(distance)
            }
            'U' -> {
                prev = start.moveUp(distance)
                start.iterateUp(distance)
            }
            else -> throw Exception("Invalid direction: ${it[0]}")
        }
    }
}

Compiled from "main.kt"
public final class adventofcode.day03.MainKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: arraylength
       8: iconst_1
       9: if_icmpge     34
      12: getstatic     #21                 // Field java/lang/System.err:Ljava/io/PrintStream;
      15: ldc           #23                 // String Usage: adventofcode day03 <INPUT FILE>
      17: invokevirtual #29                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      20: iconst_1
      21: invokestatic  #33                 // Method java/lang/System.exit:(I)V
      24: new           #35                 // class java/lang/Exception
      27: dup
      28: ldc           #37                 // String Whoop
      30: invokespecial #40                 // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
      33: athrow
      34: aload_0
      35: iconst_0
      36: aaload
      37: astore_1
      38: new           #42                 // class java/io/File
      41: dup
      42: aload_1
      43: invokespecial #43                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      46: aconst_null
      47: iconst_1
      48: aconst_null
      49: invokestatic  #49                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      52: checkcast     #51                 // class java/lang/Iterable
      55: astore_3
      56: iconst_0
      57: istore        4
      59: aload_3
      60: astore        5
      62: new           #53                 // class java/util/ArrayList
      65: dup
      66: aload_3
      67: bipush        10
      69: invokestatic  #59                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      72: invokespecial #61                 // Method java/util/ArrayList."<init>":(I)V
      75: checkcast     #63                 // class java/util/Collection
      78: astore        6
      80: iconst_0
      81: istore        7
      83: aload         5
      85: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      90: astore        8
      92: aload         8
      94: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      99: ifeq          142
     102: aload         8
     104: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     109: astore        9
     111: aload         6
     113: aload         9
     115: checkcast     #79                 // class java/lang/String
     118: astore        10
     120: astore        15
     122: iconst_0
     123: istore        11
     125: aload         10
     127: invokestatic  #83                 // Method parseItem:(Ljava/lang/String;)Ljava/util/List;
     130: aload         15
     132: swap
     133: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     138: pop
     139: goto          92
     142: aload         6
     144: checkcast     #89                 // class java/util/List
     147: nop
     148: astore_2
     149: aload_2
     150: iconst_0
     151: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     156: checkcast     #51                 // class java/lang/Iterable
     159: aload_2
     160: iconst_1
     161: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     166: checkcast     #51                 // class java/lang/Iterable
     169: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     172: checkcast     #51                 // class java/lang/Iterable
     175: astore        4
     177: iconst_0
     178: istore        5
     180: aload         4
     182: astore        6
     184: new           #53                 // class java/util/ArrayList
     187: dup
     188: invokespecial #100                // Method java/util/ArrayList."<init>":()V
     191: checkcast     #63                 // class java/util/Collection
     194: astore        7
     196: iconst_0
     197: istore        8
     199: aload         6
     201: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     206: astore        9
     208: aload         9
     210: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     215: ifeq          274
     218: aload         9
     220: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     225: astore        10
     227: aload         10
     229: checkcast     #102                // class adventofcode/day03/Point
     232: astore        11
     234: iconst_0
     235: istore        12
     237: aload         11
     239: invokevirtual #106                // Method adventofcode/day03/Point.getX:()I
     242: ifne          257
     245: aload         11
     247: invokevirtual #109                // Method adventofcode/day03/Point.getY:()I
     250: ifne          257
     253: iconst_1
     254: goto          258
     257: iconst_0
     258: ifne          208
     261: aload         7
     263: aload         10
     265: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     270: pop
     271: goto          208
     274: aload         7
     276: checkcast     #89                 // class java/util/List
     279: nop
     280: astore_3
     281: aload_3
     282: checkcast     #51                 // class java/lang/Iterable
     285: astore        5
     287: iconst_0
     288: istore        6
     290: aload         5
     292: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     297: astore        7
     299: aload         7
     301: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     306: ifne          317
     309: new           #111                // class java/util/NoSuchElementException
     312: dup
     313: invokespecial #112                // Method java/util/NoSuchElementException."<init>":()V
     316: athrow
     317: aload         7
     319: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     324: astore        8
     326: aload         7
     328: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     333: ifne          341
     336: aload         8
     338: goto          483
     341: aload         8
     343: checkcast     #102                // class adventofcode/day03/Point
     346: astore        9
     348: iconst_0
     349: istore        10
     351: new           #114                // class java/lang/StringBuilder
     354: dup
     355: invokespecial #115                // Method java/lang/StringBuilder."<init>":()V
     358: ldc           #117                // String [Part 1] Intersection at
     360: invokevirtual #121                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     363: aload         9
     365: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     368: invokevirtual #128                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     371: getstatic     #131                // Field java/lang/System.out:Ljava/io/PrintStream;
     374: swap
     375: invokevirtual #134                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     378: aload         9
     380: new           #102                // class adventofcode/day03/Point
     383: dup
     384: iconst_0
     385: iconst_0
     386: invokespecial #137                // Method adventofcode/day03/Point."<init>":(II)V
     389: invokevirtual #141                // Method adventofcode/day03/Point.manhattenDistance:(Ladventofcode/day03/Point;)I
     392: istore        9
     394: aload         7
     396: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     401: astore        10
     403: aload         10
     405: checkcast     #102                // class adventofcode/day03/Point
     408: astore        11
     410: iconst_0
     411: istore        12
     413: new           #114                // class java/lang/StringBuilder
     416: dup
     417: invokespecial #115                // Method java/lang/StringBuilder."<init>":()V
     420: ldc           #117                // String [Part 1] Intersection at
     422: invokevirtual #121                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     425: aload         11
     427: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     430: invokevirtual #128                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     433: getstatic     #131                // Field java/lang/System.out:Ljava/io/PrintStream;
     436: swap
     437: invokevirtual #134                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     440: aload         11
     442: new           #102                // class adventofcode/day03/Point
     445: dup
     446: iconst_0
     447: iconst_0
     448: invokespecial #137                // Method adventofcode/day03/Point."<init>":(II)V
     451: invokevirtual #141                // Method adventofcode/day03/Point.manhattenDistance:(Ladventofcode/day03/Point;)I
     454: istore        11
     456: iload         9
     458: iload         11
     460: if_icmple     471
     463: aload         10
     465: astore        8
     467: iload         11
     469: istore        9
     471: aload         7
     473: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     478: ifne          394
     481: aload         8
     483: checkcast     #102                // class adventofcode/day03/Point
     486: astore        4
     488: aload         4
     490: ifnonnull     505
     493: ldc           #143                // String [Part 1] No intersection found.
     495: getstatic     #131                // Field java/lang/System.out:Ljava/io/PrintStream;
     498: swap
     499: invokevirtual #134                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     502: goto          563
     505: aload         4
     507: new           #102                // class adventofcode/day03/Point
     510: dup
     511: iconst_0
     512: iconst_0
     513: invokespecial #137                // Method adventofcode/day03/Point."<init>":(II)V
     516: invokevirtual #141                // Method adventofcode/day03/Point.manhattenDistance:(Ladventofcode/day03/Point;)I
     519: istore        5
     521: new           #114                // class java/lang/StringBuilder
     524: dup
     525: invokespecial #115                // Method java/lang/StringBuilder."<init>":()V
     528: ldc           #145                // String [Part 1] Closest intersection is
     530: invokevirtual #121                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     533: aload         4
     535: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     538: ldc           #147                // String  (distance:
     540: invokevirtual #121                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     543: iload         5
     545: invokevirtual #150                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     548: bipush        41
     550: invokevirtual #153                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     553: invokevirtual #128                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     556: getstatic     #131                // Field java/lang/System.out:Ljava/io/PrintStream;
     559: swap
     560: invokevirtual #134                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     563: aload_3
     564: checkcast     #51                 // class java/lang/Iterable
     567: astore        6
     569: iconst_0
     570: istore        7
     572: aload         6
     574: astore        8
     576: new           #53                 // class java/util/ArrayList
     579: dup
     580: aload         6
     582: bipush        10
     584: invokestatic  #59                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     587: invokespecial #61                 // Method java/util/ArrayList."<init>":(I)V
     590: checkcast     #63                 // class java/util/Collection
     593: astore        9
     595: iconst_0
     596: istore        10
     598: aload         8
     600: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     605: astore        11
     607: aload         11
     609: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     614: ifeq          701
     617: aload         11
     619: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     624: astore        12
     626: aload         9
     628: aload         12
     630: checkcast     #102                // class adventofcode/day03/Point
     633: astore        13
     635: astore        15
     637: iconst_0
     638: istore        14
     640: new           #155                // class kotlin/Pair
     643: dup
     644: aload         13
     646: aload_2
     647: iconst_0
     648: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     653: checkcast     #89                 // class java/util/List
     656: aload         13
     658: invokeinterface #159,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     663: aload_2
     664: iconst_1
     665: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     670: checkcast     #89                 // class java/util/List
     673: aload         13
     675: invokeinterface #159,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     680: iadd
     681: iconst_2
     682: iadd
     683: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     686: invokespecial #168                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     689: aload         15
     691: swap
     692: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     697: pop
     698: goto          607
     701: aload         9
     703: checkcast     #89                 // class java/util/List
     706: nop
     707: checkcast     #51                 // class java/lang/Iterable
     710: astore        6
     712: nop
     713: iconst_0
     714: istore        7
     716: aload         6
     718: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     723: astore        8
     725: aload         8
     727: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     732: ifne          743
     735: new           #111                // class java/util/NoSuchElementException
     738: dup
     739: invokespecial #112                // Method java/util/NoSuchElementException."<init>":()V
     742: athrow
     743: aload         8
     745: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     750: astore        9
     752: aload         8
     754: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     759: ifne          767
     762: aload         9
     764: goto          849
     767: aload         9
     769: checkcast     #155                // class kotlin/Pair
     772: astore        10
     774: iconst_0
     775: istore        11
     777: aload         10
     779: invokevirtual #171                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     782: checkcast     #173                // class java/lang/Number
     785: invokevirtual #176                // Method java/lang/Number.intValue:()I
     788: istore        10
     790: aload         8
     792: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     797: astore        11
     799: aload         11
     801: checkcast     #155                // class kotlin/Pair
     804: astore        12
     806: iconst_0
     807: istore        13
     809: aload         12
     811: invokevirtual #171                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     814: checkcast     #173                // class java/lang/Number
     817: invokevirtual #176                // Method java/lang/Number.intValue:()I
     820: istore        12
     822: iload         10
     824: iload         12
     826: if_icmple     837
     829: aload         11
     831: astore        9
     833: iload         12
     835: istore        10
     837: aload         8
     839: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     844: ifne          790
     847: aload         9
     849: checkcast     #155                // class kotlin/Pair
     852: astore        5
     854: aload         5
     856: ifnonnull     871
     859: ldc           #178                // String [Part 2] No intersection found.
     861: getstatic     #131                // Field java/lang/System.out:Ljava/io/PrintStream;
     864: swap
     865: invokevirtual #134                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     868: goto          925
     871: new           #114                // class java/lang/StringBuilder
     874: dup
     875: invokespecial #115                // Method java/lang/StringBuilder."<init>":()V
     878: ldc           #180                // String [Part 2] Closest intersection is
     880: invokevirtual #121                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     883: aload         5
     885: invokevirtual #183                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     888: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     891: ldc           #147                // String  (distance:
     893: invokevirtual #121                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     896: aload         5
     898: invokevirtual #171                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     901: checkcast     #173                // class java/lang/Number
     904: invokevirtual #176                // Method java/lang/Number.intValue:()I
     907: invokevirtual #150                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     910: bipush        41
     912: invokevirtual #153                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     915: invokevirtual #128                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     918: getstatic     #131                // Field java/lang/System.out:Ljava/io/PrintStream;
     921: swap
     922: invokevirtual #134                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     925: return

  public static final java.util.List<adventofcode.day03.Point> parseItem(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #228                // String line
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aconst_null
       7: astore_1
       8: new           #102                // class adventofcode/day03/Point
      11: dup
      12: iconst_0
      13: iconst_0
      14: invokespecial #137                // Method adventofcode/day03/Point."<init>":(II)V
      17: astore_1
      18: aload_0
      19: checkcast     #230                // class java/lang/CharSequence
      22: iconst_1
      23: anewarray     #79                 // class java/lang/String
      26: astore_2
      27: aload_2
      28: iconst_0
      29: ldc           #232                // String ,
      31: aastore
      32: aload_2
      33: iconst_0
      34: iconst_0
      35: bipush        6
      37: aconst_null
      38: invokestatic  #238                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      41: checkcast     #51                 // class java/lang/Iterable
      44: astore_2
      45: iconst_0
      46: istore_3
      47: aload_2
      48: astore        4
      50: new           #53                 // class java/util/ArrayList
      53: dup
      54: invokespecial #100                // Method java/util/ArrayList."<init>":()V
      57: checkcast     #63                 // class java/util/Collection
      60: astore        5
      62: iconst_0
      63: istore        6
      65: aload         4
      67: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      72: astore        7
      74: aload         7
      76: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      81: ifeq          294
      84: aload         7
      86: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      91: astore        8
      93: aload         8
      95: checkcast     #79                 // class java/lang/String
      98: astore        9
     100: iconst_0
     101: istore        10
     103: aload_1
     104: astore        11
     106: nop
     107: aload         9
     109: iconst_1
     110: invokevirtual #242                // Method java/lang/String.substring:(I)Ljava/lang/String;
     113: dup
     114: ldc           #244                // String substring(...)
     116: invokestatic  #247                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     119: invokestatic  #251                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     122: istore        12
     124: aload         9
     126: iconst_0
     127: invokevirtual #255                // Method java/lang/String.charAt:(I)C
     130: lookupswitch  { // 4
                    68: 208
                    76: 172
                    82: 190
                    85: 226
               default: 244
          }
     172: aload         11
     174: iload         12
     176: invokevirtual #259                // Method adventofcode/day03/Point.moveLeft:(I)Ladventofcode/day03/Point;
     179: astore_1
     180: aload         11
     182: iload         12
     184: invokevirtual #263                // Method adventofcode/day03/Point.iterateLeft:(I)Ljava/util/List;
     187: goto          277
     190: aload         11
     192: iload         12
     194: invokevirtual #266                // Method adventofcode/day03/Point.moveRight:(I)Ladventofcode/day03/Point;
     197: astore_1
     198: aload         11
     200: iload         12
     202: invokevirtual #269                // Method adventofcode/day03/Point.iterateRight:(I)Ljava/util/List;
     205: goto          277
     208: aload         11
     210: iload         12
     212: invokevirtual #272                // Method adventofcode/day03/Point.moveDown:(I)Ladventofcode/day03/Point;
     215: astore_1
     216: aload         11
     218: iload         12
     220: invokevirtual #275                // Method adventofcode/day03/Point.iterateDown:(I)Ljava/util/List;
     223: goto          277
     226: aload         11
     228: iload         12
     230: invokevirtual #278                // Method adventofcode/day03/Point.moveUp:(I)Ladventofcode/day03/Point;
     233: astore_1
     234: aload         11
     236: iload         12
     238: invokevirtual #281                // Method adventofcode/day03/Point.iterateUp:(I)Ljava/util/List;
     241: goto          277
     244: new           #35                 // class java/lang/Exception
     247: dup
     248: new           #114                // class java/lang/StringBuilder
     251: dup
     252: invokespecial #115                // Method java/lang/StringBuilder."<init>":()V
     255: ldc_w         #283                // String Invalid direction:
     258: invokevirtual #121                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     261: aload         9
     263: iconst_0
     264: invokevirtual #255                // Method java/lang/String.charAt:(I)C
     267: invokevirtual #153                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     270: invokevirtual #128                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     273: invokespecial #40                 // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
     276: athrow
     277: checkcast     #51                 // class java/lang/Iterable
     280: nop
     281: astore        9
     283: aload         5
     285: aload         9
     287: invokestatic  #287                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     290: pop
     291: goto          74
     294: aload         5
     296: checkcast     #89                 // class java/util/List
     299: nop
     300: areturn
}


package com.codeviking.kxg.math

import kotlin.math.*

/**
 * Partitions items with the given comparator. After partitioning, all elements left of k are smaller
 * than all elements right of k with respect to the given comparator function.
 *
 * This method implements the Floyd-Rivest selection algorithm:
 * https://en.wikipedia.org/wiki/Floyd%E2%80%93Rivest_algorithm
 */
fun <T> MutableList<T>.partition(k: Int, cmp: (T, T) -> Int) = partition(indices, k, cmp)

fun <T> MutableList<T>.partition(rng: IntRange, k: Int, cmp: (T, T) -> Int) {
    var left = rng.first
    var right = rng.last
    while (right > left) {
        if (right - left > 600) {
            val n = right - left + 1
            val i = k - left + 1
            val z = ln(n.toDouble())
            val s = 0.5 * exp(2.0 * z / 3.0)
            val sd = 0.5 * sqrt(z * s * (n - s) / n) * sign(i - n / 2.0)
            val newLeft = max(left, (k - i * s / n + sd).toInt())
            val newRight = min(right, (k + (n - i) * s / n + sd).toInt())
            partition(newLeft..newRight, k, cmp)
        }
        val t = get(k)
        var i = left
        var j = right
        swap(left, k)
        if (cmp(get(right), t) > 0) {
            swap(right, left)
        }
        while (i < j) {
            swap( i, j)
            i++
            j--
            while (cmp(get(i), t) < 0) {
                i++
            }
            while (cmp(get(j), t) > 0) {
                j--
            }
        }
        if (cmp(get(left), t) == 0) {
            swap(left, j)
        } else {
            j++
            swap(j, right)
        }
        if (j <= k) {
            left = j + 1
        }
        if (k <= j) {
            right = j - 1
        }
    }
}

private fun <T> MutableList<T>.swap(a: Int, b: Int) {
    this[a] = this[b].also { this[b] = this[a] }
}

Compiled from "Partition.kt"
public final class com.codeviking.kxg.math.PartitionKt {
  public static final <T> void partition(java.util.List<T>, int, kotlin.jvm.functions.Function2<? super T, ? super T, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String cmp
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_0
      14: checkcast     #20                 // class java/util/Collection
      17: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
      20: iload_1
      21: aload_2
      22: invokestatic  #29                 // Method partition:(Ljava/util/List;Lkotlin/ranges/IntRange;ILkotlin/jvm/functions/Function2;)V
      25: return

  public static final <T> void partition(java.util.List<T>, kotlin.ranges.IntRange, int, kotlin.jvm.functions.Function2<? super T, ? super T, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #37                 // String rng
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #18                 // String cmp
      15: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload_1
      19: invokevirtual #43                 // Method kotlin/ranges/IntRange.getFirst:()I
      22: istore        4
      24: aload_1
      25: invokevirtual #46                 // Method kotlin/ranges/IntRange.getLast:()I
      28: istore        5
      30: iload         5
      32: iload         4
      34: if_icmple     414
      37: iload         5
      39: iload         4
      41: isub
      42: sipush        600
      45: if_icmple     200
      48: iload         5
      50: iload         4
      52: isub
      53: iconst_1
      54: iadd
      55: istore        6
      57: iload_2
      58: iload         4
      60: isub
      61: iconst_1
      62: iadd
      63: istore        7
      65: iload         6
      67: i2d
      68: invokestatic  #52                 // Method java/lang/Math.log:(D)D
      71: dstore        8
      73: ldc2_w        #53                 // double 0.5d
      76: ldc2_w        #55                 // double 2.0d
      79: dload         8
      81: dmul
      82: ldc2_w        #57                 // double 3.0d
      85: ddiv
      86: invokestatic  #61                 // Method java/lang/Math.exp:(D)D
      89: dmul
      90: dstore        10
      92: ldc2_w        #53                 // double 0.5d
      95: dload         8
      97: dload         10
      99: dmul
     100: iload         6
     102: i2d
     103: dload         10
     105: dsub
     106: dmul
     107: iload         6
     109: i2d
     110: ddiv
     111: invokestatic  #64                 // Method java/lang/Math.sqrt:(D)D
     114: dmul
     115: iload         7
     117: i2d
     118: iload         6
     120: i2d
     121: ldc2_w        #55                 // double 2.0d
     124: ddiv
     125: dsub
     126: invokestatic  #67                 // Method java/lang/Math.signum:(D)D
     129: dmul
     130: dstore        12
     132: iload         4
     134: iload_2
     135: i2d
     136: iload         7
     138: i2d
     139: dload         10
     141: dmul
     142: iload         6
     144: i2d
     145: ddiv
     146: dsub
     147: dload         12
     149: dadd
     150: d2i
     151: invokestatic  #71                 // Method java/lang/Math.max:(II)I
     154: istore        14
     156: iload         5
     158: iload_2
     159: i2d
     160: iload         6
     162: iload         7
     164: isub
     165: i2d
     166: dload         10
     168: dmul
     169: iload         6
     171: i2d
     172: ddiv
     173: dadd
     174: dload         12
     176: dadd
     177: d2i
     178: invokestatic  #74                 // Method java/lang/Math.min:(II)I
     181: istore        15
     183: aload_0
     184: new           #39                 // class kotlin/ranges/IntRange
     187: dup
     188: iload         14
     190: iload         15
     192: invokespecial #78                 // Method kotlin/ranges/IntRange."<init>":(II)V
     195: iload_2
     196: aload_3
     197: invokestatic  #29                 // Method partition:(Ljava/util/List;Lkotlin/ranges/IntRange;ILkotlin/jvm/functions/Function2;)V
     200: aload_0
     201: iload_2
     202: invokeinterface #84,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     207: astore        6
     209: iload         4
     211: istore        7
     213: iload         5
     215: istore        8
     217: aload_0
     218: iload         4
     220: iload_2
     221: invokestatic  #88                 // Method swap:(Ljava/util/List;II)V
     224: aload_3
     225: aload_0
     226: iload         5
     228: invokeinterface #84,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     233: aload         6
     235: invokeinterface #94,  3           // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     240: checkcast     #96                 // class java/lang/Number
     243: invokevirtual #99                 // Method java/lang/Number.intValue:()I
     246: ifle          257
     249: aload_0
     250: iload         5
     252: iload         4
     254: invokestatic  #88                 // Method swap:(Ljava/util/List;II)V
     257: iload         7
     259: iload         8
     261: if_icmpge     340
     264: aload_0
     265: iload         7
     267: iload         8
     269: invokestatic  #88                 // Method swap:(Ljava/util/List;II)V
     272: iinc          7, 1
     275: iinc          8, -1
     278: aload_3
     279: aload_0
     280: iload         7
     282: invokeinterface #84,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     287: aload         6
     289: invokeinterface #94,  3           // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     294: checkcast     #96                 // class java/lang/Number
     297: invokevirtual #99                 // Method java/lang/Number.intValue:()I
     300: ifge          309
     303: iinc          7, 1
     306: goto          278
     309: aload_3
     310: aload_0
     311: iload         8
     313: invokeinterface #84,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     318: aload         6
     320: invokeinterface #94,  3           // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     325: checkcast     #96                 // class java/lang/Number
     328: invokevirtual #99                 // Method java/lang/Number.intValue:()I
     331: ifle          257
     334: iinc          8, -1
     337: goto          309
     340: aload_3
     341: aload_0
     342: iload         4
     344: invokeinterface #84,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     349: aload         6
     351: invokeinterface #94,  3           // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     356: checkcast     #96                 // class java/lang/Number
     359: invokevirtual #99                 // Method java/lang/Number.intValue:()I
     362: ifne          376
     365: aload_0
     366: iload         4
     368: iload         8
     370: invokestatic  #88                 // Method swap:(Ljava/util/List;II)V
     373: goto          387
     376: iinc          8, 1
     379: aload_0
     380: iload         8
     382: iload         5
     384: invokestatic  #88                 // Method swap:(Ljava/util/List;II)V
     387: iload         8
     389: iload_2
     390: if_icmpgt     399
     393: iload         8
     395: iconst_1
     396: iadd
     397: istore        4
     399: iload_2
     400: iload         8
     402: if_icmpgt     30
     405: iload         8
     407: iconst_1
     408: isub
     409: istore        5
     411: goto          30
     414: return

  private static final <T> void swap(java.util.List<T>, int, int);
    Code:
       0: aload_0
       1: iload_1
       2: aload_0
       3: iload_2
       4: invokeinterface #84,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       9: astore_3
      10: aload_3
      11: astore        4
      13: istore        7
      15: astore        6
      17: iconst_0
      18: istore        5
      20: aload_0
      21: iload_2
      22: aload_0
      23: iload_1
      24: invokeinterface #84,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      29: invokeinterface #118,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      34: pop
      35: getstatic     #124                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      38: astore        8
      40: aload         6
      42: iload         7
      44: aload_3
      45: invokeinterface #118,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      50: pop
      51: return
}


package solution

/**
 * https://www.codewars.com/kata/54dc6f5a224c26032800005c/train/kotlin
 */
object StockList {
    fun stockSummary(lstOfArt: Array<String>, lstOfCat: Array<String>): String {
        if (lstOfArt.isEmpty()) {
            return ""
        }

        val stock = lstOfArt
            .map(::readOne)
            .groupBy { it.category }
            .map { (key, value) ->
                StockItem(key, value.sumOf { it.quantity })
            }
            .associateBy { it.category }

        return lstOfCat
            .map {
                stock[it] ?: StockItem(it, 0)
            }
            .joinToString(" - ") {
                "(${it.category} : ${it.quantity})"
            }
    }
}

data class StockItem(val category: String, val quantity: Int) {
}

val stockItemPattern = """([A-Z][A-Z0-9]+) ([0-9]+)""".toRegex()

fun readOne(input: String): StockItem {
    val match = stockItemPattern.matchEntire(input)
    val groups = match!!.groups

    val category = groups[1]!!.value
    val quantity = groups[2]!!.value

    return StockItem(category.take(1), quantity.toInt())
}

Compiled from "StockList.kt"
public final class solution.StockList {
  public static final solution.StockList INSTANCE;

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

  public final java.lang.String stockSummary(java.lang.String[], java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String lstOfArt
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String lstOfCat
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: arraylength
      14: ifne          21
      17: iconst_1
      18: goto          22
      21: iconst_0
      22: ifeq          28
      25: ldc           #25                 // String
      27: areturn
      28: aload_1
      29: astore        4
      31: nop
      32: iconst_0
      33: istore        5
      35: aload         4
      37: astore        6
      39: new           #27                 // class java/util/ArrayList
      42: dup
      43: aload         4
      45: arraylength
      46: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      49: checkcast     #32                 // class java/util/Collection
      52: astore        7
      54: iconst_0
      55: istore        8
      57: iconst_0
      58: istore        9
      60: aload         6
      62: arraylength
      63: istore        10
      65: iload         9
      67: iload         10
      69: if_icmpge     110
      72: aload         6
      74: iload         9
      76: aaload
      77: astore        11
      79: aload         7
      81: aload         11
      83: astore        12
      85: astore        25
      87: iconst_0
      88: istore        13
      90: aload         12
      92: invokestatic  #38                 // Method solution/StockListKt.readOne:(Ljava/lang/String;)Lsolution/StockItem;
      95: aload         25
      97: swap
      98: invokeinterface #42,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     103: pop
     104: iinc          9, 1
     107: goto          65
     110: aload         7
     112: checkcast     #44                 // class java/util/List
     115: nop
     116: checkcast     #46                 // class java/lang/Iterable
     119: astore        4
     121: nop
     122: iconst_0
     123: istore        5
     125: aload         4
     127: astore        6
     129: new           #48                 // class java/util/LinkedHashMap
     132: dup
     133: invokespecial #49                 // Method java/util/LinkedHashMap."<init>":()V
     136: checkcast     #51                 // class java/util/Map
     139: astore        7
     141: iconst_0
     142: istore        8
     144: aload         6
     146: invokeinterface #55,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     151: astore        9
     153: aload         9
     155: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     160: ifeq          265
     163: aload         9
     165: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     170: astore        10
     172: aload         10
     174: checkcast     #67                 // class solution/StockItem
     177: astore        11
     179: iconst_0
     180: istore        12
     182: aload         11
     184: invokevirtual #71                 // Method solution/StockItem.getCategory:()Ljava/lang/String;
     187: astore        13
     189: aload         7
     191: astore        14
     193: iconst_0
     194: istore        15
     196: aload         14
     198: aload         13
     200: invokeinterface #75,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     205: astore        16
     207: aload         16
     209: ifnonnull     244
     212: iconst_0
     213: istore        17
     215: new           #27                 // class java/util/ArrayList
     218: dup
     219: invokespecial #76                 // Method java/util/ArrayList."<init>":()V
     222: checkcast     #44                 // class java/util/List
     225: astore        17
     227: aload         14
     229: aload         13
     231: aload         17
     233: invokeinterface #80,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     238: pop
     239: aload         17
     241: goto          246
     244: aload         16
     246: nop
     247: checkcast     #44                 // class java/util/List
     250: astore        11
     252: aload         11
     254: aload         10
     256: invokeinterface #81,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     261: pop
     262: goto          153
     265: aload         7
     267: nop
     268: astore        4
     270: nop
     271: iconst_0
     272: istore        5
     274: aload         4
     276: astore        6
     278: new           #27                 // class java/util/ArrayList
     281: dup
     282: aload         4
     284: invokeinterface #85,  1           // InterfaceMethod java/util/Map.size:()I
     289: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     292: checkcast     #32                 // class java/util/Collection
     295: astore        7
     297: iconst_0
     298: istore        8
     300: aload         6
     302: invokeinterface #89,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     307: invokeinterface #92,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     312: astore        9
     314: aload         9
     316: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     321: ifeq          479
     324: aload         9
     326: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     331: checkcast     #94                 // class java/util/Map$Entry
     334: astore        10
     336: aload         7
     338: aload         10
     340: astore        11
     342: astore        25
     344: iconst_0
     345: istore        12
     347: aload         11
     349: invokeinterface #97,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     354: checkcast     #99                 // class java/lang/String
     357: astore        13
     359: aload         11
     361: invokeinterface #102,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     366: checkcast     #44                 // class java/util/List
     369: astore        14
     371: aload         13
     373: aload         14
     375: checkcast     #46                 // class java/lang/Iterable
     378: astore        15
     380: astore        16
     382: iconst_0
     383: istore        18
     385: aload         15
     387: invokeinterface #55,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     392: astore        19
     394: aload         19
     396: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     401: ifeq          444
     404: aload         19
     406: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     411: astore        20
     413: iload         18
     415: aload         20
     417: checkcast     #67                 // class solution/StockItem
     420: astore        21
     422: istore        22
     424: iconst_0
     425: istore        23
     427: aload         21
     429: invokevirtual #105                // Method solution/StockItem.getQuantity:()I
     432: istore        24
     434: iload         22
     436: iload         24
     438: iadd
     439: istore        18
     441: goto          394
     444: iload         18
     446: istore        22
     448: aload         16
     450: iload         22
     452: istore        26
     454: astore        27
     456: new           #67                 // class solution/StockItem
     459: dup
     460: aload         27
     462: iload         26
     464: invokespecial #108                // Method solution/StockItem."<init>":(Ljava/lang/String;I)V
     467: aload         25
     469: swap
     470: invokeinterface #42,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     475: pop
     476: goto          314
     479: aload         7
     481: checkcast     #44                 // class java/util/List
     484: nop
     485: checkcast     #46                 // class java/lang/Iterable
     488: astore        4
     490: nop
     491: iconst_0
     492: istore        5
     494: aload         4
     496: bipush        10
     498: invokestatic  #114                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     501: invokestatic  #120                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     504: bipush        16
     506: invokestatic  #126                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     509: istore        6
     511: aload         4
     513: astore        7
     515: new           #48                 // class java/util/LinkedHashMap
     518: dup
     519: iload         6
     521: invokespecial #127                // Method java/util/LinkedHashMap."<init>":(I)V
     524: checkcast     #51                 // class java/util/Map
     527: astore        8
     529: iconst_0
     530: istore        9
     532: aload         7
     534: invokeinterface #55,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     539: astore        10
     541: aload         10
     543: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     548: ifeq          593
     551: aload         10
     553: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     558: astore        11
     560: aload         8
     562: aload         11
     564: checkcast     #67                 // class solution/StockItem
     567: astore        12
     569: astore        25
     571: iconst_0
     572: istore        13
     574: aload         12
     576: invokevirtual #71                 // Method solution/StockItem.getCategory:()Ljava/lang/String;
     579: aload         25
     581: swap
     582: aload         11
     584: invokeinterface #80,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     589: pop
     590: goto          541
     593: aload         8
     595: nop
     596: astore_3
     597: aload_2
     598: astore        4
     600: nop
     601: iconst_0
     602: istore        5
     604: aload         4
     606: astore        6
     608: new           #27                 // class java/util/ArrayList
     611: dup
     612: aload         4
     614: arraylength
     615: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     618: checkcast     #32                 // class java/util/Collection
     621: astore        7
     623: iconst_0
     624: istore        8
     626: iconst_0
     627: istore        9
     629: aload         6
     631: arraylength
     632: istore        10
     634: iload         9
     636: iload         10
     638: if_icmpge     700
     641: aload         6
     643: iload         9
     645: aaload
     646: astore        11
     648: aload         7
     650: aload         11
     652: astore        12
     654: astore        25
     656: iconst_0
     657: istore        13
     659: aload_3
     660: aload         12
     662: invokeinterface #75,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     667: checkcast     #67                 // class solution/StockItem
     670: dup
     671: ifnonnull     685
     674: pop
     675: new           #67                 // class solution/StockItem
     678: dup
     679: aload         12
     681: iconst_0
     682: invokespecial #108                // Method solution/StockItem."<init>":(Ljava/lang/String;I)V
     685: aload         25
     687: swap
     688: invokeinterface #42,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     693: pop
     694: iinc          9, 1
     697: goto          634
     700: aload         7
     702: checkcast     #44                 // class java/util/List
     705: nop
     706: checkcast     #46                 // class java/lang/Iterable
     709: ldc           #129                // String  -
     711: checkcast     #131                // class java/lang/CharSequence
     714: aconst_null
     715: aconst_null
     716: iconst_0
     717: aconst_null
     718: invokedynamic #149,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     723: bipush        30
     725: aconst_null
     726: invokestatic  #153                // 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;
     729: areturn

  private static final java.lang.CharSequence stockSummary$lambda$5(solution.StockItem);
    Code:
       0: aload_0
       1: ldc           #200                // String it
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #202                // class java/lang/StringBuilder
       9: dup
      10: invokespecial #203                // Method java/lang/StringBuilder."<init>":()V
      13: bipush        40
      15: invokevirtual #207                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      18: aload_0
      19: invokevirtual #71                 // Method solution/StockItem.getCategory:()Ljava/lang/String;
      22: invokevirtual #210                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      25: ldc           #212                // String  :
      27: invokevirtual #210                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      30: aload_0
      31: invokevirtual #105                // Method solution/StockItem.getQuantity:()I
      34: invokevirtual #215                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      37: bipush        41
      39: invokevirtual #207                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      42: invokevirtual #218                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      45: checkcast     #131                // class java/lang/CharSequence
      48: areturn

  static {};
    Code:
       0: new           #2                  // class solution/StockList
       3: dup
       4: invokespecial #220                // Method "<init>":()V
       7: putstatic     #223                // Field INSTANCE:Lsolution/StockList;
      10: return
}

Compiled from "StockList.kt"
public final class solution.StockListKt {
  private static final kotlin.text.Regex stockItemPattern;

  public static final kotlin.text.Regex getStockItemPattern();
    Code:
       0: getstatic     #11                 // Field stockItemPattern:Lkotlin/text/Regex;
       3: areturn

  public static final solution.StockItem readOne(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #15                 // String input
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: getstatic     #11                 // Field stockItemPattern:Lkotlin/text/Regex;
       9: aload_0
      10: checkcast     #23                 // class java/lang/CharSequence
      13: invokevirtual #29                 // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
      16: astore_1
      17: aload_1
      18: dup
      19: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      22: invokeinterface #39,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
      27: astore_2
      28: aload_2
      29: iconst_1
      30: invokeinterface #45,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
      35: dup
      36: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      39: invokevirtual #51                 // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
      42: astore_3
      43: aload_2
      44: iconst_2
      45: invokeinterface #45,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
      50: dup
      51: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      54: invokevirtual #51                 // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
      57: astore        4
      59: new           #53                 // class solution/StockItem
      62: dup
      63: aload_3
      64: iconst_1
      65: invokestatic  #59                 // Method kotlin/text/StringsKt.take:(Ljava/lang/String;I)Ljava/lang/String;
      68: aload         4
      70: invokestatic  #65                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      73: invokespecial #69                 // Method solution/StockItem."<init>":(Ljava/lang/String;I)V
      76: areturn

  static {};
    Code:
       0: new           #25                 // class kotlin/text/Regex
       3: dup
       4: ldc           #80                 // String ([A-Z][A-Z0-9]+) ([0-9]+)
       6: invokespecial #83                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: putstatic     #11                 // Field stockItemPattern:Lkotlin/text/Regex;
      12: return
}


package org.aoc2021

import java.nio.file.Files
import java.nio.file.Path
import java.util.PriorityQueue

object Day15 {
    data class RiskPath(val currentCost: Int, val row: Int, val col: Int)

    private fun solve(lines: List<String>, shouldExpandGrid: Boolean = false): Int {
        val rawGrid = parseLines(lines)
        val grid = if (shouldExpandGrid) expandGrid(rawGrid) else rawGrid

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

        pq.add(RiskPath(0, 0, 0))

        val directions = listOf(-1 to 0, 1 to 0, 0 to -1, 0 to 1)

        val minCosts = mutableMapOf<Pair<Int, Int>, Int>()
        minCosts[0 to 0] = 0

        while (true) {
            val top = pq.remove()!!

            if (top.row == grid.size - 1 && top.col == grid[0].size - 1) {
                return top.currentCost
            }

            directions.forEach { (dx, dy) ->
                val x = top.row + dx
                val y = top.col + dy
                if (x >= 0 && x < grid.size && y >= 0 && y < grid[0].size) {
                    val newCost = top.currentCost + grid[x][y]
                    if (newCost < (minCosts[x to y] ?: Integer.MAX_VALUE)) {
                        pq.add(RiskPath(newCost, x, y))
                        minCosts[x to y] = newCost
                    }
                }
            }
        }
    }

    private fun parseLines(lines: List<String>): List<List<Int>> {
        return lines.map { line ->
            line.map(Char::digitToInt)
        }
    }

    private fun expandGrid(grid: List<List<Int>>): List<List<Int>> {
        val newGrid = Array(grid.size * 5) { Array(grid[0].size * 5) { 0 } }

        for (i in grid.indices) {
            for (j in grid[0].indices) {
                for (k in 0 until 5) {
                    for (x in 0 until 5) {
                        val ni = i + grid.size * k
                        val nj = j + grid[0].size * x
                        newGrid[ni][nj] = grid[i][j] + k + x
                        while (newGrid[ni][nj] > 9) {
                            newGrid[ni][nj] -= 9
                        }
                    }
                }
            }
        }

        return newGrid.map(Array<Int>::toList)
    }

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

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

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

  private final int solve(java.util.List<java.lang.String>, boolean);
    Code:
       0: aload_0
       1: aload_1
       2: invokespecial #17                 // Method parseLines:(Ljava/util/List;)Ljava/util/List;
       5: astore_3
       6: iload_2
       7: ifeq          18
      10: aload_0
      11: aload_3
      12: invokespecial #20                 // Method expandGrid:(Ljava/util/List;)Ljava/util/List;
      15: goto          19
      18: aload_3
      19: astore        4
      21: new           #22                 // class java/util/PriorityQueue
      24: dup
      25: invokedynamic #42,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
      30: invokedynamic #53,  0             // InvokeDynamic #1:compare:(Lkotlin/jvm/functions/Function2;)Ljava/util/Comparator;
      35: invokespecial #56                 // Method java/util/PriorityQueue."<init>":(Ljava/util/Comparator;)V
      38: astore        5
      40: aload         5
      42: new           #58                 // class org/aoc2021/Day15$RiskPath
      45: dup
      46: iconst_0
      47: iconst_0
      48: iconst_0
      49: invokespecial #61                 // Method org/aoc2021/Day15$RiskPath."<init>":(III)V
      52: invokevirtual #65                 // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
      55: pop
      56: iconst_4
      57: anewarray     #67                 // class kotlin/Pair
      60: astore        7
      62: aload         7
      64: iconst_0
      65: iconst_m1
      66: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      69: iconst_0
      70: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      73: invokestatic  #79                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      76: aastore
      77: aload         7
      79: iconst_1
      80: iconst_1
      81: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      84: iconst_0
      85: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: invokestatic  #79                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      91: aastore
      92: aload         7
      94: iconst_2
      95: iconst_0
      96: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: iconst_m1
     100: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     103: invokestatic  #79                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     106: aastore
     107: aload         7
     109: iconst_3
     110: iconst_0
     111: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: iconst_1
     115: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     118: invokestatic  #79                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     121: aastore
     122: aload         7
     124: invokestatic  #85                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     127: astore        6
     129: new           #87                 // class java/util/LinkedHashMap
     132: dup
     133: invokespecial #88                 // Method java/util/LinkedHashMap."<init>":()V
     136: checkcast     #90                 // class java/util/Map
     139: astore        7
     141: aload         7
     143: iconst_0
     144: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     147: iconst_0
     148: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     151: invokestatic  #79                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     154: iconst_0
     155: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     158: invokeinterface #93,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     163: pop
     164: nop
     165: aload         5
     167: invokevirtual #97                 // Method java/util/PriorityQueue.remove:()Ljava/lang/Object;
     170: dup
     171: invokestatic  #103                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     174: checkcast     #58                 // class org/aoc2021/Day15$RiskPath
     177: astore        8
     179: aload         8
     181: invokevirtual #107                // Method org/aoc2021/Day15$RiskPath.getRow:()I
     184: aload         4
     186: invokeinterface #112,  1          // InterfaceMethod java/util/List.size:()I
     191: iconst_1
     192: isub
     193: if_icmpne     228
     196: aload         8
     198: invokevirtual #115                // Method org/aoc2021/Day15$RiskPath.getCol:()I
     201: aload         4
     203: iconst_0
     204: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     209: checkcast     #109                // class java/util/List
     212: invokeinterface #112,  1          // InterfaceMethod java/util/List.size:()I
     217: iconst_1
     218: isub
     219: if_icmpne     228
     222: aload         8
     224: invokevirtual #122                // Method org/aoc2021/Day15$RiskPath.getCurrentCost:()I
     227: ireturn
     228: aload         6
     230: checkcast     #124                // class java/lang/Iterable
     233: astore        9
     235: iconst_0
     236: istore        10
     238: aload         9
     240: invokeinterface #128,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     245: astore        11
     247: aload         11
     249: invokeinterface #134,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     254: ifeq          493
     257: aload         11
     259: invokeinterface #137,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     264: astore        12
     266: aload         12
     268: checkcast     #67                 // class kotlin/Pair
     271: astore        13
     273: iconst_0
     274: istore        14
     276: aload         13
     278: invokevirtual #140                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     281: checkcast     #142                // class java/lang/Number
     284: invokevirtual #145                // Method java/lang/Number.intValue:()I
     287: istore        15
     289: aload         13
     291: invokevirtual #148                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     294: checkcast     #142                // class java/lang/Number
     297: invokevirtual #145                // Method java/lang/Number.intValue:()I
     300: istore        16
     302: aload         8
     304: invokevirtual #107                // Method org/aoc2021/Day15$RiskPath.getRow:()I
     307: iload         15
     309: iadd
     310: istore        17
     312: aload         8
     314: invokevirtual #115                // Method org/aoc2021/Day15$RiskPath.getCol:()I
     317: iload         16
     319: iadd
     320: istore        18
     322: iload         17
     324: iflt          488
     327: iload         17
     329: aload         4
     331: invokeinterface #112,  1          // InterfaceMethod java/util/List.size:()I
     336: if_icmpge     488
     339: iload         18
     341: iflt          488
     344: iload         18
     346: aload         4
     348: iconst_0
     349: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     354: checkcast     #109                // class java/util/List
     357: invokeinterface #112,  1          // InterfaceMethod java/util/List.size:()I
     362: if_icmpge     488
     365: aload         8
     367: invokevirtual #122                // Method org/aoc2021/Day15$RiskPath.getCurrentCost:()I
     370: aload         4
     372: iload         17
     374: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     379: checkcast     #109                // class java/util/List
     382: iload         18
     384: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     389: checkcast     #142                // class java/lang/Number
     392: invokevirtual #145                // Method java/lang/Number.intValue:()I
     395: iadd
     396: istore        19
     398: iload         19
     400: aload         7
     402: iload         17
     404: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     407: iload         18
     409: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     412: invokestatic  #79                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     415: invokeinterface #151,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     420: checkcast     #69                 // class java/lang/Integer
     423: dup
     424: ifnull        433
     427: invokevirtual #152                // Method java/lang/Integer.intValue:()I
     430: goto          436
     433: pop
     434: ldc           #153                // int 2147483647
     436: if_icmpge     488
     439: aload         5
     441: new           #58                 // class org/aoc2021/Day15$RiskPath
     444: dup
     445: iload         19
     447: iload         17
     449: iload         18
     451: invokespecial #61                 // Method org/aoc2021/Day15$RiskPath."<init>":(III)V
     454: invokevirtual #65                 // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
     457: pop
     458: iload         19
     460: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     463: astore        20
     465: aload         7
     467: iload         17
     469: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     472: iload         18
     474: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     477: invokestatic  #79                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     480: aload         20
     482: invokeinterface #93,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     487: pop
     488: nop
     489: nop
     490: goto          247
     493: nop
     494: goto          164

  static int solve$default(org.aoc2021.Day15, java.util.List, boolean, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_2
       8: aload_0
       9: aload_1
      10: iload_2
      11: invokespecial #182                // Method solve:(Ljava/util/List;Z)I
      14: ireturn

  private final java.util.List<java.util.List<java.lang.Integer>> parseLines(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #124                // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: astore        4
      10: new           #185                // class java/util/ArrayList
      13: dup
      14: aload_2
      15: bipush        10
      17: invokestatic  #189                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      20: invokespecial #192                // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #194                // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        6
      31: aload         4
      33: invokeinterface #128,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        7
      40: aload         7
      42: invokeinterface #134,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          188
      50: aload         7
      52: invokeinterface #137,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        8
      59: aload         5
      61: aload         8
      63: checkcast     #196                // class java/lang/String
      66: astore        9
      68: astore        21
      70: iconst_0
      71: istore        10
      73: aload         9
      75: checkcast     #198                // class java/lang/CharSequence
      78: astore        11
      80: iconst_0
      81: istore        12
      83: aload         11
      85: astore        13
      87: new           #185                // class java/util/ArrayList
      90: dup
      91: aload         11
      93: invokeinterface #201,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      98: invokespecial #192                // Method java/util/ArrayList."<init>":(I)V
     101: checkcast     #194                // class java/util/Collection
     104: astore        14
     106: iconst_0
     107: istore        15
     109: iconst_0
     110: istore        16
     112: iload         16
     114: aload         13
     116: invokeinterface #201,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     121: if_icmpge     169
     124: aload         13
     126: iload         16
     128: invokeinterface #205,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     133: istore        17
     135: aload         14
     137: iload         17
     139: istore        18
     141: astore        19
     143: iconst_0
     144: istore        20
     146: iload         18
     148: invokestatic  #211                // Method kotlin/text/CharsKt.digitToInt:(C)I
     151: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: aload         19
     156: swap
     157: invokeinterface #212,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     162: pop
     163: iinc          16, 1
     166: goto          112
     169: aload         14
     171: checkcast     #109                // class java/util/List
     174: nop
     175: nop
     176: aload         21
     178: swap
     179: invokeinterface #212,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     184: pop
     185: goto          40
     188: aload         5
     190: checkcast     #109                // class java/util/List
     193: nop
     194: areturn

  private final java.util.List<java.util.List<java.lang.Integer>> expandGrid(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: iconst_0
       1: istore_3
       2: aload_1
       3: invokeinterface #112,  1          // InterfaceMethod java/util/List.size:()I
       8: iconst_5
       9: imul
      10: istore        4
      12: iload         4
      14: anewarray     #229                // class "[Ljava/lang/Integer;"
      17: astore        5
      19: iload_3
      20: iload         4
      22: if_icmpge     104
      25: iload_3
      26: istore        6
      28: aload         5
      30: iload         6
      32: iconst_0
      33: istore        7
      35: aload_1
      36: iconst_0
      37: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      42: checkcast     #109                // class java/util/List
      45: invokeinterface #112,  1          // InterfaceMethod java/util/List.size:()I
      50: iconst_5
      51: imul
      52: istore        8
      54: iload         8
      56: anewarray     #69                 // class java/lang/Integer
      59: astore        9
      61: istore        14
      63: astore        13
      65: iload         7
      67: iload         8
      69: if_icmpge     91
      72: iload         7
      74: istore        10
      76: aload         9
      78: iload         10
      80: iconst_0
      81: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      84: aastore
      85: iinc          7, 1
      88: goto          65
      91: aload         13
      93: iload         14
      95: aload         9
      97: aastore
      98: iinc          3, 1
     101: goto          19
     104: aload         5
     106: astore_2
     107: iconst_0
     108: istore_3
     109: aload_1
     110: checkcast     #194                // class java/util/Collection
     113: invokeinterface #230,  1          // InterfaceMethod java/util/Collection.size:()I
     118: istore        4
     120: iload_3
     121: iload         4
     123: if_icmpge     313
     126: iconst_0
     127: istore        5
     129: aload_1
     130: iconst_0
     131: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     136: checkcast     #194                // class java/util/Collection
     139: invokeinterface #230,  1          // InterfaceMethod java/util/Collection.size:()I
     144: istore        6
     146: iload         5
     148: iload         6
     150: if_icmpge     307
     153: iconst_0
     154: istore        7
     156: iload         7
     158: iconst_5
     159: if_icmpge     301
     162: iconst_0
     163: istore        8
     165: iload         8
     167: iconst_5
     168: if_icmpge     295
     171: iload_3
     172: aload_1
     173: invokeinterface #112,  1          // InterfaceMethod java/util/List.size:()I
     178: iload         7
     180: imul
     181: iadd
     182: istore        9
     184: iload         5
     186: aload_1
     187: iconst_0
     188: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     193: checkcast     #109                // class java/util/List
     196: invokeinterface #112,  1          // InterfaceMethod java/util/List.size:()I
     201: iload         8
     203: imul
     204: iadd
     205: istore        10
     207: aload_2
     208: iload         9
     210: aaload
     211: iload         10
     213: aload_1
     214: iload_3
     215: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     220: checkcast     #109                // class java/util/List
     223: iload         5
     225: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     230: checkcast     #142                // class java/lang/Number
     233: invokevirtual #145                // Method java/lang/Number.intValue:()I
     236: iload         7
     238: iadd
     239: iload         8
     241: iadd
     242: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     245: aastore
     246: aload_2
     247: iload         9
     249: aaload
     250: iload         10
     252: aaload
     253: invokevirtual #152                // Method java/lang/Integer.intValue:()I
     256: bipush        9
     258: if_icmple     289
     261: aload_2
     262: iload         9
     264: aaload
     265: astore        11
     267: aload         11
     269: iload         10
     271: aload         11
     273: iload         10
     275: aaload
     276: invokevirtual #152                // Method java/lang/Integer.intValue:()I
     279: bipush        9
     281: isub
     282: invokestatic  #73                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     285: aastore
     286: goto          246
     289: iinc          8, 1
     292: goto          165
     295: iinc          7, 1
     298: goto          156
     301: iinc          5, 1
     304: goto          146
     307: iinc          3, 1
     310: goto          120
     313: aload_2
     314: checkcast     #232                // class "[Ljava/lang/Object;"
     317: astore_3
     318: iconst_0
     319: istore        4
     321: aload_3
     322: astore        5
     324: new           #185                // class java/util/ArrayList
     327: dup
     328: aload_3
     329: arraylength
     330: invokespecial #192                // Method java/util/ArrayList."<init>":(I)V
     333: checkcast     #194                // class java/util/Collection
     336: astore        6
     338: iconst_0
     339: istore        7
     341: iconst_0
     342: istore        8
     344: aload         5
     346: arraylength
     347: istore        9
     349: iload         8
     351: iload         9
     353: if_icmpge     397
     356: aload         5
     358: iload         8
     360: aaload
     361: astore        10
     363: aload         6
     365: aload         10
     367: checkcast     #229                // class "[Ljava/lang/Integer;"
     370: astore        11
     372: astore        13
     374: iconst_0
     375: istore        12
     377: aload         11
     379: invokestatic  #237                // Method kotlin/collections/ArraysKt.toList:([Ljava/lang/Object;)Ljava/util/List;
     382: aload         13
     384: swap
     385: invokeinterface #212,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     390: pop
     391: iinc          8, 1
     394: goto          349
     397: aload         6
     399: checkcast     #109                // class java/util/List
     402: nop
     403: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #252                // String args
       3: invokestatic  #256                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc_w         #258                // String input15.txt
       9: iconst_0
      10: anewarray     #196                // class java/lang/String
      13: invokestatic  #264                // InterfaceMethod java/nio/file/Path.of:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
      16: getstatic     #270                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      19: invokestatic  #276                // Method java/nio/file/Files.readAllLines:(Ljava/nio/file/Path;Ljava/nio/charset/Charset;)Ljava/util/List;
      22: astore_1
      23: getstatic     #279                // Field INSTANCE:Lorg/aoc2021/Day15;
      26: aload_1
      27: invokestatic  #103                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      30: aload_1
      31: iconst_0
      32: invokespecial #182                // Method solve:(Ljava/util/List;Z)I
      35: istore_2
      36: getstatic     #285                // Field java/lang/System.out:Ljava/io/PrintStream;
      39: iload_2
      40: invokevirtual #290                // Method java/io/PrintStream.println:(I)V
      43: getstatic     #279                // Field INSTANCE:Lorg/aoc2021/Day15;
      46: aload_1
      47: iconst_1
      48: invokespecial #182                // Method solve:(Ljava/util/List;Z)I
      51: istore_3
      52: getstatic     #285                // Field java/lang/System.out:Ljava/io/PrintStream;
      55: iload_3
      56: invokevirtual #290                // Method java/io/PrintStream.println:(I)V
      59: return

  private static final int solve$lambda$0(org.aoc2021.Day15$RiskPath, org.aoc2021.Day15$RiskPath);
    Code:
       0: aload_0
       1: invokevirtual #122                // Method org/aoc2021/Day15$RiskPath.getCurrentCost:()I
       4: aload_1
       5: invokevirtual #122                // Method org/aoc2021/Day15$RiskPath.getCurrentCost:()I
       8: invokestatic  #296                // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      11: ireturn

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

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

Compiled from "Day15.kt"
public final class org.aoc2021.Day15$RiskPath {
  private final int currentCost;

  private final int row;

  private final int col;

  public org.aoc2021.Day15$RiskPath(int, int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field currentCost:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field row:I
      14: aload_0
      15: iload_3
      16: putfield      #19                 // Field col:I
      19: return

  public final int getCurrentCost();
    Code:
       0: aload_0
       1: getfield      #13                 // Field currentCost:I
       4: ireturn

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

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

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

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

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

  public final org.aoc2021.Day15$RiskPath copy(int, int, int);
    Code:
       0: new           #2                  // class org/aoc2021/Day15$RiskPath
       3: dup
       4: iload_1
       5: iload_2
       6: iload_3
       7: invokespecial #33                 // Method "<init>":(III)V
      10: areturn

  public static org.aoc2021.Day15$RiskPath copy$default(org.aoc2021.Day15$RiskPath, int, int, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #13                 // Field currentCost:I
      11: istore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #16                 // Field row:I
      23: istore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #19                 // Field col:I
      35: istore_3
      36: aload_0
      37: iload_1
      38: iload_2
      39: iload_3
      40: invokevirtual #37                 // Method copy:(III)Lorg/aoc2021/Day15$RiskPath;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #41                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #44                 // String RiskPath(currentCost=
       9: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field currentCost:I
      16: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #53                 // String , row=
      21: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field row:I
      28: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #55                 // String , col=
      33: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #19                 // Field col:I
      40: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #58                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #60                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field currentCost:I
       4: invokestatic  #66                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field row:I
      16: invokestatic  #66                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #19                 // Field col:I
      29: invokestatic  #66                 // Method java/lang/Integer.hashCode:(I)I
      32: iadd
      33: istore_1
      34: iload_1
      35: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class org/aoc2021/Day15$RiskPath
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class org/aoc2021/Day15$RiskPath
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field currentCost:I
      25: aload_2
      26: getfield      #13                 // Field currentCost:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field row:I
      38: aload_2
      39: getfield      #16                 // Field row:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: getfield      #19                 // Field col:I
      51: aload_2
      52: getfield      #19                 // Field col:I
      55: if_icmpeq     60
      58: iconst_0
      59: ireturn
      60: iconst_1
      61: ireturn
}