package day24

import Point
import day24.Blizzard.DOWN
import day24.Blizzard.LEFT
import day24.Blizzard.RIGHT
import day24.Blizzard.UP
import day24.Blizzard.WALL
import readInput

typealias Valley = Map<Point, List<Blizzard>>

private val initialValley = readInput("main/day24/Day24").toValley()
private val maxX = initialValley.keys.maxOf { it.x }
private val minX = initialValley.keys.minOf { it.x }
private val maxY = initialValley.keys.maxOf { it.y }
private val minY = initialValley.keys.minOf { it.y }
private val start = initialValley.filter { it.key.y == minY }.keys.first { initialValley[it]!!.isEmpty() }
private val exit = initialValley.filter { it.key.y == maxY }.keys.first { initialValley[it]!!.isEmpty() }
private val walls = initialValley.filter { it.value.firstOrNull() == WALL }
private val valleySequence = generateSequence(initialValley) { it.step() }.take(1000).toList()

fun main() {

    println(part1())
    println(part2())
}

fun part1(): Int {
    return findPath()
}

fun part2(): Int {
    val toGoal = findPath()
    val backToStart = findPath(entry = exit, currentStep = toGoal, goal = start)
    return findPath(currentStep = backToStart)
}

fun findPath(entry: Point = start, currentStep: Int = 0, goal: Point = exit): Int {
    val pathsToCheck = mutableListOf(State(entry, currentStep))
    val checked = mutableSetOf<State>()

    while (pathsToCheck.isNotEmpty()) {
        val current = pathsToCheck.removeFirst()
        if (current !in checked) {
            val nextValley = valleySequence[current.step + 1]
            val neighbours = validNeighboursFor(current.point).filter { nextValley.isOpenAt(it) }

            if (goal in neighbours) return current.step + 1

            checked += current
            neighbours.forEach {
                pathsToCheck.add(State(it, current.step + 1))
            }
        }
    }
    error("lost in the vally of blizzards")
}

fun List<String>.toValley(): Valley {
    val valley = mutableMapOf<Point, List<Blizzard>>()
    mapIndexed { y, line ->
        line.mapIndexed { x, c ->
            val p = Point(x, y)
            when (c) {
                '^' -> valley[p] = listOf(UP)
                'v' -> valley[p] = listOf(DOWN)
                '<' -> valley[p] = listOf(LEFT)
                '>' -> valley[p] = listOf(RIGHT)
                '#' -> valley[p] = listOf(WALL)
                else -> valley[p] = emptyList()
            }
        }
    }
    return valley
}

fun validNeighboursFor(p: Point) = p.neighbours(true)
    .filterNot { it in walls }
    .filter { it.x in (minX..maxX) }
    .filter { it.y in (minY..maxY) }

fun Valley.isOpenAt(p: Point): Boolean = this[p].isNullOrEmpty()

fun Valley.step(): Valley =
    mutableMapOf<Point, MutableList<Blizzard>>(
        // start and goal must always be in the map
        start to mutableListOf(),
        exit to mutableListOf()
    ).let { result ->
        (minX..maxX).forEach { x ->
            (minY..maxY).forEach { y ->
                val here = Point(x, y)
                val blizzards = this[here]
                if (!blizzards.isNullOrEmpty()) {
                    blizzards.forEach { blizzard ->
                        var newLocation = here + blizzard.offset
                        if (newLocation in walls) {
                            newLocation = when (blizzard) {
                                LEFT -> Point(maxX - 1, y)
                                RIGHT -> Point(minX + 1, y)
                                UP -> Point(x, maxY - 1)
                                DOWN -> Point(x, minY + 1)
                                WALL -> Point(x, y) // walls do not move
                            }
                        }
                        if (result[newLocation] == null) result[newLocation] = mutableListOf(blizzard)
                        else result[newLocation]!!.add(blizzard)
                    }
                }
            }
        }
        result
    }

enum class Blizzard(val offset: Point) {
    LEFT(Point(-1, 0)),
    RIGHT(Point(1, 0)),
    UP(Point(0, -1)),
    DOWN(Point(0, 1)),
    WALL(Point(0, 0)),
}

data class State(val point: Point, val step: Int)

Compiled from "day24.kt"
public final class day24.Day24Kt$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method day24/Blizzard.values:()[Lday24/Blizzard;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field day24/Blizzard.LEFT:Lday24/Blizzard;
      12: invokevirtual #22                 // Method day24/Blizzard.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field day24/Blizzard.RIGHT:Lday24/Blizzard;
      26: invokevirtual #22                 // Method day24/Blizzard.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field day24/Blizzard.UP:Lday24/Blizzard;
      40: invokevirtual #22                 // Method day24/Blizzard.ordinal:()I
      43: iconst_3
      44: iastore
      45: goto          49
      48: astore_1
      49: nop
      50: aload_0
      51: getstatic     #31                 // Field day24/Blizzard.DOWN:Lday24/Blizzard;
      54: invokevirtual #22                 // Method day24/Blizzard.ordinal:()I
      57: iconst_4
      58: iastore
      59: goto          63
      62: astore_1
      63: nop
      64: aload_0
      65: getstatic     #34                 // Field day24/Blizzard.WALL:Lday24/Blizzard;
      68: invokevirtual #22                 // Method day24/Blizzard.ordinal:()I
      71: iconst_5
      72: iastore
      73: goto          77
      76: astore_1
      77: aload_0
      78: putstatic     #38                 // Field $EnumSwitchMapping$0:[I
      81: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
          35    45    48   Class java/lang/NoSuchFieldError
          49    59    62   Class java/lang/NoSuchFieldError
          63    73    76   Class java/lang/NoSuchFieldError
}

Compiled from "day24.kt"
public final class day24.Day24Kt {
  private static final java.util.Map<Point, java.util.List<day24.Blizzard>> initialValley;

  private static final int maxX;

  private static final int minX;

  private static final int maxY;

  private static final int minY;

  private static final Point start;

  private static final Point exit;

  private static final java.util.Map<Point, java.util.List<day24.Blizzard>> walls;

  private static final java.util.List<java.util.Map<Point, java.util.List<day24.Blizzard>>> valleySequence;

  public static final void main();
    Code:
       0: invokestatic  #10                 // Method part1:()I
       3: istore_0
       4: getstatic     #16                 // Field java/lang/System.out:Ljava/io/PrintStream;
       7: iload_0
       8: invokevirtual #22                 // Method java/io/PrintStream.println:(I)V
      11: invokestatic  #25                 // Method part2:()I
      14: istore_0
      15: getstatic     #16                 // Field java/lang/System.out:Ljava/io/PrintStream;
      18: iload_0
      19: invokevirtual #22                 // Method java/io/PrintStream.println:(I)V
      22: return

  public static final int part1();
    Code:
       0: aconst_null
       1: iconst_0
       2: aconst_null
       3: bipush        7
       5: aconst_null
       6: invokestatic  #29                 // Method findPath$default:(LPoint;ILPoint;ILjava/lang/Object;)I
       9: ireturn

