package day5

import java.io.File

typealias Coordinates = Pair<Int, Int>
typealias Matrix = Map<Coordinates, Int>

private val regex = """(\d+),(\d+) -> (\d+),(\d+)""".toRegex()

fun parseLine(line: String): List<Int> =
  regex.matchEntire(line)!!
    .groupValues.drop(1) // dropping first item because it's the whole line
    .map(String::toInt)

private fun expandRange(start: Int, end: Int) = if (start <= end) start.rangeTo(end) else start.downTo(end)

// required for part 1
fun expandSegmentRangeWithoutDiagonals(x1: Int, y1: Int, x2: Int, y2: Int): Iterable<Coordinates> = when {
  x1 == x2 -> expandRange(y1, y2).map { x1 to it }
  y1 == y2 -> expandRange(x1, x2).map { it to y1 }
  else -> emptyList() // ignore
}

fun expandSegmentRange(x1: Int, y1: Int, x2: Int, y2: Int): Iterable<Coordinates> = when {
  x1 == x2 -> expandRange(y1, y2).map { x1 to it }
  y1 == y2 -> expandRange(x1, x2).map { it to y1 }
  else -> expandRange(x1, x2).zip(expandRange(y1, y2)) // diagonal, update both coordinates
}

fun buildMatrix(segments: List<String>): Matrix =
  segments
    .map { segment -> parseLine(segment) }
    .flatMap { (x1, y1, x2, y2) -> expandSegmentRange(x1, y1, x2, y2) }
    .groupingBy { it }.eachCount()

fun countCloudSegmentOverlappingPoints(matrix: Matrix): Int = matrix.values.count { it > 1 }

fun main() {
  File("./input/day5.txt").useLines { lines ->
    val matrix = buildMatrix(lines.toList())
    println(countCloudSegmentOverlappingPoints(matrix))
  }
}

Compiled from "_Collections.kt"
public final class day5.Day5Kt$buildMatrix$$inlined$groupingBy$1 implements kotlin.collections.Grouping<kotlin.Pair<? extends java.lang.Integer, ? extends java.lang.Integer>, kotlin.Pair<? extends java.lang.Integer, ? extends java.lang.Integer>> {
  final java.lang.Iterable $this_groupingBy;

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

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

  public kotlin.Pair<? extends java.lang.Integer, ? extends java.lang.Integer> keyOf(kotlin.Pair<? extends java.lang.Integer, ? extends java.lang.Integer>);
    Code:
       0: aload_1
       1: checkcast     #37                 // class kotlin/Pair
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: areturn
}

Compiled from "Day5.kt"
public final class day5.Day5Kt {
  private static final kotlin.text.Regex regex;