  public static final int part2();
    Code:
       0: aconst_null
       1: iconst_0
       2: aconst_null
       3: bipush        7
       5: aconst_null
       6: invokestatic  #29                 // Method findPath$default:(LPoint;ILPoint;ILjava/lang/Object;)I
       9: istore_0
      10: getstatic     #33                 // Field exit:LPoint;
      13: iload_0
      14: getstatic     #36                 // Field start:LPoint;
      17: invokestatic  #40                 // Method findPath:(LPoint;ILPoint;)I
      20: istore_1
      21: aconst_null
      22: iload_1
      23: aconst_null
      24: iconst_5
      25: aconst_null
      26: invokestatic  #29                 // Method findPath$default:(LPoint;ILPoint;ILjava/lang/Object;)I
      29: ireturn

  public static final int findPath(Point, int, Point);
    Code:
       0: aload_0
       1: ldc           #46                 // String entry
       3: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #54                 // String goal
       9: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_1
      13: anewarray     #56                 // class day24/State
      16: astore        4
      18: aload         4
      20: iconst_0
      21: new           #56                 // class day24/State
      24: dup
      25: aload_0
      26: iload_1
      27: invokespecial #60                 // Method day24/State."<init>":(LPoint;I)V
      30: aastore
      31: aload         4
      33: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      36: astore_3
      37: new           #68                 // class java/util/LinkedHashSet
      40: dup
      41: invokespecial #70                 // Method java/util/LinkedHashSet."<init>":()V
      44: checkcast     #72                 // class java/util/Set
      47: astore        4
      49: aload_3
      50: checkcast     #74                 // class java/util/Collection
      53: invokeinterface #78,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      58: ifne          65
      61: iconst_1
      62: goto          66
      65: iconst_0
      66: ifeq          334
      69: aload_3
      70: invokeinterface #84,  1           // InterfaceMethod java/util/List.removeFirst:()Ljava/lang/Object;
      75: dup
      76: ldc           #86                 // String removeFirst(...)
      78: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      81: checkcast     #56                 // class day24/State
      84: astore        5
      86: aload         4
      88: aload         5
      90: invokeinterface #93,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      95: ifne          49
      98: getstatic     #97                 // Field valleySequence:Ljava/util/List;
     101: aload         5
     103: invokevirtual #100                // Method day24/State.getStep:()I
     106: iconst_1
     107: iadd
     108: invokeinterface #104,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     113: checkcast     #106                // class java/util/Map
     116: astore        6
     118: aload         5
     120: invokevirtual #110                // Method day24/State.getPoint:()LPoint;
     123: invokestatic  #114                // Method validNeighboursFor:(LPoint;)Ljava/util/List;
     126: checkcast     #116                // class java/lang/Iterable
     129: astore        8
     131: iconst_0
     132: istore        9
     134: aload         8
     136: astore        10
     138: new           #118                // class java/util/ArrayList
     141: dup
     142: invokespecial #119                // Method java/util/ArrayList."<init>":()V
     145: checkcast     #74                 // class java/util/Collection
     148: astore        11
     150: iconst_0
     151: istore        12
     153: aload         10
     155: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     160: astore        13
     162: aload         13
     164: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     169: ifeq          214
     172: aload         13
     174: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     179: astore        14
     181: aload         14
     183: checkcast     #133                // class Point
     186: astore        15
     188: iconst_0
     189: istore        16
     191: aload         6
     193: aload         15
     195: invokestatic  #137                // Method isOpenAt:(Ljava/util/Map;LPoint;)Z
     198: ifeq          162
     201: aload         11
     203: aload         14
     205: invokeinterface #140,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     210: pop
     211: goto          162
     214: aload         11
     216: checkcast     #80                 // class java/util/List
     219: nop
     220: astore        7
     222: aload         7
     224: aload_2
     225: invokeinterface #141,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     230: ifeq          241
     233: aload         5
     235: invokevirtual #100                // Method day24/State.getStep:()I
     238: iconst_1
     239: iadd
     240: ireturn
     241: aload         4
     243: checkcast     #74                 // class java/util/Collection
     246: aload         5
     248: invokeinterface #140,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     253: pop
     254: aload         7
     256: checkcast     #116                // class java/lang/Iterable
     259: astore        8
     261: iconst_0
     262: istore        9
     264: aload         8
     266: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     271: astore        10
     273: aload         10
     275: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     280: ifeq          330
     283: aload         10
     285: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     290: astore        11
     292: aload         11
     294: checkcast     #133                // class Point
     297: astore        12
     299: iconst_0
     300: istore        13
     302: aload_3
     303: new           #56                 // class day24/State
     306: dup
     307: aload         12
     309: aload         5
     311: invokevirtual #100                // Method day24/State.getStep:()I
     314: iconst_1
     315: iadd
     316: invokespecial #60                 // Method day24/State."<init>":(LPoint;I)V
     319: invokeinterface #142,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     324: pop
     325: nop
     326: nop
     327: goto          273
     330: nop
     331: goto          49
     334: new           #144                // class java/lang/IllegalStateException
     337: dup
     338: ldc           #146                // String lost in the vally of blizzards
     340: invokevirtual #150                // Method java/lang/Object.toString:()Ljava/lang/String;
     343: invokespecial #153                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     346: athrow

  public static int findPath$default(Point, int, Point, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          10
       6: getstatic     #36                 // Field start:LPoint;
       9: astore_0
      10: iload_3
      11: iconst_2
      12: iand
      13: ifeq          18
      16: iconst_0
      17: istore_1
      18: iload_3
      19: iconst_4
      20: iand
      21: ifeq          28
      24: getstatic     #33                 // Field exit:LPoint;
      27: astore_2
      28: aload_0
      29: iload_1
      30: aload_2
      31: invokestatic  #40                 // Method findPath:(LPoint;ILPoint;)I
      34: ireturn

  public static final java.util.Map<Point, java.util.List<day24.Blizzard>> toValley(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #182                // String <this>
       3: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #184                // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #185                // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #106                // class java/util/Map
      16: astore_1
      17: aload_0
      18: checkcast     #116                // class java/lang/Iterable
      21: astore_2
      22: iconst_0
      23: istore_3
      24: aload_2
      25: astore        4
      27: new           #118                // class java/util/ArrayList
      30: dup
      31: aload_2
      32: bipush        10
      34: invokestatic  #189                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      37: invokespecial #191                // Method java/util/ArrayList."<init>":(I)V
      40: checkcast     #74                 // class java/util/Collection
      43: astore        5
      45: iconst_0
      46: istore        6
      48: iconst_0
      49: istore        7
      51: aload         4
      53: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        8
      60: aload         8
      62: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          399
      70: aload         8
      72: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        9
      79: aload         5
      81: iload         7
      83: iinc          7, 1
      86: istore        10
      88: iload         10
      90: ifge          96
      93: invokestatic  #194                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      96: iload         10
      98: aload         9
     100: checkcast     #196                // class java/lang/String
     103: astore        11
     105: istore        12
     107: astore        27
     109: iconst_0
     110: istore        13
     112: aload         11
     114: checkcast     #198                // class java/lang/CharSequence
     117: astore        14
     119: iconst_0
     120: istore        15
     122: aload         14
     124: astore        16
     126: new           #118                // class java/util/ArrayList
     129: dup
     130: aload         14
     132: invokeinterface #201,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     137: invokespecial #191                // Method java/util/ArrayList."<init>":(I)V
     140: checkcast     #74                 // class java/util/Collection
     143: astore        17
     145: iconst_0
     146: istore        18
     148: iconst_0
     149: istore        19
     151: iconst_0
     152: istore        20
     154: iload         20
     156: aload         16
     158: invokeinterface #201,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     163: if_icmpge     380
     166: aload         16
     168: iload         20
     170: invokeinterface #205,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     175: istore        21
     177: aload         17
     179: iload         19
     181: iinc          19, 1
     184: iload         21
     186: istore        22
     188: istore        23
     190: astore        24
     192: iconst_0
     193: istore        25
     195: new           #133                // class Point
     198: dup
     199: iload         23
     201: iload         12
     203: invokespecial #208                // Method Point."<init>":(II)V
     206: astore        26
     208: iload         22
     210: lookupswitch  { // 5
                    35: 332
                    60: 296
                    62: 314
                    94: 260
                   118: 278
               default: 350
          }
     260: aload_1
     261: aload         26
     263: getstatic     #214                // Field day24/Blizzard.UP:Lday24/Blizzard;
     266: invokestatic  #218                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     269: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     274: pop
     275: goto          362
     278: aload_1
     279: aload         26
     281: getstatic     #225                // Field day24/Blizzard.DOWN:Lday24/Blizzard;
     284: invokestatic  #218                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     287: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     292: pop
     293: goto          362
     296: aload_1
     297: aload         26
     299: getstatic     #228                // Field day24/Blizzard.LEFT:Lday24/Blizzard;
     302: invokestatic  #218                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     305: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     310: pop
     311: goto          362
     314: aload_1
     315: aload         26
     317: getstatic     #231                // Field day24/Blizzard.RIGHT:Lday24/Blizzard;
     320: invokestatic  #218                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     323: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     328: pop
     329: goto          362
     332: aload_1
     333: aload         26
     335: getstatic     #234                // Field day24/Blizzard.WALL:Lday24/Blizzard;
     338: invokestatic  #218                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     341: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     346: pop
     347: goto          362
     350: aload_1
     351: aload         26
     353: invokestatic  #238                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     356: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     361: pop
     362: nop
     363: aload         24
     365: getstatic     #244                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     368: invokeinterface #140,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     373: pop
     374: iinc          20, 1
     377: goto          154
     380: aload         17
     382: checkcast     #80                 // class java/util/List
     385: nop
     386: nop
     387: aload         27
     389: swap
     390: invokeinterface #140,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     395: pop
     396: goto          60
     399: aload         5
     401: checkcast     #80                 // class java/util/List
     404: nop
     405: pop
     406: aload_1
     407: areturn

  public static final java.util.List<Point> validNeighboursFor(Point);
    Code:
       0: aload_0
       1: ldc_w         #264                // String p
       4: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: iconst_1
       9: invokevirtual #267                // Method Point.neighbours:(Z)Ljava/util/List;
      12: checkcast     #116                // class java/lang/Iterable
      15: astore_1
      16: nop
      17: iconst_0
      18: istore_2
      19: aload_1
      20: astore_3
      21: new           #118                // class java/util/ArrayList
      24: dup
      25: invokespecial #119                // Method java/util/ArrayList."<init>":()V
      28: checkcast     #74                 // class java/util/Collection
      31: astore        4
      33: iconst_0
      34: istore        5
      36: aload_3
      37: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        6
      44: aload         6
      46: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          100
      54: aload         6
      56: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        7
      63: aload         7
      65: checkcast     #133                // class Point
      68: astore        8
      70: iconst_0
      71: istore        9
      73: getstatic     #270                // Field walls:Ljava/util/Map;
      76: aload         8
      78: invokeinterface #273,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      83: nop
      84: ifne          44
      87: aload         4
      89: aload         7
      91: invokeinterface #140,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      96: pop
      97: goto          44
     100: aload         4
     102: checkcast     #80                 // class java/util/List
     105: nop
     106: checkcast     #116                // class java/lang/Iterable
     109: astore_1
     110: nop
     111: iconst_0
     112: istore_2
     113: aload_1
     114: astore_3
     115: new           #118                // class java/util/ArrayList
     118: dup
     119: invokespecial #119                // Method java/util/ArrayList."<init>":()V
     122: checkcast     #74                 // class java/util/Collection
     125: astore        4
     127: iconst_0
     128: istore        5
     130: aload_3
     131: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     136: astore        6
     138: aload         6
     140: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     145: ifeq          223
     148: aload         6
     150: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     155: astore        7
     157: aload         7
     159: checkcast     #133                // class Point
     162: astore        8
     164: iconst_0
     165: istore        9
     167: getstatic     #276                // Field minX:I
     170: istore        10
     172: getstatic     #279                // Field maxX:I
     175: istore        11
     177: aload         8
     179: invokevirtual #282                // Method Point.getX:()I
     182: istore        12
     184: iload         10
     186: iload         12
     188: if_icmpgt     206
     191: iload         12
     193: iload         11
     195: if_icmpgt     202
     198: iconst_1
     199: goto          207
     202: iconst_0
     203: goto          207
     206: iconst_0
     207: ifeq          138
     210: aload         4
     212: aload         7
     214: invokeinterface #140,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     219: pop
     220: goto          138
     223: aload         4
     225: checkcast     #80                 // class java/util/List
     228: nop
     229: checkcast     #116                // class java/lang/Iterable
     232: astore_1
     233: nop
     234: iconst_0
     235: istore_2
     236: aload_1
     237: astore_3
     238: new           #118                // class java/util/ArrayList
     241: dup
     242: invokespecial #119                // Method java/util/ArrayList."<init>":()V
     245: checkcast     #74                 // class java/util/Collection
     248: astore        4
     250: iconst_0
     251: istore        5
     253: aload_3
     254: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     259: astore        6
     261: aload         6
     263: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     268: ifeq          346
     271: aload         6
     273: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     278: astore        7
     280: aload         7
     282: checkcast     #133                // class Point
     285: astore        8
     287: iconst_0
     288: istore        9
     290: getstatic     #285                // Field minY:I
     293: istore        10
     295: getstatic     #288                // Field maxY:I
     298: istore        11
     300: aload         8
     302: invokevirtual #291                // Method Point.getY:()I
     305: istore        12
     307: iload         10
     309: iload         12
     311: if_icmpgt     329
     314: iload         12
     316: iload         11
     318: if_icmpgt     325
     321: iconst_1
     322: goto          330
     325: iconst_0
     326: goto          330
     329: iconst_0
     330: ifeq          261
     333: aload         4
     335: aload         7
     337: invokeinterface #140,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     342: pop
     343: goto          261
     346: aload         4
     348: checkcast     #80                 // class java/util/List
     351: nop
     352: areturn

  public static final boolean isOpenAt(java.util.Map<Point, ? extends java.util.List<? extends day24.Blizzard>>, Point);
    Code:
       0: aload_0
       1: ldc           #182                // String <this>
       3: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc_w         #264                // String p
      10: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: aload_0
      14: aload_1
      15: invokeinterface #302,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      20: checkcast     #74                 // class java/util/Collection
      23: astore_2
      24: aload_2
      25: ifnull        37
      28: aload_2
      29: invokeinterface #78,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      34: ifeq          41
      37: iconst_1
      38: goto          42
      41: iconst_0
      42: ireturn

  public static final java.util.Map<Point, java.util.List<day24.Blizzard>> step(java.util.Map<Point, ? extends java.util.List<? extends day24.Blizzard>>);
    Code:
       0: aload_0
       1: ldc           #182                // String <this>
       3: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_2
       7: anewarray     #308                // class kotlin/Pair
      10: astore_1
      11: aload_1
      12: iconst_0
      13: getstatic     #36                 // Field start:LPoint;
      16: new           #118                // class java/util/ArrayList
      19: dup
      20: invokespecial #119                // Method java/util/ArrayList."<init>":()V
      23: checkcast     #80                 // class java/util/List
      26: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      29: aastore
      30: aload_1
      31: iconst_1
      32: getstatic     #33                 // Field exit:LPoint;
      35: new           #118                // class java/util/ArrayList
      38: dup
      39: invokespecial #119                // Method java/util/ArrayList."<init>":()V
      42: checkcast     #80                 // class java/util/List
      45: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      48: aastore
      49: aload_1
      50: invokestatic  #320                // Method kotlin/collections/MapsKt.mutableMapOf:([Lkotlin/Pair;)Ljava/util/Map;
      53: astore_2
      54: iconst_0
      55: istore_3
      56: new           #322                // class kotlin/ranges/IntRange
      59: dup
      60: getstatic     #276                // Field minX:I
      63: getstatic     #279                // Field maxX:I
      66: invokespecial #323                // Method kotlin/ranges/IntRange."<init>":(II)V
      69: checkcast     #116                // class java/lang/Iterable
      72: astore        4
      74: iconst_0
      75: istore        5
      77: aload         4
      79: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      84: astore        6
      86: aload         6
      88: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      93: ifeq          524
      96: aload         6
      98: checkcast     #325                // class kotlin/collections/IntIterator
     101: invokevirtual #328                // Method kotlin/collections/IntIterator.nextInt:()I
     104: istore        7
     106: iload         7
     108: istore        8
     110: iconst_0
     111: istore        9
     113: new           #322                // class kotlin/ranges/IntRange
     116: dup
     117: getstatic     #285                // Field minY:I
     120: getstatic     #288                // Field maxY:I
     123: invokespecial #323                // Method kotlin/ranges/IntRange."<init>":(II)V
     126: checkcast     #116                // class java/lang/Iterable
     129: astore        10
     131: iconst_0
     132: istore        11
     134: aload         10
     136: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     141: astore        12
     143: aload         12
     145: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     150: ifeq          518
     153: aload         12
     155: checkcast     #325                // class kotlin/collections/IntIterator
     158: invokevirtual #328                // Method kotlin/collections/IntIterator.nextInt:()I
     161: istore        13
     163: iload         13
     165: istore        14
     167: iconst_0
     168: istore        15
     170: new           #133                // class Point
     173: dup
     174: iload         8
     176: iload         14
     178: invokespecial #208                // Method Point."<init>":(II)V
     181: astore        16
     183: aload_0
     184: aload         16
     186: invokeinterface #302,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     191: checkcast     #80                 // class java/util/List
     194: astore        17
     196: aload         17
     198: checkcast     #74                 // class java/util/Collection
     201: astore        18
     203: aload         18
     205: ifnull        218
     208: aload         18
     210: invokeinterface #78,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     215: ifeq          222
     218: iconst_1
     219: goto          223
     222: iconst_0
     223: ifne          513
     226: aload         17
     228: checkcast     #116                // class java/lang/Iterable
     231: astore        18
     233: iconst_0
     234: istore        19
     236: aload         18
     238: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     243: astore        20
     245: aload         20
     247: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     252: ifeq          512
     255: aload         20
     257: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     262: astore        21
     264: aload         21
     266: checkcast     #210                // class day24/Blizzard
     269: astore        22
     271: iconst_0
     272: istore        23
     274: aload         16
     276: aload         22
     278: invokevirtual #331                // Method day24/Blizzard.getOffset:()LPoint;
     281: invokevirtual #335                // Method Point.plus:(LPoint;)LPoint;
     284: astore        24
     286: getstatic     #270                // Field walls:Ljava/util/Map;
     289: aload         24
     291: invokeinterface #273,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     296: ifeq          436
     299: aload         22
     301: getstatic     #341                // Field day24/Day24Kt$WhenMappings.$EnumSwitchMapping$0:[I
     304: swap
     305: invokevirtual #344                // Method day24/Blizzard.ordinal:()I
     308: iaload
     309: tableswitch   { // 1 to 5
                     1: 344
                     2: 361
                     3: 378
                     4: 395
                     5: 412
               default: 426
          }
     344: new           #133                // class Point
     347: dup
     348: getstatic     #279                // Field maxX:I
     351: iconst_1
     352: isub
     353: iload         14
     355: invokespecial #208                // Method Point."<init>":(II)V
     358: goto          434
     361: new           #133                // class Point
     364: dup
     365: getstatic     #276                // Field minX:I
     368: iconst_1
     369: iadd
     370: iload         14
     372: invokespecial #208                // Method Point."<init>":(II)V
     375: goto          434
     378: new           #133                // class Point
     381: dup
     382: iload         8
     384: getstatic     #288                // Field maxY:I
     387: iconst_1
     388: isub
     389: invokespecial #208                // Method Point."<init>":(II)V
     392: goto          434
     395: new           #133                // class Point
     398: dup
     399: iload         8
     401: getstatic     #285                // Field minY:I
     404: iconst_1
     405: iadd
     406: invokespecial #208                // Method Point."<init>":(II)V
     409: goto          434
     412: new           #133                // class Point
     415: dup
     416: iload         8
     418: iload         14
     420: invokespecial #208                // Method Point."<init>":(II)V
     423: goto          434
     426: new           #346                // class kotlin/NoWhenBranchMatchedException
     429: dup
     430: invokespecial #347                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     433: athrow
     434: astore        24
     436: aload_2
     437: aload         24
     439: invokeinterface #302,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     444: ifnonnull     484
     447: aload_2
     448: astore        25
     450: iconst_1
     451: anewarray     #210                // class day24/Blizzard
     454: astore        26
     456: aload         26
     458: iconst_0
     459: aload         22
     461: aastore
     462: aload         26
     464: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
     467: astore        26
     469: aload         25
     471: aload         24
     473: aload         26
     475: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     480: pop
     481: goto          507
     484: aload_2
     485: aload         24
     487: invokeinterface #302,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     492: dup
     493: invokestatic  #351                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     496: checkcast     #80                 // class java/util/List
     499: aload         22
     501: invokeinterface #142,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     506: pop
     507: nop
     508: nop
     509: goto          245
     512: nop
     513: nop
     514: nop
     515: goto          143
     518: nop
     519: nop
     520: nop
     521: goto          86
     524: nop
     525: aload_2
     526: nop
     527: areturn

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

  private static final java.util.Map valleySequence$lambda$9(java.util.Map);
    Code:
       0: aload_0
       1: ldc_w         #370                // String it
       4: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokestatic  #372                // Method step:(Ljava/util/Map;)Ljava/util/Map;
      11: areturn

  static {};
    Code:
       0: ldc_w         #375                // String main/day24/Day24
       3: invokestatic  #381                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       6: invokestatic  #383                // Method toValley:(Ljava/util/List;)Ljava/util/Map;
       9: putstatic     #386                // Field initialValley:Ljava/util/Map;
      12: getstatic     #386                // Field initialValley:Ljava/util/Map;
      15: invokeinterface #390,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
      20: checkcast     #116                // class java/lang/Iterable
      23: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      28: astore_1
      29: aload_1
      30: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      35: ifne          46
      38: new           #392                // class java/util/NoSuchElementException
      41: dup
      42: invokespecial #393                // Method java/util/NoSuchElementException."<init>":()V
      45: athrow
      46: aload_1
      47: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: checkcast     #133                // class Point
      55: astore_2
      56: iconst_0
      57: istore_3
      58: aload_2
      59: invokevirtual #282                // Method Point.getX:()I
      62: istore_2
      63: aload_1
      64: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      69: ifeq          100
      72: aload_1
      73: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      78: checkcast     #133                // class Point
      81: astore_3
      82: iconst_0
      83: istore        4
      85: aload_3
      86: invokevirtual #282                // Method Point.getX:()I
      89: istore_3
      90: iload_2
      91: iload_3
      92: if_icmpge     63
      95: iload_3
      96: istore_2
      97: goto          63
     100: iload_2
     101: putstatic     #279                // Field maxX:I
     104: getstatic     #386                // Field initialValley:Ljava/util/Map;
     107: invokeinterface #390,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     112: checkcast     #116                // class java/lang/Iterable
     115: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     120: astore_1
     121: aload_1
     122: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     127: ifne          138
     130: new           #392                // class java/util/NoSuchElementException
     133: dup
     134: invokespecial #393                // Method java/util/NoSuchElementException."<init>":()V
     137: athrow
     138: aload_1
     139: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     144: checkcast     #133                // class Point
     147: astore_2
     148: iconst_0
     149: istore_3
     150: aload_2
     151: invokevirtual #282                // Method Point.getX:()I
     154: istore_2
     155: aload_1
     156: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     161: ifeq          192
     164: aload_1
     165: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     170: checkcast     #133                // class Point
     173: astore_3
     174: iconst_0
     175: istore        4
     177: aload_3
     178: invokevirtual #282                // Method Point.getX:()I
     181: istore_3
     182: iload_2
     183: iload_3
     184: if_icmple     155
     187: iload_3
     188: istore_2
     189: goto          155
     192: iload_2
     193: putstatic     #276                // Field minX:I
     196: getstatic     #386                // Field initialValley:Ljava/util/Map;
     199: invokeinterface #390,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     204: checkcast     #116                // class java/lang/Iterable
     207: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     212: astore_1
     213: aload_1
     214: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     219: ifne          230
     222: new           #392                // class java/util/NoSuchElementException
     225: dup
     226: invokespecial #393                // Method java/util/NoSuchElementException."<init>":()V
     229: athrow
     230: aload_1
     231: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     236: checkcast     #133                // class Point
     239: astore_2
     240: iconst_0
     241: istore_3
     242: aload_2
     243: invokevirtual #291                // Method Point.getY:()I
     246: istore_2
     247: aload_1
     248: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     253: ifeq          284
     256: aload_1
     257: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     262: checkcast     #133                // class Point
     265: astore_3
     266: iconst_0
     267: istore        4
     269: aload_3
     270: invokevirtual #291                // Method Point.getY:()I
     273: istore_3
     274: iload_2
     275: iload_3
     276: if_icmpge     247
     279: iload_3
     280: istore_2
     281: goto          247
     284: iload_2
     285: putstatic     #288                // Field maxY:I
     288: getstatic     #386                // Field initialValley:Ljava/util/Map;
     291: invokeinterface #390,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     296: checkcast     #116                // class java/lang/Iterable
     299: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     304: astore_1
     305: aload_1
     306: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     311: ifne          322
     314: new           #392                // class java/util/NoSuchElementException
     317: dup
     318: invokespecial #393                // Method java/util/NoSuchElementException."<init>":()V
     321: athrow
     322: aload_1
     323: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     328: checkcast     #133                // class Point
     331: astore_2
     332: iconst_0
     333: istore_3
     334: aload_2
     335: invokevirtual #291                // Method Point.getY:()I
     338: istore_2
     339: aload_1
     340: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     345: ifeq          376
     348: aload_1
     349: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     354: checkcast     #133                // class Point
     357: astore_3
     358: iconst_0
     359: istore        4
     361: aload_3
     362: invokevirtual #291                // Method Point.getY:()I
     365: istore_3
     366: iload_2
     367: iload_3
     368: if_icmple     339
     371: iload_3
     372: istore_2
     373: goto          339
     376: iload_2
     377: putstatic     #285                // Field minY:I
     380: getstatic     #386                // Field initialValley:Ljava/util/Map;
     383: astore_0
     384: iconst_0
     385: istore_1
     386: aload_0
     387: astore_2
     388: new           #184                // class java/util/LinkedHashMap
     391: dup
     392: invokespecial #185                // Method java/util/LinkedHashMap."<init>":()V
     395: checkcast     #106                // class java/util/Map
     398: astore_3
     399: iconst_0
     400: istore        4
     402: aload_2
     403: invokeinterface #396,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     408: invokeinterface #397,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     413: astore        5
     415: aload         5
     417: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     422: ifeq          495
     425: aload         5
     427: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     432: checkcast     #399                // class java/util/Map$Entry
     435: astore        6
     437: aload         6
     439: astore        7
     441: iconst_0
     442: istore        8
     444: aload         7
     446: invokeinterface #402,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     451: checkcast     #133                // class Point
     454: invokevirtual #291                // Method Point.getY:()I
     457: getstatic     #285                // Field minY:I
     460: if_icmpne     467
     463: iconst_1
     464: goto          468
     467: iconst_0
     468: ifeq          415
     471: aload_3
     472: aload         6
     474: invokeinterface #402,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     479: aload         6
     481: invokeinterface #405,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     486: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     491: pop
     492: goto          415
     495: aload_3
     496: nop
     497: invokeinterface #390,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     502: checkcast     #116                // class java/lang/Iterable
     505: astore_0
     506: iconst_0
     507: istore_1
     508: aload_0
     509: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     514: astore_2
     515: aload_2
     516: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     521: ifeq          569
     524: aload_2
     525: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     530: astore_3
     531: aload_3
     532: checkcast     #133                // class Point
     535: astore        4
     537: iconst_0
     538: istore        5
     540: getstatic     #386                // Field initialValley:Ljava/util/Map;
     543: aload         4
     545: invokeinterface #302,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     550: dup
     551: invokestatic  #351                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     554: checkcast     #80                 // class java/util/List
     557: invokeinterface #406,  1          // InterfaceMethod java/util/List.isEmpty:()Z
     562: ifeq          515
     565: aload_3
     566: goto          580
     569: new           #392                // class java/util/NoSuchElementException
     572: dup
     573: ldc_w         #408                // String Collection contains no element matching the predicate.
     576: invokespecial #409                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     579: athrow
     580: checkcast     #133                // class Point
     583: putstatic     #36                 // Field start:LPoint;
     586: getstatic     #386                // Field initialValley:Ljava/util/Map;
     589: astore_0
     590: iconst_0
     591: istore_1
     592: aload_0
     593: astore_2
     594: new           #184                // class java/util/LinkedHashMap
     597: dup
     598: invokespecial #185                // Method java/util/LinkedHashMap."<init>":()V
     601: checkcast     #106                // class java/util/Map
     604: astore_3
     605: iconst_0
     606: istore        4
     608: aload_2
     609: invokeinterface #396,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     614: invokeinterface #397,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     619: astore        5
     621: aload         5
     623: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     628: ifeq          701
     631: aload         5
     633: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     638: checkcast     #399                // class java/util/Map$Entry
     641: astore        6
     643: aload         6
     645: astore        7
     647: iconst_0
     648: istore        8
     650: aload         7
     652: invokeinterface #402,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     657: checkcast     #133                // class Point
     660: invokevirtual #291                // Method Point.getY:()I
     663: getstatic     #288                // Field maxY:I
     666: if_icmpne     673
     669: iconst_1
     670: goto          674
     673: iconst_0
     674: ifeq          621
     677: aload_3
     678: aload         6
     680: invokeinterface #402,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     685: aload         6
     687: invokeinterface #405,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     692: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     697: pop
     698: goto          621
     701: aload_3
     702: nop
     703: invokeinterface #390,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     708: checkcast     #116                // class java/lang/Iterable
     711: astore_0
     712: iconst_0
     713: istore_1
     714: aload_0
     715: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     720: astore_2
     721: aload_2
     722: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     727: ifeq          775
     730: aload_2
     731: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     736: astore_3
     737: aload_3
     738: checkcast     #133                // class Point
     741: astore        4
     743: iconst_0
     744: istore        5
     746: getstatic     #386                // Field initialValley:Ljava/util/Map;
     749: aload         4
     751: invokeinterface #302,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     756: dup
     757: invokestatic  #351                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     760: checkcast     #80                 // class java/util/List
     763: invokeinterface #406,  1          // InterfaceMethod java/util/List.isEmpty:()Z
     768: ifeq          721
     771: aload_3
     772: goto          786
     775: new           #392                // class java/util/NoSuchElementException
     778: dup
     779: ldc_w         #408                // String Collection contains no element matching the predicate.
     782: invokespecial #409                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     785: athrow
     786: checkcast     #133                // class Point
     789: putstatic     #33                 // Field exit:LPoint;
     792: getstatic     #386                // Field initialValley:Ljava/util/Map;
     795: astore_0
     796: iconst_0
     797: istore_1
     798: aload_0
     799: astore_2
     800: new           #184                // class java/util/LinkedHashMap
     803: dup
     804: invokespecial #185                // Method java/util/LinkedHashMap."<init>":()V
     807: checkcast     #106                // class java/util/Map
     810: astore_3
     811: iconst_0
     812: istore        4
     814: aload_2
     815: invokeinterface #396,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     820: invokeinterface #397,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     825: astore        5
     827: aload         5
     829: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     834: ifeq          907
     837: aload         5
     839: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     844: checkcast     #399                // class java/util/Map$Entry
     847: astore        6
     849: aload         6
     851: astore        7
     853: iconst_0
     854: istore        8
     856: aload         7
     858: invokeinterface #405,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     863: checkcast     #80                 // class java/util/List
     866: invokestatic  #413                // Method kotlin/collections/CollectionsKt.firstOrNull:(Ljava/util/List;)Ljava/lang/Object;
     869: getstatic     #234                // Field day24/Blizzard.WALL:Lday24/Blizzard;
     872: if_acmpne     879
     875: iconst_1
     876: goto          880
     879: iconst_0
     880: ifeq          827
     883: aload_3
     884: aload         6
     886: invokeinterface #402,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     891: aload         6
     893: invokeinterface #405,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     898: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     903: pop
     904: goto          827
     907: aload_3
     908: nop
     909: putstatic     #270                // Field walls:Ljava/util/Map;
     912: getstatic     #386                // Field initialValley:Ljava/util/Map;
     915: invokedynamic #429,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     920: invokestatic  #435                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     923: sipush        1000
     926: invokestatic  #439                // Method kotlin/sequences/SequencesKt.take:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
     929: invokestatic  #443                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     932: putstatic     #97                 // Field valleySequence:Ljava/util/List;
     935: return
}


package day12

import Point
import readInput

typealias Grid = MutableMap<Point, Char>

fun main() {
    val input = readInput("main/day12/Day12")

    println(part1(input))
    println(part2(input))
}

fun part1(input: List<String>): Int = input.solveFor('S')

fun part2(input: List<String>): Int = input.solveFor('a')

fun List<String>.solveFor(start: Char): Int {
    val grid = parse()

    val startPoint = grid.filter { it.value == 'S' }.keys.first()
    val goal = grid.filterValues { it == 'E' }.keys.first()

    grid[goal] = 'z'

    return grid.filter { it.value == start }.mapNotNull {
        grid[startPoint] = 'a'
        distance(it.key, goal, grid)
    }.minOf { it }
}

private fun distance(start: Point, goal: Point, grid: Grid): Int? {
    // the metaphor is to "flood" the terrain with water, always going in all 4 directions if the neighbouring point is not too high
    // and keep track of the distance.
    // As soon as the goal is "wet", we have our result

    val lake = mutableMapOf(start to 0)
    var distance = 0
    var currentSize = 0
    do {
        currentSize = lake.size
        distance = grid.floodValley(lake, distance)
    } while (!lake.containsKey(goal) && lake.size > currentSize)

    if (lake.size <= currentSize) {
        // there is no valid path from start to goal
        return null
    }
    return distance
}

fun Grid.floodValley(lake: MutableMap<Point, Int>, distance: Int): Int {
    lake.filterValues { it == distance }.forEach { (point, _) ->
        point.neighbours().filter {
            this[it] != null && this[it]!! - this[point]!! <= 1
        }.forEach {
            if (!lake.containsKey(it)) lake[it] = distance + 1
        }
    }
    return distance + 1
}

fun List<String>.parse(): Grid {
    val result = mutableMapOf<Point, Char>()
    forEachIndexed { y, line ->
        line.forEachIndexed { x, c ->
            result[Point(x, y)] = c
        }
    }
    return result
}

Compiled from "day12.kt"
public final class day12.Day12Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String main/day12/Day12
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method part1:(Ljava/util/List;)I
      10: istore_1
      11: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: iload_1
      15: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      18: aload_0
      19: invokestatic  #33                 // Method part2:(Ljava/util/List;)I
      22: istore_1
      23: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: iload_1
      27: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      30: return

  public static final int part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #38                 // String input
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: bipush        83
       9: invokestatic  #48                 // Method solveFor:(Ljava/util/List;C)I
      12: ireturn

  public static final int part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #38                 // String input
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: bipush        97
       9: invokestatic  #48                 // Method solveFor:(Ljava/util/List;C)I
      12: ireturn

  public static final int solveFor(java.util.List<java.lang.String>, char);
    Code:
       0: aload_0
       1: ldc           #51                 // String <this>
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #55                 // Method parse:(Ljava/util/List;)Ljava/util/Map;
      10: astore_2
      11: aload_2
      12: astore        4
      14: iconst_0
      15: istore        5
      17: aload         4
      19: astore        6
      21: new           #57                 // class java/util/LinkedHashMap
      24: dup
      25: invokespecial #60                 // Method java/util/LinkedHashMap."<init>":()V
      28: checkcast     #62                 // class java/util/Map
      31: astore        7
      33: iconst_0
      34: istore        8
      36: aload         6
      38: invokeinterface #66,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      43: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      48: astore        9
      50: aload         9
      52: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          130
      60: aload         9
      62: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: checkcast     #84                 // class java/util/Map$Entry
      70: astore        10
      72: aload         10
      74: astore        11
      76: iconst_0
      77: istore        12
      79: aload         11
      81: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      86: checkcast     #89                 // class java/lang/Character
      89: invokevirtual #93                 // Method java/lang/Character.charValue:()C
      92: bipush        83
      94: if_icmpne     101
      97: iconst_1
      98: goto          102
     101: iconst_0
     102: ifeq          50
     105: aload         7
     107: aload         10
     109: invokeinterface #96,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     114: aload         10
     116: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     121: invokeinterface #100,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     126: pop
     127: goto          50
     130: aload         7
     132: nop
     133: invokeinterface #103,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     138: checkcast     #105                // class java/lang/Iterable
     141: invokestatic  #111                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
     144: checkcast     #113                // class Point
     147: astore_3
     148: aload_2
     149: astore        5
     151: iconst_0
     152: istore        6
     154: new           #57                 // class java/util/LinkedHashMap
     157: dup
     158: invokespecial #60                 // Method java/util/LinkedHashMap."<init>":()V
     161: astore        7
     163: aload         5
     165: invokeinterface #66,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     170: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     175: astore        8
     177: aload         8
     179: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     184: ifeq          255
     187: aload         8
     189: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     194: checkcast     #84                 // class java/util/Map$Entry
     197: astore        9
     199: aload         9
     201: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     206: checkcast     #89                 // class java/lang/Character
     209: invokevirtual #93                 // Method java/lang/Character.charValue:()C
     212: istore        10
     214: iconst_0
     215: istore        11
     217: iload         10
     219: bipush        69
     221: if_icmpne     228
     224: iconst_1
     225: goto          229
     228: iconst_0
     229: ifeq          177
     232: aload         7
     234: aload         9
     236: invokeinterface #96,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     241: aload         9
     243: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     248: invokevirtual #114                // Method java/util/LinkedHashMap.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     251: pop
     252: goto          177
     255: aload         7
     257: checkcast     #62                 // class java/util/Map
     260: invokeinterface #103,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     265: checkcast     #105                // class java/lang/Iterable
     268: invokestatic  #111                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
     271: checkcast     #113                // class Point
     274: astore        4
     276: aload_2
     277: aload         4
     279: bipush        122
     281: invokestatic  #118                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     284: invokeinterface #100,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     289: pop
     290: aload_2
     291: astore        5
     293: iconst_0
     294: istore        6
     296: aload         5
     298: astore        7
     300: new           #57                 // class java/util/LinkedHashMap
     303: dup
     304: invokespecial #60                 // Method java/util/LinkedHashMap."<init>":()V
     307: checkcast     #62                 // class java/util/Map
     310: astore        8
     312: iconst_0
     313: istore        9
     315: aload         7
     317: invokeinterface #66,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     322: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     327: astore        10
     329: aload         10
     331: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     336: ifeq          408
     339: aload         10
     341: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     346: checkcast     #84                 // class java/util/Map$Entry
     349: astore        11
     351: aload         11
     353: astore        12
     355: iconst_0
     356: istore        13
     358: aload         12
     360: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     365: checkcast     #89                 // class java/lang/Character
     368: invokevirtual #93                 // Method java/lang/Character.charValue:()C
     371: iload_1
     372: if_icmpne     379
     375: iconst_1
     376: goto          380
     379: iconst_0
     380: ifeq          329
     383: aload         8
     385: aload         11
     387: invokeinterface #96,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     392: aload         11
     394: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     399: invokeinterface #100,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     404: pop
     405: goto          329
     408: aload         8
     410: nop
     411: astore        5
     413: nop
     414: iconst_0
     415: istore        6
     417: aload         5
     419: astore        7
     421: new           #120                // class java/util/ArrayList
     424: dup
     425: invokespecial #121                // Method java/util/ArrayList."<init>":()V
     428: checkcast     #123                // class java/util/Collection
     431: astore        8
     433: iconst_0
     434: istore        9
     436: aload         7
     438: astore        10
     440: iconst_0
     441: istore        11
     443: aload         10
     445: invokeinterface #66,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     450: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     455: astore        12
     457: aload         12
     459: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     464: ifeq          549
     467: aload         12
     469: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     474: checkcast     #84                 // class java/util/Map$Entry
     477: astore        13
     479: aload         13
     481: astore        14
     483: iconst_0
     484: istore        15
     486: aload         14
     488: astore        16
     490: iconst_0
     491: istore        17
     493: aload_2
     494: aload_3
     495: bipush        97
     497: invokestatic  #118                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     500: invokeinterface #100,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     505: pop
     506: aload         16
     508: invokeinterface #96,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     513: checkcast     #113                // class Point
     516: aload         4
     518: aload_2
     519: invokestatic  #127                // Method distance:(LPoint;LPoint;Ljava/util/Map;)Ljava/lang/Integer;
     522: dup
     523: ifnull        544
     526: astore        18
     528: iconst_0
     529: istore        19
     531: aload         8
     533: aload         18
     535: invokeinterface #131,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     540: pop
     541: goto          545
     544: pop
     545: nop
     546: goto          457
     549: nop
     550: aload         8
     552: checkcast     #133                // class java/util/List
     555: nop
     556: checkcast     #105                // class java/lang/Iterable
     559: invokeinterface #134,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     564: astore        6
     566: aload         6
     568: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     573: ifne          584
     576: new           #136                // class java/util/NoSuchElementException
     579: dup
     580: invokespecial #137                // Method java/util/NoSuchElementException."<init>":()V
     583: athrow
     584: aload         6
     586: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     591: checkcast     #139                // class java/lang/Number
     594: invokevirtual #143                // Method java/lang/Number.intValue:()I
     597: istore        7
     599: iconst_0
     600: istore        8
     602: iload         7
     604: istore        7
     606: aload         6
     608: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     613: ifeq          652
     616: aload         6
     618: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     623: checkcast     #139                // class java/lang/Number
     626: invokevirtual #143                // Method java/lang/Number.intValue:()I
     629: istore        8
     631: iconst_0
     632: istore        9
     634: iload         8
     636: istore        8
     638: iload         7
     640: iload         8
     642: if_icmple     606
     645: iload         8
     647: istore        7
     649: goto          606
     652: iload         7
     654: ireturn

  private static final java.lang.Integer distance(Point, Point, java.util.Map<Point, java.lang.Character>);
    Code:
       0: iconst_1
       1: anewarray     #187                // class kotlin/Pair
       4: astore        4
       6: aload         4
       8: iconst_0
       9: aload_0
      10: iconst_0
      11: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      14: invokestatic  #196                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      17: aastore
      18: aload         4
      20: invokestatic  #202                // Method kotlin/collections/MapsKt.mutableMapOf:([Lkotlin/Pair;)Ljava/util/Map;
      23: astore_3
      24: iconst_0
      25: istore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #205,  1          // InterfaceMethod java/util/Map.size:()I
      36: istore        5
      38: aload_2
      39: aload_3
      40: iload         4
      42: invokestatic  #209                // Method floodValley:(Ljava/util/Map;Ljava/util/Map;I)I
      45: istore        4
      47: aload_3
      48: aload_1
      49: invokeinterface #212,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      54: ifne          68
      57: aload_3
      58: invokeinterface #205,  1          // InterfaceMethod java/util/Map.size:()I
      63: iload         5
      65: if_icmpgt     30
      68: aload_3
      69: invokeinterface #205,  1          // InterfaceMethod java/util/Map.size:()I
      74: iload         5
      76: if_icmpgt     81
      79: aconst_null
      80: areturn
      81: iload         4
      83: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: areturn

  public static final int floodValley(java.util.Map<Point, java.lang.Character>, java.util.Map<Point, java.lang.Integer>, int);
    Code:
       0: aload_0
       1: ldc           #51                 // String <this>
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #216                // String lake
       9: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: astore_3
      14: iconst_0
      15: istore        4
      17: new           #57                 // class java/util/LinkedHashMap
      20: dup
      21: invokespecial #60                 // Method java/util/LinkedHashMap."<init>":()V
      24: astore        5
      26: aload_3
      27: invokeinterface #66,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      32: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      37: astore        6
      39: aload         6
      41: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          116
      49: aload         6
      51: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: checkcast     #84                 // class java/util/Map$Entry
      59: astore        7
      61: aload         7
      63: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      68: checkcast     #139                // class java/lang/Number
      71: invokevirtual #143                // Method java/lang/Number.intValue:()I
      74: istore        8
      76: iconst_0
      77: istore        9
      79: iload         8
      81: iload_2
      82: if_icmpne     89
      85: iconst_1
      86: goto          90
      89: iconst_0
      90: ifeq          39
      93: aload         5
      95: aload         7
      97: invokeinterface #96,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     102: aload         7
     104: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     109: invokevirtual #114                // Method java/util/LinkedHashMap.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     112: pop
     113: goto          39
     116: aload         5
     118: checkcast     #62                 // class java/util/Map
     121: astore_3
     122: nop
     123: iconst_0
     124: istore        4
     126: aload_3
     127: invokeinterface #66,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     132: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     137: astore        5
     139: aload         5
     141: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     146: ifeq          416
     149: aload         5
     151: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     156: checkcast     #84                 // class java/util/Map$Entry
     159: astore        6
     161: aload         6
     163: astore        7
     165: iconst_0
     166: istore        8
     168: aload         7
     170: invokeinterface #96,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     175: checkcast     #113                // class Point
     178: astore        9
     180: aload         9
     182: iconst_0
     183: iconst_1
     184: aconst_null
     185: invokestatic  #220                // Method Point.neighbours$default:(LPoint;ZILjava/lang/Object;)Ljava/util/List;
     188: checkcast     #105                // class java/lang/Iterable
     191: astore        10
     193: iconst_0
     194: istore        11
     196: aload         10
     198: astore        12
     200: new           #120                // class java/util/ArrayList
     203: dup
     204: invokespecial #121                // Method java/util/ArrayList."<init>":()V
     207: checkcast     #123                // class java/util/Collection
     210: astore        13
     212: iconst_0
     213: istore        14
     215: aload         12
     217: invokeinterface #134,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     222: astore        15
     224: aload         15
     226: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     231: ifeq          326
     234: aload         15
     236: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     241: astore        16
     243: aload         16
     245: checkcast     #113                // class Point
     248: astore        17
     250: iconst_0
     251: istore        18
     253: aload_0
     254: aload         17
     256: invokeinterface #224,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     261: ifnull        309
     264: aload_0
     265: aload         17
     267: invokeinterface #224,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     272: dup
     273: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     276: checkcast     #89                 // class java/lang/Character
     279: invokevirtual #93                 // Method java/lang/Character.charValue:()C
     282: aload_0
     283: aload         9
     285: invokeinterface #224,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     290: dup
     291: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     294: checkcast     #89                 // class java/lang/Character
     297: invokevirtual #93                 // Method java/lang/Character.charValue:()C
     300: isub
     301: iconst_1
     302: if_icmpgt     309
     305: iconst_1
     306: goto          310
     309: iconst_0
     310: ifeq          224
     313: aload         13
     315: aload         16
     317: invokeinterface #131,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     322: pop
     323: goto          224
     326: aload         13
     328: checkcast     #133                // class java/util/List
     331: nop
     332: checkcast     #105                // class java/lang/Iterable
     335: astore        10
     337: nop
     338: iconst_0
     339: istore        11
     341: aload         10
     343: invokeinterface #134,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     348: astore        12
     350: aload         12
     352: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     357: ifeq          410
     360: aload         12
     362: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     367: astore        13
     369: aload         13
     371: checkcast     #113                // class Point
     374: astore        14
     376: iconst_0
     377: istore        15
     379: aload_1
     380: aload         14
     382: invokeinterface #212,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     387: ifne          405
     390: aload_1
     391: aload         14
     393: iload_2
     394: iconst_1
     395: iadd
     396: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     399: invokeinterface #100,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     404: pop
     405: nop
     406: nop
     407: goto          350
     410: nop
     411: nop
     412: nop
     413: goto          139
     416: nop
     417: iload_2
     418: iconst_1
     419: iadd
     420: ireturn

  public static final java.util.Map<Point, java.lang.Character> parse(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #51                 // String <this>
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #57                 // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #60                 // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #62                 // class java/util/Map
      16: astore_1
      17: aload_0
      18: checkcast     #105                // class java/lang/Iterable
      21: astore_2
      22: iconst_0
      23: istore_3
      24: iconst_0
      25: istore        4
      27: aload_2
      28: invokeinterface #134,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        5
      35: aload         5
      37: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          177
      45: aload         5
      47: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        6
      54: iload         4
      56: iinc          4, 1
      59: istore        7
      61: iload         7
      63: ifge          69
      66: invokestatic  #241                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      69: iload         7
      71: aload         6
      73: checkcast     #243                // class java/lang/String
      76: astore        8
      78: istore        9
      80: iconst_0
      81: istore        10
      83: aload         8
      85: checkcast     #245                // class java/lang/CharSequence
      88: astore        11
      90: iconst_0
      91: istore        12
      93: iconst_0
      94: istore        13
      96: iconst_0
      97: istore        14
      99: iload         14
     101: aload         11
     103: invokeinterface #248,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     108: if_icmpge     171
     111: aload         11
     113: iload         14
     115: invokeinterface #252,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     120: istore        15
     122: iload         13
     124: iinc          13, 1
     127: iload         15
     129: istore        16
     131: istore        17
     133: iconst_0
     134: istore        18
     136: iload         16
     138: invokestatic  #118                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     141: astore        19
     143: aload_1
     144: new           #113                // class Point
     147: dup
     148: iload         17
     150: iload         9
     152: invokespecial #255                // Method Point."<init>":(II)V
     155: aload         19
     157: invokeinterface #100,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     162: pop
     163: nop
     164: nop
     165: iinc          14, 1
     168: goto          99
     171: nop
     172: nop
     173: nop
     174: goto          35
     177: nop
     178: aload_1
     179: areturn

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