  public static final java.util.List<java.lang.Integer> parseLine(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String line
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: getstatic     #20                 // Field regex:Lkotlin/text/Regex;
       9: aload_0
      10: checkcast     #22                 // class java/lang/CharSequence
      13: invokevirtual #28                 // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
      16: dup
      17: invokestatic  #32                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      20: invokeinterface #38,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      25: checkcast     #40                 // class java/lang/Iterable
      28: iconst_1
      29: invokestatic  #46                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      32: checkcast     #40                 // class java/lang/Iterable
      35: astore_1
      36: nop
      37: iconst_0
      38: istore_2
      39: aload_1
      40: astore_3
      41: new           #48                 // class java/util/ArrayList
      44: dup
      45: aload_1
      46: bipush        10
      48: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      51: invokespecial #56                 // Method java/util/ArrayList."<init>":(I)V
      54: checkcast     #58                 // class java/util/Collection
      57: astore        4
      59: iconst_0
      60: istore        5
      62: aload_3
      63: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      68: astore        6
      70: aload         6
      72: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      77: ifeq          124
      80: aload         6
      82: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      87: astore        7
      89: aload         4
      91: aload         7
      93: checkcast     #74                 // class java/lang/String
      96: astore        8
      98: astore        10
     100: iconst_0
     101: istore        9
     103: aload         8
     105: invokestatic  #80                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     108: nop
     109: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: aload         10
     114: swap
     115: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     120: pop
     121: goto          70
     124: aload         4
     126: checkcast     #90                 // class java/util/List
     129: nop
     130: areturn

  private static final kotlin.ranges.IntProgression expandRange(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: if_icmpgt     20
       5: new           #107                // class kotlin/ranges/IntRange
       8: dup
       9: iload_0
      10: iload_1
      11: invokespecial #110                // Method kotlin/ranges/IntRange."<init>":(II)V
      14: checkcast     #112                // class kotlin/ranges/IntProgression
      17: goto          25
      20: iload_0
      21: iload_1
      22: invokestatic  #117                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      25: areturn

  public static final java.lang.Iterable<kotlin.Pair<java.lang.Integer, java.lang.Integer>> expandSegmentRangeWithoutDiagonals(int, int, int, int);
    Code:
       0: nop
       1: iload_0
       2: iload_2
       3: if_icmpne     121
       6: iload_1
       7: iload_3
       8: invokestatic  #124                // Method expandRange:(II)Lkotlin/ranges/IntProgression;
      11: checkcast     #40                 // class java/lang/Iterable
      14: astore        4
      16: iconst_0
      17: istore        5
      19: aload         4
      21: astore        6
      23: new           #48                 // class java/util/ArrayList
      26: dup
      27: aload         4
      29: bipush        10
      31: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #56                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #58                 // class java/util/Collection
      40: astore        7
      42: iconst_0
      43: istore        8
      45: aload         6
      47: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        9
      54: aload         9
      56: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          109
      64: aload         9
      66: checkcast     #126                // class kotlin/collections/IntIterator
      69: invokevirtual #130                // Method kotlin/collections/IntIterator.nextInt:()I
      72: istore        10
      74: aload         7
      76: iload         10
      78: istore        11
      80: astore        13
      82: iconst_0
      83: istore        12
      85: iload_0
      86: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      89: iload         11
      91: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: invokestatic  #136                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      97: aload         13
      99: swap
     100: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     105: pop
     106: goto          54
     109: aload         7
     111: checkcast     #90                 // class java/util/List
     114: nop
     115: checkcast     #40                 // class java/lang/Iterable
     118: goto          247
     121: iload_1
     122: iload_3
     123: if_icmpne     241
     126: iload_0
     127: iload_2
     128: invokestatic  #124                // Method expandRange:(II)Lkotlin/ranges/IntProgression;
     131: checkcast     #40                 // class java/lang/Iterable
     134: astore        4
     136: iconst_0
     137: istore        5
     139: aload         4
     141: astore        6
     143: new           #48                 // class java/util/ArrayList
     146: dup
     147: aload         4
     149: bipush        10
     151: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     154: invokespecial #56                 // Method java/util/ArrayList."<init>":(I)V
     157: checkcast     #58                 // class java/util/Collection
     160: astore        7
     162: iconst_0
     163: istore        8
     165: aload         6
     167: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     172: astore        9
     174: aload         9
     176: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     181: ifeq          229
     184: aload         9
     186: checkcast     #126                // class kotlin/collections/IntIterator
     189: invokevirtual #130                // Method kotlin/collections/IntIterator.nextInt:()I
     192: istore        10
     194: aload         7
     196: iload         10
     198: istore        11
     200: astore        13
     202: iconst_0
     203: istore        12
     205: iload         11
     207: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     210: iload_1
     211: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     214: invokestatic  #136                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     217: aload         13
     219: swap
     220: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     225: pop
     226: goto          174
     229: aload         7
     231: checkcast     #90                 // class java/util/List
     234: nop
     235: checkcast     #40                 // class java/lang/Iterable
     238: goto          247
     241: invokestatic  #139                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     244: checkcast     #40                 // class java/lang/Iterable
     247: areturn

  public static final java.lang.Iterable<kotlin.Pair<java.lang.Integer, java.lang.Integer>> expandSegmentRange(int, int, int, int);
    Code:
       0: nop
       1: iload_0
       2: iload_2
       3: if_icmpne     121
       6: iload_1
       7: iload_3
       8: invokestatic  #124                // Method expandRange:(II)Lkotlin/ranges/IntProgression;
      11: checkcast     #40                 // class java/lang/Iterable
      14: astore        4
      16: iconst_0
      17: istore        5
      19: aload         4
      21: astore        6
      23: new           #48                 // class java/util/ArrayList
      26: dup
      27: aload         4
      29: bipush        10
      31: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #56                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #58                 // class java/util/Collection
      40: astore        7
      42: iconst_0
      43: istore        8
      45: aload         6
      47: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        9
      54: aload         9
      56: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          109
      64: aload         9
      66: checkcast     #126                // class kotlin/collections/IntIterator
      69: invokevirtual #130                // Method kotlin/collections/IntIterator.nextInt:()I
      72: istore        10
      74: aload         7
      76: iload         10
      78: istore        11
      80: astore        13
      82: iconst_0
      83: istore        12
      85: iload_0
      86: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      89: iload         11
      91: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: invokestatic  #136                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      97: aload         13
      99: swap
     100: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     105: pop
     106: goto          54
     109: aload         7
     111: checkcast     #90                 // class java/util/List
     114: nop
     115: checkcast     #40                 // class java/lang/Iterable
     118: goto          263
     121: iload_1
     122: iload_3
     123: if_icmpne     241
     126: iload_0
     127: iload_2
     128: invokestatic  #124                // Method expandRange:(II)Lkotlin/ranges/IntProgression;
     131: checkcast     #40                 // class java/lang/Iterable
     134: astore        4
     136: iconst_0
     137: istore        5
     139: aload         4
     141: astore        6
     143: new           #48                 // class java/util/ArrayList
     146: dup
     147: aload         4
     149: bipush        10
     151: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     154: invokespecial #56                 // Method java/util/ArrayList."<init>":(I)V
     157: checkcast     #58                 // class java/util/Collection
     160: astore        7
     162: iconst_0
     163: istore        8
     165: aload         6
     167: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     172: astore        9
     174: aload         9
     176: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     181: ifeq          229
     184: aload         9
     186: checkcast     #126                // class kotlin/collections/IntIterator
     189: invokevirtual #130                // Method kotlin/collections/IntIterator.nextInt:()I
     192: istore        10
     194: aload         7
     196: iload         10
     198: istore        11
     200: astore        13
     202: iconst_0
     203: istore        12
     205: iload         11
     207: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     210: iload_1
     211: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     214: invokestatic  #136                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     217: aload         13
     219: swap
     220: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     225: pop
     226: goto          174
     229: aload         7
     231: checkcast     #90                 // class java/util/List
     234: nop
     235: checkcast     #40                 // class java/lang/Iterable
     238: goto          263
     241: iload_0
     242: iload_2
     243: invokestatic  #124                // Method expandRange:(II)Lkotlin/ranges/IntProgression;
     246: checkcast     #40                 // class java/lang/Iterable
     249: iload_1
     250: iload_3
     251: invokestatic  #124                // Method expandRange:(II)Lkotlin/ranges/IntProgression;
     254: checkcast     #40                 // class java/lang/Iterable
     257: invokestatic  #151                // Method kotlin/collections/CollectionsKt.zip:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
     260: checkcast     #40                 // class java/lang/Iterable
     263: areturn

  public static final java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.lang.Integer> buildMatrix(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #158                // String segments
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #40                 // class java/lang/Iterable
      10: astore_1
      11: nop
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #48                 // class java/util/ArrayList
      19: dup
      20: aload_1
      21: bipush        10
      23: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #56                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #58                 // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload_3
      38: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        6
      45: aload         6
      47: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          95
      55: aload         6
      57: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        7
      64: aload         4
      66: aload         7
      68: checkcast     #74                 // class java/lang/String
      71: astore        8
      73: astore        14
      75: iconst_0
      76: istore        9
      78: aload         8
      80: invokestatic  #160                // Method parseLine:(Ljava/lang/String;)Ljava/util/List;
      83: aload         14
      85: swap
      86: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: goto          45
      95: aload         4
      97: checkcast     #90                 // class java/util/List
     100: nop
     101: checkcast     #40                 // class java/lang/Iterable
     104: astore_1
     105: nop
     106: iconst_0
     107: istore_2
     108: aload_1
     109: astore_3
     110: new           #48                 // class java/util/ArrayList
     113: dup
     114: invokespecial #163                // Method java/util/ArrayList."<init>":()V
     117: checkcast     #58                 // class java/util/Collection
     120: astore        4
     122: iconst_0
     123: istore        5
     125: aload_3
     126: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     131: astore        6
     133: aload         6
     135: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     140: ifeq          250
     143: aload         6
     145: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     150: astore        7
     152: aload         7
     154: checkcast     #90                 // class java/util/List
     157: astore        8
     159: iconst_0
     160: istore        9
     162: aload         8
     164: iconst_0
     165: invokeinterface #167,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     170: checkcast     #169                // class java/lang/Number
     173: invokevirtual #172                // Method java/lang/Number.intValue:()I
     176: istore        10
     178: aload         8
     180: iconst_1
     181: invokeinterface #167,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: checkcast     #169                // class java/lang/Number
     189: invokevirtual #172                // Method java/lang/Number.intValue:()I
     192: istore        11
     194: aload         8
     196: iconst_2
     197: invokeinterface #167,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     202: checkcast     #169                // class java/lang/Number
     205: invokevirtual #172                // Method java/lang/Number.intValue:()I
     208: istore        12
     210: aload         8
     212: iconst_3
     213: invokeinterface #167,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     218: checkcast     #169                // class java/lang/Number
     221: invokevirtual #172                // Method java/lang/Number.intValue:()I
     224: istore        13
     226: iload         10
     228: iload         11
     230: iload         12
     232: iload         13
     234: invokestatic  #174                // Method expandSegmentRange:(IIII)Ljava/lang/Iterable;
     237: astore        8
     239: aload         4
     241: aload         8
     243: invokestatic  #178                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     246: pop
     247: goto          133
     250: aload         4
     252: checkcast     #90                 // class java/util/List
     255: nop
     256: checkcast     #40                 // class java/lang/Iterable
     259: astore_1
     260: nop
     261: iconst_0
     262: istore_2
     263: new           #180                // class day5/Day5Kt$buildMatrix$$inlined$groupingBy$1
     266: dup
     267: aload_1
     268: invokespecial #183                // Method day5/Day5Kt$buildMatrix$$inlined$groupingBy$1."<init>":(Ljava/lang/Iterable;)V
     271: checkcast     #185                // class kotlin/collections/Grouping
     274: invokestatic  #191                // Method kotlin/collections/GroupingKt.eachCount:(Lkotlin/collections/Grouping;)Ljava/util/Map;
     277: areturn

  public static final int countCloudSegmentOverlappingPoints(java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #208                // String matrix
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #214,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      12: checkcast     #40                 // class java/lang/Iterable
      15: astore_1
      16: iconst_0
      17: istore_2
      18: aload_1
      19: instanceof    #58                 // class java/util/Collection
      22: ifeq          41
      25: aload_1
      26: checkcast     #58                 // class java/util/Collection
      29: invokeinterface #217,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      34: ifeq          41
      37: iconst_0
      38: goto          111
      41: iconst_0
      42: istore_3
      43: aload_1
      44: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      49: astore        4
      51: aload         4
      53: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifeq          110
      61: aload         4
      63: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      68: astore        5
      70: aload         5
      72: checkcast     #169                // class java/lang/Number
      75: invokevirtual #172                // Method java/lang/Number.intValue:()I
      78: istore        6
      80: iconst_0
      81: istore        7
      83: iload         6
      85: iconst_1
      86: if_icmple     93
      89: iconst_1
      90: goto          94
      93: iconst_0
      94: ifeq          51
      97: iinc          3, 1
     100: iload_3
     101: ifge          51
     104: invokestatic  #220                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     107: goto          51
     110: iload_3
     111: ireturn

  public static final void main();
    Code:
       0: new           #231                // class java/io/File
       3: dup
       4: ldc           #233                // String ./input/day5.txt
       6: invokespecial #236                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: getstatic     #242                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_0
      17: astore_3
      18: sipush        8192
      21: istore        4
      23: aload_3
      24: astore        5
      26: new           #244                // class java/io/InputStreamReader
      29: dup
      30: new           #246                // class java/io/FileInputStream
      33: dup
      34: aload         5
      36: invokespecial #249                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      39: checkcast     #251                // class java/io/InputStream
      42: aload_1
      43: invokespecial #254                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      46: checkcast     #256                // class java/io/Reader
      49: astore        5
      51: aload         5
      53: instanceof    #258                // class java/io/BufferedReader
      56: ifeq          67
      59: aload         5
      61: checkcast     #258                // class java/io/BufferedReader
      64: goto          78
      67: new           #258                // class java/io/BufferedReader
      70: dup
      71: aload         5
      73: iload         4
      75: invokespecial #261                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      78: checkcast     #263                // class java/io/Closeable
      81: astore_3
      82: aconst_null
      83: astore        4
      85: nop
      86: aload_3
      87: checkcast     #258                // class java/io/BufferedReader
      90: astore        5
      92: iconst_0
      93: istore        6
      95: aload         5
      97: invokestatic  #269                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     100: astore        7
     102: iconst_0
     103: istore        8
     105: aload         7
     107: invokestatic  #275                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     110: invokestatic  #277                // Method buildMatrix:(Ljava/util/List;)Ljava/util/Map;
     113: astore        9
     115: aload         9
     117: invokestatic  #279                // Method countCloudSegmentOverlappingPoints:(Ljava/util/Map;)I
     120: istore        10
     122: getstatic     #285                // Field java/lang/System.out:Ljava/io/PrintStream;
     125: iload         10
     127: invokevirtual #290                // Method java/io/PrintStream.println:(I)V
     130: nop
     131: getstatic     #296                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     134: astore        5
     136: aload_3
     137: aload         4
     139: invokestatic  #302                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     142: goto          165
     145: astore        6
     147: aload         6
     149: astore        4
     151: aload         6
     153: athrow
     154: astore        6
     156: aload_3
     157: aload         4
     159: invokestatic  #302                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     162: aload         6
     164: athrow
     165: nop
     166: return
    Exception table:
       from    to  target type
          85   136   145   Class java/lang/Throwable
          85   136   154   any
         145   154   154   any
         154   156   154   any

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

  static {};
    Code:
       0: new           #24                 // class kotlin/text/Regex
       3: dup
       4: ldc_w         #324                // String (\\d+),(\\d+) -> (\\d+),(\\d+)
       7: invokespecial #325                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      10: putstatic     #20                 // Field regex:Lkotlin/text/Regex;
      13: return
}


package day12

import java.io.File

fun parseInput(lines: List<String>): Map<String, List<String>> =
  lines.flatMap {
    val (cave1, cave2) = it.split("-")
    listOf(cave1 to cave2, cave2 to cave1)
  }.groupBy({ it.first }, { it.second })

private fun String.isCaveSmall(): Boolean = this.first().isLowerCase()

fun countDistinctPathsThatVisitSmallCavesAtMostOnce(map: Map<String, List<String>>): Int {
  fun rec(cave: String, visited: Set<String>): Int =
    when {
      cave == "end" -> 1
      visited.contains(cave) -> 0
      else -> {
        map[cave]?.sumOf { rec(it, if (cave.isCaveSmall()) visited + cave else visited) } ?: 0
      }
    }
  return rec("start", setOf())
}

fun countDistinctPathsThatVisitSmallCavesAtMostOnceExceptOneRepetition(map: Map<String, List<String>>): Int {
  fun rec(cave: String, smallCavesVisited: Set<String>, repetitionUsed: Boolean): Int {
    return when {
      cave == "end" -> 1
      smallCavesVisited.contains(cave) ->
        if (repetitionUsed || cave == "start") 0
        else map[cave]?.sumOf { rec(it, smallCavesVisited, true) } ?: 0
      else -> {
        val next = if (cave.isCaveSmall()) smallCavesVisited + cave else smallCavesVisited
        map[cave]?.sumOf { rec(it, next, repetitionUsed) } ?: 0
      }
    }
  }
  return rec("start", setOf(), false)
}

fun main() {
  File("./input/day12.txt").useLines { lines ->
    val map = parseInput(lines.toList())
    println(countDistinctPathsThatVisitSmallCavesAtMostOnce(map))
    println(countDistinctPathsThatVisitSmallCavesAtMostOnceExceptOneRepetition(map))
  }
}

Compiled from "Day12.kt"
public final class day12.Day12Kt {
  public static final java.util.Map<java.lang.String, java.util.List<java.lang.String>> parseInput(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String lines
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #20                 // class java/util/ArrayList
      18: dup
      19: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      22: checkcast     #26                 // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          171
      48: aload         6
      50: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         7
      59: checkcast     #42                 // class java/lang/String
      62: astore        8
      64: iconst_0
      65: istore        9
      67: aload         8
      69: checkcast     #44                 // class java/lang/CharSequence
      72: iconst_1
      73: anewarray     #42                 // class java/lang/String
      76: astore        10
      78: aload         10
      80: iconst_0
      81: ldc           #46                 // String -
      83: aastore
      84: aload         10
      86: iconst_0
      87: iconst_0
      88: bipush        6
      90: aconst_null
      91: invokestatic  #52                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      94: astore        11
      96: aload         11
      98: iconst_0
      99: invokeinterface #58,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     104: checkcast     #42                 // class java/lang/String
     107: astore        10
     109: aload         11
     111: iconst_1
     112: invokeinterface #58,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     117: checkcast     #42                 // class java/lang/String
     120: astore        12
     122: iconst_2
     123: anewarray     #60                 // class kotlin/Pair
     126: astore        13
     128: aload         13
     130: iconst_0
     131: aload         10
     133: aload         12
     135: invokestatic  #66                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     138: aastore
     139: aload         13
     141: iconst_1
     142: aload         12
     144: aload         10
     146: invokestatic  #66                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     149: aastore
     150: aload         13
     152: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     155: checkcast     #18                 // class java/lang/Iterable
     158: astore        8
     160: aload         4
     162: aload         8
     164: invokestatic  #76                 // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     167: pop
     168: goto          38
     171: aload         4
     173: checkcast     #54                 // class java/util/List
     176: nop
     177: checkcast     #18                 // class java/lang/Iterable
     180: astore_1
     181: nop
     182: iconst_0
     183: istore_2
     184: aload_1
     185: astore_3
     186: new           #78                 // class java/util/LinkedHashMap
     189: dup
     190: invokespecial #79                 // Method java/util/LinkedHashMap."<init>":()V
     193: checkcast     #81                 // class java/util/Map
     196: astore        4
     198: iconst_0
     199: istore        5
     201: aload_3
     202: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     207: astore        6
     209: aload         6
     211: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     216: ifeq          345
     219: aload         6
     221: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     226: astore        7
     228: aload         7
     230: checkcast     #60                 // class kotlin/Pair
     233: astore        8
     235: iconst_0
     236: istore        9
     238: aload         8
     240: invokevirtual #84                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     243: checkcast     #42                 // class java/lang/String
     246: astore        10
     248: aload         4
     250: astore        11
     252: iconst_0
     253: istore        12
     255: aload         11
     257: aload         10
     259: invokeinterface #87,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     264: astore        13
     266: aload         13
     268: ifnonnull     303
     271: iconst_0
     272: istore        14
     274: new           #20                 // class java/util/ArrayList
     277: dup
     278: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
     281: checkcast     #54                 // class java/util/List
     284: astore        14
     286: aload         11
     288: aload         10
     290: aload         14
     292: invokeinterface #91,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     297: pop
     298: aload         14
     300: goto          305
     303: aload         13
     305: nop
     306: checkcast     #54                 // class java/util/List
     309: astore        8
     311: aload         8
     313: aload         7
     315: checkcast     #60                 // class kotlin/Pair
     318: astore        9
     320: astore        16
     322: iconst_0
     323: istore        15
     325: aload         9
     327: invokevirtual #94                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     330: checkcast     #42                 // class java/lang/String
     333: aload         16
     335: swap
     336: invokeinterface #98,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     341: pop
     342: goto          209
     345: aload         4
     347: nop
     348: areturn

  private static final boolean isCaveSmall(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #44                 // class java/lang/CharSequence
       4: invokestatic  #135                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
       7: invokestatic  #141                // Method java/lang/Character.isLowerCase:(C)Z
      10: ireturn

  public static final int countDistinctPathsThatVisitSmallCavesAtMostOnce(java.util.Map<java.lang.String, ? extends java.util.List<java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #147                // String map
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: ldc           #149                // String start
       9: invokestatic  #155                // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
      12: invokestatic  #159                // Method countDistinctPathsThatVisitSmallCavesAtMostOnce$rec:(Ljava/util/Map;Ljava/lang/String;Ljava/util/Set;)I
      15: ireturn

  public static final int countDistinctPathsThatVisitSmallCavesAtMostOnceExceptOneRepetition(java.util.Map<java.lang.String, ? extends java.util.List<java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #147                // String map
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: ldc           #149                // String start
       9: invokestatic  #155                // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
      12: iconst_0
      13: invokestatic  #164                // Method countDistinctPathsThatVisitSmallCavesAtMostOnceExceptOneRepetition$rec$6:(Ljava/util/Map;Ljava/lang/String;Ljava/util/Set;Z)I
      16: ireturn

  public static final void main();
    Code:
       0: new           #169                // class java/io/File
       3: dup
       4: ldc           #171                // String ./input/day12.txt
       6: invokespecial #174                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: getstatic     #180                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_0
      17: astore_3
      18: sipush        8192
      21: istore        4
      23: aload_3
      24: astore        5
      26: new           #182                // class java/io/InputStreamReader
      29: dup
      30: new           #184                // class java/io/FileInputStream
      33: dup
      34: aload         5
      36: invokespecial #187                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      39: checkcast     #189                // class java/io/InputStream
      42: aload_1
      43: invokespecial #192                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      46: checkcast     #194                // class java/io/Reader
      49: astore        5
      51: aload         5
      53: instanceof    #196                // class java/io/BufferedReader
      56: ifeq          67
      59: aload         5
      61: checkcast     #196                // class java/io/BufferedReader
      64: goto          78
      67: new           #196                // class java/io/BufferedReader
      70: dup
      71: aload         5
      73: iload         4
      75: invokespecial #199                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      78: checkcast     #201                // class java/io/Closeable
      81: astore_3
      82: aconst_null
      83: astore        4
      85: nop
      86: aload_3
      87: checkcast     #196                // class java/io/BufferedReader
      90: astore        5
      92: iconst_0
      93: istore        6
      95: aload         5
      97: invokestatic  #207                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     100: astore        7
     102: iconst_0
     103: istore        8
     105: aload         7
     107: invokestatic  #213                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     110: invokestatic  #215                // Method parseInput:(Ljava/util/List;)Ljava/util/Map;
     113: astore        9
     115: aload         9
     117: invokestatic  #217                // Method countDistinctPathsThatVisitSmallCavesAtMostOnce:(Ljava/util/Map;)I
     120: istore        10
     122: getstatic     #223                // Field java/lang/System.out:Ljava/io/PrintStream;
     125: iload         10
     127: invokevirtual #229                // Method java/io/PrintStream.println:(I)V
     130: aload         9
     132: invokestatic  #231                // Method countDistinctPathsThatVisitSmallCavesAtMostOnceExceptOneRepetition:(Ljava/util/Map;)I
     135: istore        10
     137: getstatic     #223                // Field java/lang/System.out:Ljava/io/PrintStream;
     140: iload         10
     142: invokevirtual #229                // Method java/io/PrintStream.println:(I)V
     145: nop
     146: getstatic     #237                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     149: astore        5
     151: aload_3
     152: aload         4
     154: invokestatic  #243                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     157: goto          180
     160: astore        6
     162: aload         6
     164: astore        4
     166: aload         6
     168: athrow
     169: astore        6
     171: aload_3
     172: aload         4
     174: invokestatic  #243                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     177: aload         6
     179: athrow
     180: nop
     181: return
    Exception table:
       from    to  target type
          85   151   160   Class java/lang/Throwable
          85   151   169   any
         160   169   169   any
         169   171   169   any

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

  private static final int countDistinctPathsThatVisitSmallCavesAtMostOnce$rec(java.util.Map<java.lang.String, ? extends java.util.List<java.lang.String>>, java.lang.String, java.util.Set<java.lang.String>);
    Code:
       0: nop
       1: aload_1
       2: ldc_w         #264                // String end
       5: invokestatic  #268                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       8: ifeq          15
      11: iconst_1
      12: goto          132
      15: aload_2
      16: aload_1
      17: invokeinterface #273,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      22: ifeq          29
      25: iconst_0
      26: goto          132
      29: aload_0
      30: aload_1
      31: invokeinterface #87,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      36: checkcast     #54                 // class java/util/List
      39: dup
      40: ifnull        130
      43: checkcast     #18                 // class java/lang/Iterable
      46: astore_3
      47: iconst_0
      48: istore        4
      50: aload_3
      51: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        5
      58: aload         5
      60: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          125
      68: aload         5
      70: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        6
      77: iload         4
      79: aload         6
      81: checkcast     #42                 // class java/lang/String
      84: astore        7
      86: istore        9
      88: iconst_0
      89: istore        8
      91: aload_0
      92: aload         7
      94: aload_1
      95: invokestatic  #275                // Method isCaveSmall:(Ljava/lang/String;)Z
      98: ifeq          109
     101: aload_2
     102: aload_1
     103: invokestatic  #279                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Object;)Ljava/util/Set;
     106: goto          110
     109: aload_2
     110: invokestatic  #159                // Method countDistinctPathsThatVisitSmallCavesAtMostOnce$rec:(Ljava/util/Map;Ljava/lang/String;Ljava/util/Set;)I
     113: istore        10
     115: iload         9
     117: iload         10
     119: iadd
     120: istore        4
     122: goto          58
     125: iload         4
     127: goto          132
     130: pop
     131: iconst_0
     132: ireturn

  private static final int countDistinctPathsThatVisitSmallCavesAtMostOnceExceptOneRepetition$rec$6(java.util.Map<java.lang.String, ? extends java.util.List<java.lang.String>>, java.lang.String, java.util.Set<java.lang.String>, boolean);
    Code:
       0: nop
       1: aload_1
       2: ldc_w         #264                // String end
       5: invokestatic  #268                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       8: ifeq          15
      11: iconst_1
      12: goto          246
      15: aload_2
      16: aload_1
      17: invokeinterface #273,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      22: ifeq          136
      25: iload_3
      26: ifne          38
      29: aload_1
      30: ldc           #149                // String start
      32: invokestatic  #268                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      35: ifeq          42
      38: iconst_0
      39: goto          246
      42: aload_0
      43: aload_1
      44: invokeinterface #87,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      49: checkcast     #54                 // class java/util/List
      52: dup
      53: ifnull        131
      56: checkcast     #18                 // class java/lang/Iterable
      59: astore        5
      61: iconst_0
      62: istore        6
      64: aload         5
      66: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      71: astore        7
      73: aload         7
      75: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      80: ifeq          126
      83: aload         7
      85: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      90: astore        8
      92: iload         6
      94: aload         8
      96: checkcast     #42                 // class java/lang/String
      99: astore        9
     101: istore        12
     103: iconst_0
     104: istore        10
     106: aload_0
     107: aload         9
     109: aload_2
     110: iconst_1
     111: invokestatic  #164                // Method countDistinctPathsThatVisitSmallCavesAtMostOnceExceptOneRepetition$rec$6:(Ljava/util/Map;Ljava/lang/String;Ljava/util/Set;Z)I
     114: istore        13
     116: iload         12
     118: iload         13
     120: iadd
     121: istore        6
     123: goto          73
     126: iload         6
     128: goto          246
     131: pop
     132: iconst_0
     133: goto          246
     136: aload_1
     137: invokestatic  #275                // Method isCaveSmall:(Ljava/lang/String;)Z
     140: ifeq          151
     143: aload_2
     144: aload_1
     145: invokestatic  #279                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Object;)Ljava/util/Set;
     148: goto          152
     151: aload_2
     152: astore        4
     154: aload_0
     155: aload_1
     156: invokeinterface #87,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     161: checkcast     #54                 // class java/util/List
     164: dup
     165: ifnull        244
     168: checkcast     #18                 // class java/lang/Iterable
     171: astore        6
     173: iconst_0
     174: istore        7
     176: aload         6
     178: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     183: astore        8
     185: aload         8
     187: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     192: ifeq          239
     195: aload         8
     197: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     202: astore        9
     204: iload         7
     206: aload         9
     208: checkcast     #42                 // class java/lang/String
     211: astore        10
     213: istore        12
     215: iconst_0
     216: istore        11
     218: aload_0
     219: aload         10
     221: aload         4
     223: iload_3
     224: invokestatic  #164                // Method countDistinctPathsThatVisitSmallCavesAtMostOnceExceptOneRepetition$rec$6:(Ljava/util/Map;Ljava/lang/String;Ljava/util/Set;Z)I
     227: istore        13
     229: iload         12
     231: iload         13
     233: iadd
     234: istore        7
     236: goto          185
     239: iload         7
     241: goto          246
     244: pop
     245: iconst_0
     246: ireturn
}


package day15

import java.io.File
import java.util.PriorityQueue

// Syntax sugar
typealias Matrix<T> = Array<Array<T>>
typealias RiskFn = (Pair<Int, Int>) -> Int

private fun <T> Matrix<T>.get(pair: Pair<Int, Int>) = this[pair.first][pair.second]
private fun <T> Matrix<T>.put(pair: Pair<Int, Int>, element: T) {
  this[pair.first][pair.second] = element
}

fun parseInput(lines: List<String>): Matrix<Int> =
  lines
    .map { it.map(Char::digitToInt).toTypedArray() }
    .toTypedArray()

private fun Pair<Int, Int>.withinBoundaries(limit: Int) =
  (0 until limit).let { range -> range.contains(this.first) && range.contains(this.second) }

// I decided to navigate from destination to start: (N, N) to (0, 0)
// Let's try to go up and left first even though there is a priority queue that
// will ultimately decide the order
private fun Pair<Int, Int>.adjacent(boundaries: Int) =
  listOf(-1 to 0, 0 to -1, 0 to 1, 1 to 0) // up, left, right, down
    .map { (first, second) -> (first + this.first) to (second + this.second) }
    .filter { it.withinBoundaries(boundaries) }

private fun solve(dimension: Int, riskFn: RiskFn): Int {
  val minPathRiskTabulation = Array(dimension) { Array(dimension) { Int.MAX_VALUE } }
  val toVisit = PriorityQueue<Pair<Pair<Int, Int>, Int>> { (_, risk1), (_, risk2) -> risk1.compareTo(risk2) }

  val start = 0 to 0
  val destination = (dimension - 1) to (dimension - 1)
  toVisit.add(destination to 0)
  do {
    val (current, accumulatedRisk) = toVisit.poll()
    if (current == start) return accumulatedRisk
    val pathRisk = riskFn(current) + accumulatedRisk
    val minPathRisk = minPathRiskTabulation.get(current)
    if (pathRisk < minPathRisk) {
      minPathRiskTabulation.put(current, pathRisk)
      toVisit.addAll(current.adjacent(dimension).associateWith { pathRisk }.toList())
    }
  } while (true)
}

fun solve1(riskMatrix: Matrix<Int>): Int = solve(riskMatrix.size, riskMatrix::get)

fun riskFn2(riskMatrix: Matrix<Int>): RiskFn = { (r, c) ->
  val additionalRisk = (r / riskMatrix.size) + (c / riskMatrix.size)
  val risk = riskMatrix[r % riskMatrix.size][c % riskMatrix.size] + additionalRisk
  if (risk > 9) risk - 9 else risk // only 1..9 (10 resets to 1)
}

fun solve2(riskMatrix: Matrix<Int>): Int = solve(riskMatrix.size * 5, riskFn2(riskMatrix))

fun main() {
  File("./input/day15.txt").useLines { lines ->
    val riskMatrix = parseInput(lines.toList())
    println(solve1(riskMatrix))
    println(solve2(riskMatrix))
  }
}

Compiled from "Day15.kt"
public final class day15.Day15Kt {
  private static final <T> T get(T[][], kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_1
       2: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: checkcast     #15                 // class java/lang/Number
       8: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      11: aaload
      12: aload_1
      13: invokevirtual #22                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      16: checkcast     #15                 // class java/lang/Number
      19: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      22: aaload
      23: areturn

  private static final <T> void put(T[][], kotlin.Pair<java.lang.Integer, java.lang.Integer>, T);
    Code:
       0: aload_0
       1: aload_1
       2: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: checkcast     #15                 // class java/lang/Number
       8: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      11: aaload
      12: aload_1
      13: invokevirtual #22                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      16: checkcast     #15                 // class java/lang/Number
      19: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      22: aload_2
      23: aastore
      24: return

  public static final java.lang.Integer[][] parseInput(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #38                 // String lines
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #46                 // class java/lang/Iterable
      10: astore_1
      11: nop
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #48                 // class java/util/ArrayList
      19: dup
      20: aload_1
      21: bipush        10
      23: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #58                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #60                 // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload_3
      38: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        6
      45: aload         6
      47: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          220
      55: aload         6
      57: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        7
      64: aload         4
      66: aload         7
      68: checkcast     #75                 // class java/lang/String
      71: astore        8
      73: astore        20
      75: iconst_0
      76: istore        9
      78: aload         8
      80: checkcast     #77                 // class java/lang/CharSequence
      83: astore        10
      85: iconst_0
      86: istore        11
      88: aload         10
      90: astore        12
      92: new           #48                 // class java/util/ArrayList
      95: dup
      96: aload         10
      98: invokeinterface #80,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     103: invokespecial #58                 // Method java/util/ArrayList."<init>":(I)V
     106: checkcast     #60                 // class java/util/Collection
     109: astore        13
     111: iconst_0
     112: istore        14
     114: iconst_0
     115: istore        15
     117: iload         15
     119: aload         12
     121: invokeinterface #80,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     126: if_icmpge     174
     129: aload         12
     131: iload         15
     133: invokeinterface #84,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     138: istore        16
     140: aload         13
     142: iload         16
     144: istore        17
     146: astore        18
     148: iconst_0
     149: istore        19
     151: iload         17
     153: invokestatic  #90                 // Method kotlin/text/CharsKt.digitToInt:(C)I
     156: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     159: aload         18
     161: swap
     162: invokeinterface #100,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     167: pop
     168: iinc          15, 1
     171: goto          117
     174: aload         13
     176: checkcast     #102                // class java/util/List
     179: nop
     180: checkcast     #60                 // class java/util/Collection
     183: astore        10
     185: nop
     186: iconst_0
     187: istore        11
     189: aload         10
     191: astore        12
     193: aload         12
     195: iconst_0
     196: anewarray     #92                 // class java/lang/Integer
     199: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     204: checkcast     #108                // class "[Ljava/lang/Integer;"
     207: nop
     208: aload         20
     210: swap
     211: invokeinterface #100,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     216: pop
     217: goto          45
     220: aload         4
     222: checkcast     #102                // class java/util/List
     225: nop
     226: checkcast     #60                 // class java/util/Collection
     229: astore_1
     230: nop
     231: iconst_0
     232: istore_2
     233: aload_1
     234: astore_3
     235: aload_3
     236: iconst_0
     237: anewarray     #108                // class "[Ljava/lang/Integer;"
     240: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     245: checkcast     #110                // class "[[Ljava/lang/Integer;"
     248: areturn

  private static final boolean withinBoundaries(kotlin.Pair<java.lang.Integer, java.lang.Integer>, int);
    Code:
       0: iconst_0
       1: iload_1
       2: invokestatic  #139                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       5: astore_2
       6: iconst_0
       7: istore_3
       8: aload_2
       9: aload_0
      10: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      13: checkcast     #15                 // class java/lang/Number
      16: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      19: invokevirtual #145                // Method kotlin/ranges/IntRange.contains:(I)Z
      22: ifeq          46
      25: aload_2
      26: aload_0
      27: invokevirtual #22                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      30: checkcast     #15                 // class java/lang/Number
      33: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      36: invokevirtual #145                // Method kotlin/ranges/IntRange.contains:(I)Z
      39: ifeq          46
      42: iconst_1
      43: goto          47
      46: iconst_0
      47: nop
      48: ireturn

  private static final java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>> adjacent(kotlin.Pair<java.lang.Integer, java.lang.Integer>, int);
    Code:
       0: iconst_4
       1: anewarray     #9                  // class kotlin/Pair
       4: astore_2
       5: aload_2
       6: iconst_0
       7: iconst_m1
       8: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      11: iconst_0
      12: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: invokestatic  #159                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      18: aastore
      19: aload_2
      20: iconst_1
      21: iconst_0
      22: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: iconst_m1
      26: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: invokestatic  #159                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      32: aastore
      33: aload_2
      34: iconst_2
      35: iconst_0
      36: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      39: iconst_1
      40: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      43: invokestatic  #159                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      46: aastore
      47: aload_2
      48: iconst_3
      49: iconst_1
      50: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      53: iconst_0
      54: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      57: invokestatic  #159                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      60: aastore
      61: aload_2
      62: invokestatic  #163                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      65: checkcast     #46                 // class java/lang/Iterable
      68: astore_2
      69: nop
      70: iconst_0
      71: istore_3
      72: aload_2
      73: astore        4
      75: new           #48                 // class java/util/ArrayList
      78: dup
      79: aload_2
      80: bipush        10
      82: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      85: invokespecial #58                 // Method java/util/ArrayList."<init>":(I)V
      88: checkcast     #60                 // class java/util/Collection
      91: astore        5
      93: iconst_0
      94: istore        6
      96: aload         4
      98: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     103: astore        7
     105: aload         7
     107: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     112: ifeq          211
     115: aload         7
     117: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     122: astore        8
     124: aload         5
     126: aload         8
     128: checkcast     #9                  // class kotlin/Pair
     131: astore        9
     133: astore        13
     135: iconst_0
     136: istore        10
     138: aload         9
     140: invokevirtual #166                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     143: checkcast     #15                 // class java/lang/Number
     146: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     149: istore        11
     151: aload         9
     153: invokevirtual #169                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     156: checkcast     #15                 // class java/lang/Number
     159: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     162: istore        12
     164: iload         11
     166: aload_0
     167: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     170: checkcast     #15                 // class java/lang/Number
     173: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     176: iadd
     177: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     180: iload         12
     182: aload_0
     183: invokevirtual #22                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     186: checkcast     #15                 // class java/lang/Number
     189: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     192: iadd
     193: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     196: invokestatic  #159                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     199: aload         13
     201: swap
     202: invokeinterface #100,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     207: pop
     208: goto          105
     211: aload         5
     213: checkcast     #102                // class java/util/List
     216: nop
     217: checkcast     #46                 // class java/lang/Iterable
     220: astore_2
     221: nop
     222: iconst_0
     223: istore_3
     224: aload_2
     225: astore        4
     227: new           #48                 // class java/util/ArrayList
     230: dup
     231: invokespecial #172                // Method java/util/ArrayList."<init>":()V
     234: checkcast     #60                 // class java/util/Collection
     237: astore        5
     239: iconst_0
     240: istore        6
     242: aload         4
     244: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     249: astore        7
     251: aload         7
     253: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     258: ifeq          302
     261: aload         7
     263: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     268: astore        8
     270: aload         8
     272: checkcast     #9                  // class kotlin/Pair
     275: astore        9
     277: iconst_0
     278: istore        10
     280: aload         9
     282: iload_1
     283: invokestatic  #174                // Method withinBoundaries:(Lkotlin/Pair;I)Z
     286: ifeq          251
     289: aload         5
     291: aload         8
     293: invokeinterface #100,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     298: pop
     299: goto          251
     302: aload         5
     304: checkcast     #102                // class java/util/List
     307: nop
     308: areturn

  private static final int solve(int, kotlin.jvm.functions.Function1<? super kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.lang.Integer>);
    Code:
       0: iconst_0
       1: istore_3
       2: iload_0
       3: anewarray     #108                // class "[Ljava/lang/Integer;"
       6: astore        4
       8: iload_3
       9: iload_0
      10: if_icmpge     72
      13: iload_3
      14: istore        5
      16: aload         4
      18: iload         5
      20: iconst_0
      21: istore        6
      23: iload_0
      24: anewarray     #92                 // class java/lang/Integer
      27: astore        7
      29: istore        21
      31: astore        20
      33: iload         6
      35: iload_0
      36: if_icmpge     59
      39: iload         6
      41: istore        8
      43: aload         7
      45: iload         8
      47: ldc           #189                // int 2147483647
      49: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      52: aastore
      53: iinc          6, 1
      56: goto          33
      59: aload         20
      61: iload         21
      63: aload         7
      65: aastore
      66: iinc          3, 1
      69: goto          8
      72: aload         4
      74: astore_2
      75: new           #191                // class java/util/PriorityQueue
      78: dup
      79: invokedynamic #211,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
      84: invokedynamic #222,  0            // InvokeDynamic #1:compare:(Lkotlin/jvm/functions/Function2;)Ljava/util/Comparator;
      89: invokespecial #225                // Method java/util/PriorityQueue."<init>":(Ljava/util/Comparator;)V
      92: astore_3
      93: iconst_0
      94: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      97: iconst_0
      98: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     101: invokestatic  #159                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     104: astore        4
     106: iload_0
     107: iconst_1
     108: isub
     109: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: iload_0
     113: iconst_1
     114: isub
     115: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     118: invokestatic  #159                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     121: astore        5
     123: aload_3
     124: aload         5
     126: iconst_0
     127: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     130: invokestatic  #159                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     133: invokevirtual #226                // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
     136: pop
     137: aload_3
     138: invokevirtual #229                // Method java/util/PriorityQueue.poll:()Ljava/lang/Object;
     141: checkcast     #9                  // class kotlin/Pair
     144: astore        6
     146: aload         6
     148: invokevirtual #166                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     151: checkcast     #9                  // class kotlin/Pair
     154: astore        7
     156: aload         6
     158: invokevirtual #169                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     161: checkcast     #15                 // class java/lang/Number
     164: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     167: istore        8
     169: aload         7
     171: aload         4
     173: invokestatic  #233                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     176: ifeq          182
     179: iload         8
     181: ireturn
     182: aload_1
     183: aload         7
     185: invokeinterface #238,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     190: checkcast     #15                 // class java/lang/Number
     193: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     196: iload         8
     198: iadd
     199: istore        9
     201: aload_2
     202: aload         7
     204: invokestatic  #240                // Method get:([[Ljava/lang/Object;Lkotlin/Pair;)Ljava/lang/Object;
     207: checkcast     #15                 // class java/lang/Number
     210: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     213: istore        10
     215: iload         9
     217: iload         10
     219: if_icmpge     371
     222: aload_2
     223: aload         7
     225: iload         9
     227: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     230: invokestatic  #242                // Method put:([[Ljava/lang/Object;Lkotlin/Pair;Ljava/lang/Object;)V
     233: aload_3
     234: aload         7
     236: iload_0
     237: invokestatic  #244                // Method adjacent:(Lkotlin/Pair;I)Ljava/util/List;
     240: checkcast     #46                 // class java/lang/Iterable
     243: astore        11
     245: astore        20
     247: iconst_0
     248: istore        12
     250: new           #246                // class java/util/LinkedHashMap
     253: dup
     254: aload         11
     256: bipush        10
     258: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     261: invokestatic  #252                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     264: bipush        16
     266: invokestatic  #256                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     269: invokespecial #257                // Method java/util/LinkedHashMap."<init>":(I)V
     272: astore        13
     274: aload         11
     276: astore        14
     278: iconst_0
     279: istore        15
     281: aload         14
     283: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     288: astore        16
     290: aload         16
     292: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     297: ifeq          352
     300: aload         16
     302: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     307: astore        17
     309: aload         13
     311: checkcast     #259                // class java/util/Map
     314: aload         17
     316: aload         17
     318: checkcast     #9                  // class kotlin/Pair
     321: astore        18
     323: astore        22
     325: astore        21
     327: iconst_0
     328: istore        19
     330: iload         9
     332: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     335: astore        23
     337: aload         21
     339: aload         22
     341: aload         23
     343: invokeinterface #261,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     348: pop
     349: goto          290
     352: aload         13
     354: checkcast     #259                // class java/util/Map
     357: nop
     358: aload         20
     360: swap
     361: invokestatic  #265                // Method kotlin/collections/MapsKt.toList:(Ljava/util/Map;)Ljava/util/List;
     364: checkcast     #60                 // class java/util/Collection
     367: invokevirtual #269                // Method java/util/PriorityQueue.addAll:(Ljava/util/Collection;)Z
     370: pop
     371: goto          137

  public static final int solve1(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc_w         #292                // String riskMatrix
       4: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #294                // class "[Ljava/lang/Object;"
      11: arraylength
      12: new           #296                // class day15/Day15Kt$solve1$1
      15: dup
      16: aload_0
      17: invokespecial #299                // Method day15/Day15Kt$solve1$1."<init>":(Ljava/lang/Object;)V
      20: checkcast     #235                // class kotlin/jvm/functions/Function1
      23: invokestatic  #301                // Method solve:(ILkotlin/jvm/functions/Function1;)I
      26: ireturn

  public static final kotlin.jvm.functions.Function1<kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.lang.Integer> riskFn2(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc_w         #292                // String riskMatrix
       4: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokedynamic #314,  0            // InvokeDynamic #2:invoke:([[Ljava/lang/Integer;)Lkotlin/jvm/functions/Function1;
      13: areturn

  public static final int solve2(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc_w         #292                // String riskMatrix
       4: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #294                // class "[Ljava/lang/Object;"
      11: arraylength
      12: iconst_5
      13: imul
      14: aload_0
      15: invokestatic  #317                // Method riskFn2:([[Ljava/lang/Integer;)Lkotlin/jvm/functions/Function1;
      18: invokestatic  #301                // Method solve:(ILkotlin/jvm/functions/Function1;)I
      21: ireturn

  public static final void main();
    Code:
       0: new           #322                // class java/io/File
       3: dup
       4: ldc_w         #324                // String ./input/day15.txt
       7: invokespecial #327                // Method java/io/File."<init>":(Ljava/lang/String;)V
      10: astore_0
      11: getstatic     #333                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      14: astore_1
      15: iconst_0
      16: istore_2
      17: aload_0
      18: astore_3
      19: sipush        8192
      22: istore        4
      24: aload_3
      25: astore        5
      27: new           #335                // class java/io/InputStreamReader
      30: dup
      31: new           #337                // class java/io/FileInputStream
      34: dup
      35: aload         5
      37: invokespecial #340                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      40: checkcast     #342                // class java/io/InputStream
      43: aload_1
      44: invokespecial #345                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      47: checkcast     #347                // class java/io/Reader
      50: astore        5
      52: aload         5
      54: instanceof    #349                // class java/io/BufferedReader
      57: ifeq          68
      60: aload         5
      62: checkcast     #349                // class java/io/BufferedReader
      65: goto          79
      68: new           #349                // class java/io/BufferedReader
      71: dup
      72: aload         5
      74: iload         4
      76: invokespecial #352                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      79: checkcast     #354                // class java/io/Closeable
      82: astore_3
      83: aconst_null
      84: astore        4
      86: nop
      87: aload_3
      88: checkcast     #349                // class java/io/BufferedReader
      91: astore        5
      93: iconst_0
      94: istore        6
      96: aload         5
      98: invokestatic  #360                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     101: astore        7
     103: iconst_0
     104: istore        8
     106: aload         7
     108: invokestatic  #365                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     111: invokestatic  #367                // Method parseInput:(Ljava/util/List;)[[Ljava/lang/Integer;
     114: astore        9
     116: aload         9
     118: invokestatic  #369                // Method solve1:([[Ljava/lang/Integer;)I
     121: istore        10
     123: getstatic     #375                // Field java/lang/System.out:Ljava/io/PrintStream;
     126: iload         10
     128: invokevirtual #380                // Method java/io/PrintStream.println:(I)V
     131: aload         9
     133: invokestatic  #382                // Method solve2:([[Ljava/lang/Integer;)I
     136: istore        10
     138: getstatic     #375                // Field java/lang/System.out:Ljava/io/PrintStream;
     141: iload         10
     143: invokevirtual #380                // Method java/io/PrintStream.println:(I)V
     146: nop
     147: getstatic     #388                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     150: astore        5
     152: aload_3
     153: aload         4
     155: invokestatic  #394                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     158: goto          181
     161: astore        6
     163: aload         6
     165: astore        4
     167: aload         6
     169: athrow
     170: astore        6
     172: aload_3
     173: aload         4
     175: invokestatic  #394                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     178: aload         6
     180: athrow
     181: nop
     182: return
    Exception table:
       from    to  target type
          86   152   161   Class java/lang/Throwable
          86   152   170   any
         161   170   170   any
         170   172   170   any

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

  private static final int solve$lambda$4(kotlin.Pair, kotlin.Pair);
    Code:
       0: aload_0
       1: invokevirtual #169                // Method kotlin/Pair.component2:()Ljava/lang/Object;
       4: checkcast     #15                 // class java/lang/Number
       7: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      10: istore_2
      11: aload_1
      12: invokevirtual #169                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      15: checkcast     #15                 // class java/lang/Number
      18: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      21: istore_3
      22: iload_2
      23: iload_3
      24: invokestatic  #414                // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      27: ireturn

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

  private static final int riskFn2$lambda$7(java.lang.Integer[][], kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #425                // String <destruct>
       4: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokevirtual #166                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      11: checkcast     #15                 // class java/lang/Number
      14: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      17: istore_2
      18: aload_1
      19: invokevirtual #169                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      22: checkcast     #15                 // class java/lang/Number
      25: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      28: istore_3
      29: iload_2
      30: aload_0
      31: checkcast     #294                // class "[Ljava/lang/Object;"
      34: arraylength
      35: idiv
      36: iload_3
      37: aload_0
      38: checkcast     #294                // class "[Ljava/lang/Object;"
      41: arraylength
      42: idiv
      43: iadd
      44: istore        4
      46: aload_0
      47: iload_2
      48: aload_0
      49: checkcast     #294                // class "[Ljava/lang/Object;"
      52: arraylength
      53: irem
      54: aaload
      55: iload_3
      56: aload_0
      57: checkcast     #294                // class "[Ljava/lang/Object;"
      60: arraylength
      61: irem
      62: aaload
      63: invokevirtual #426                // Method java/lang/Integer.intValue:()I
      66: iload         4
      68: iadd
      69: istore        5
      71: iload         5
      73: bipush        9
      75: if_icmple     86
      78: iload         5
      80: bipush        9
      82: isub
      83: goto          88
      86: iload         5
      88: ireturn

  public static final java.lang.Object access$get(java.lang.Object[][], kotlin.Pair);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #240                // Method get:([[Ljava/lang/Object;Lkotlin/Pair;)Ljava/lang/Object;
       5: areturn
}

Compiled from "Day15.kt"
final class day15.Day15Kt$solve1$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<kotlin.Pair<? extends java.lang.Integer, ? extends java.lang.Integer>, java.lang.Integer> {
  day15.Day15Kt$solve1$1(java.lang.Object);
    Code:
       0: aload_0
       1: iconst_1
       2: aload_1
       3: ldc           #11                 // class day15/Day15Kt
       5: ldc           #13                 // String get
       7: ldc           #15                 // String get([[Ljava/lang/Object;Lkotlin/Pair;)Ljava/lang/Object;
       9: iconst_1
      10: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Integer invoke(kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #27                 // String p0
       3: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #35                 // Field receiver:Ljava/lang/Object;
      10: checkcast     #37                 // class "[[Ljava/lang/Object;"
      13: aload_1
      14: invokestatic  #41                 // Method day15/Day15Kt.access$get:([[Ljava/lang/Object;Lkotlin/Pair;)Ljava/lang/Object;
      17: checkcast     #43                 // class java/lang/Integer
      20: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #47                 // class kotlin/Pair
       5: invokevirtual #49                 // Method invoke:(Lkotlin/Pair;)Ljava/lang/Integer;
       8: areturn
}