package day08

import java.io.File

val fileList = File("puzzle_input/day08.txt").useLines { it.toList() }
val forest = fileList.map { row -> row.toList().map { col -> col.code } }
val width = forest[0].size
val height = forest.size

fun visible(row: Int, col: Int): Boolean {
  val tree = forest[row][col]

  if (
    row == 0 || row == height ||
    col == 0 || col == width
  ) return true

  var visible = true

// visible from above
  for (otherTree in forest.slice(0 until row))
    visible = visible && otherTree[col] < tree
  if (visible) return true

// visible from left
  visible = true
  for (otherTree in forest[row].slice(0 until col))
    visible = visible && otherTree < tree
  if (visible) return true

// visible from right
  visible = true
  for (otherTree in forest[row].slice(col + 1 until width))
    visible = visible && otherTree < tree
  if (visible) return true

// visible from below
  visible = true
  for (otherTree in forest.slice(row + 1 until height))
    visible = visible && otherTree[col] < tree
  return visible
}

fun scenicScore(row: Int, col: Int): Int {
  val tree = forest[row][col]
  var score = 1

  if (
    row == 0 ||
    row == height ||
    col == 0 ||
    col == width
  ) return 0

// up distance
  var distance = 0
  for (otherTree in forest.slice(row - 1 downTo 0)) {
    distance++
    if (otherTree[col] >= tree) break
  }
  score *= distance

// left distance
  distance = 0
  for (otherTree in forest[row].slice(col - 1 downTo 0)) {
    distance++
    if (otherTree >= tree) break
  }
  score *= distance

// right distance
  distance = 0
  for (otherTree in forest[row].slice(col + 1 until width)) {
    distance++
    if (otherTree >= tree) break
  }
  score *= distance

// down distance
  distance = 0
  for (otherTree in forest.slice(row + 1 until height)) {
    distance++
    if (otherTree[col] >= tree) break
  }
  score *= distance

  return score
}

fun a(): Int {
  var sum = 0

  for (row in 0 until height) for (col in 0 until width)
    if (visible(row, col)) sum++

  return sum
}

fun b(): Int {
  var max = 0

  for (row in 0 until height) for (col in 0 until width)
    if (scenicScore(row, col) > max)
      max = scenicScore(row, col)

  return max
}

Compiled from "DayEight.kt"
public final class day08.DayEightKt {
  private static final java.util.List<java.lang.String> fileList;

  private static final java.util.List<java.util.List<java.lang.Integer>> forest;

  private static final int width;

  private static final int height;

  public static final java.util.List<java.lang.String> getFileList();
    Code:
       0: getstatic     #12                 // Field fileList:Ljava/util/List;
       3: areturn

  public static final java.util.List<java.util.List<java.lang.Integer>> getForest();
    Code:
       0: getstatic     #17                 // Field forest:Ljava/util/List;
       3: areturn

  public static final int getWidth();
    Code:
       0: getstatic     #23                 // Field width:I
       3: ireturn

  public static final int getHeight();
    Code:
       0: getstatic     #27                 // Field height:I
       3: ireturn

  public static final boolean visible(int, int);
    Code:
       0: getstatic     #17                 // Field forest:Ljava/util/List;
       3: iload_0
       4: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       9: checkcast     #31                 // class java/util/List
      12: iload_1
      13: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      18: checkcast     #37                 // class java/lang/Number
      21: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      24: istore_2
      25: iload_0
      26: ifeq          47
      29: iload_0
      30: getstatic     #27                 // Field height:I
      33: if_icmpeq     47
      36: iload_1
      37: ifeq          47
      40: iload_1
      41: getstatic     #23                 // Field width:I
      44: if_icmpne     49
      47: iconst_1
      48: ireturn
      49: iconst_1
      50: istore_3
      51: getstatic     #17                 // Field forest:Ljava/util/List;
      54: iconst_0
      55: iload_0
      56: invokestatic  #46                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      59: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
      62: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      67: astore        4
      69: aload         4
      71: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          122
      79: aload         4
      81: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: checkcast     #31                 // class java/util/List
      89: astore        5
      91: iload_3
      92: ifeq          117
      95: aload         5
      97: iload_1
      98: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     103: checkcast     #37                 // class java/lang/Number
     106: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     109: iload_2
     110: if_icmpge     117
     113: iconst_1
     114: goto          118
     117: iconst_0
     118: istore_3
     119: goto          69
     122: iload_3
     123: ifeq          128
     126: iconst_1
     127: ireturn
     128: iconst_1
     129: istore_3
     130: getstatic     #17                 // Field forest:Ljava/util/List;
     133: iload_0
     134: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     139: checkcast     #31                 // class java/util/List
     142: iconst_0
     143: iload_1
     144: invokestatic  #46                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     147: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
     150: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     155: astore        4
     157: aload         4
     159: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     164: ifeq          201
     167: aload         4
     169: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     174: checkcast     #37                 // class java/lang/Number
     177: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     180: istore        5
     182: iload_3
     183: ifeq          196
     186: iload         5
     188: iload_2
     189: if_icmpge     196
     192: iconst_1
     193: goto          197
     196: iconst_0
     197: istore_3
     198: goto          157
     201: iload_3
     202: ifeq          207
     205: iconst_1
     206: ireturn
     207: iconst_1
     208: istore_3
     209: getstatic     #17                 // Field forest:Ljava/util/List;
     212: iload_0
     213: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     218: checkcast     #31                 // class java/util/List
     221: iload_1
     222: iconst_1
     223: iadd
     224: getstatic     #23                 // Field width:I
     227: invokestatic  #46                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     230: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
     233: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     238: astore        4
     240: aload         4
     242: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     247: ifeq          284
     250: aload         4
     252: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     257: checkcast     #37                 // class java/lang/Number
     260: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     263: istore        5
     265: iload_3
     266: ifeq          279
     269: iload         5
     271: iload_2
     272: if_icmpge     279
     275: iconst_1
     276: goto          280
     279: iconst_0
     280: istore_3
     281: goto          240
     284: iload_3
     285: ifeq          290
     288: iconst_1
     289: ireturn
     290: iconst_1
     291: istore_3
     292: getstatic     #17                 // Field forest:Ljava/util/List;
     295: iload_0
     296: iconst_1
     297: iadd
     298: getstatic     #27                 // Field height:I
     301: invokestatic  #46                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     304: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
     307: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     312: astore        4
     314: aload         4
     316: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     321: ifeq          367
     324: aload         4
     326: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     331: checkcast     #31                 // class java/util/List
     334: astore        5
     336: iload_3
     337: ifeq          362
     340: aload         5
     342: iload_1
     343: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     348: checkcast     #37                 // class java/lang/Number
     351: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     354: iload_2
     355: if_icmpge     362
     358: iconst_1
     359: goto          363
     362: iconst_0
     363: istore_3
     364: goto          314
     367: iload_3
     368: ireturn

  public static final int scenicScore(int, int);
    Code:
       0: getstatic     #17                 // Field forest:Ljava/util/List;
       3: iload_0
       4: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       9: checkcast     #31                 // class java/util/List
      12: iload_1
      13: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      18: checkcast     #37                 // class java/lang/Number
      21: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      24: istore_2
      25: iconst_1
      26: istore_3
      27: iload_0
      28: ifeq          49
      31: iload_0
      32: getstatic     #27                 // Field height:I
      35: if_icmpeq     49
      38: iload_1
      39: ifeq          49
      42: iload_1
      43: getstatic     #23                 // Field width:I
      46: if_icmpne     51
      49: iconst_0
      50: ireturn
      51: iconst_0
      52: istore        4
      54: getstatic     #17                 // Field forest:Ljava/util/List;
      57: iload_0
      58: iconst_1
      59: isub
      60: iconst_0
      61: invokestatic  #77                 // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      64: checkcast     #79                 // class java/lang/Iterable
      67: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Ljava/lang/Iterable;)Ljava/util/List;
      70: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      75: astore        5
      77: aload         5
      79: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      84: ifeq          123
      87: aload         5
      89: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      94: checkcast     #31                 // class java/util/List
      97: astore        6
      99: iinc          4, 1
     102: aload         6
     104: iload_1
     105: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     110: checkcast     #37                 // class java/lang/Number
     113: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     116: iload_2
     117: if_icmplt     77
     120: goto          123
     123: iload_3
     124: iload         4
     126: imul
     127: istore_3
     128: iconst_0
     129: istore        4
     131: getstatic     #17                 // Field forest:Ljava/util/List;
     134: iload_0
     135: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     140: checkcast     #31                 // class java/util/List
     143: iload_1
     144: iconst_1
     145: isub
     146: iconst_0
     147: invokestatic  #77                 // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
     150: checkcast     #79                 // class java/lang/Iterable
     153: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Ljava/lang/Iterable;)Ljava/util/List;
     156: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     161: astore        5
     163: aload         5
     165: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     170: ifeq          200
     173: aload         5
     175: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     180: checkcast     #37                 // class java/lang/Number
     183: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     186: istore        6
     188: iinc          4, 1
     191: iload         6
     193: iload_2
     194: if_icmplt     163
     197: goto          200
     200: iload_3
     201: iload         4
     203: imul
     204: istore_3
     205: iconst_0
     206: istore        4
     208: getstatic     #17                 // Field forest:Ljava/util/List;
     211: iload_0
     212: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     217: checkcast     #31                 // class java/util/List
     220: iload_1
     221: iconst_1
     222: iadd
     223: getstatic     #23                 // Field width:I
     226: invokestatic  #46                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     229: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
     232: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     237: astore        5
     239: aload         5
     241: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     246: ifeq          276
     249: aload         5
     251: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     256: checkcast     #37                 // class java/lang/Number
     259: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     262: istore        6
     264: iinc          4, 1
     267: iload         6
     269: iload_2
     270: if_icmplt     239
     273: goto          276
     276: iload_3
     277: iload         4
     279: imul
     280: istore_3
     281: iconst_0
     282: istore        4
     284: getstatic     #17                 // Field forest:Ljava/util/List;
     287: iload_0
     288: iconst_1
     289: iadd
     290: getstatic     #27                 // Field height:I
     293: invokestatic  #46                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     296: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
     299: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     304: astore        5
     306: aload         5
     308: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     313: ifeq          352
     316: aload         5
     318: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     323: checkcast     #31                 // class java/util/List
     326: astore        6
     328: iinc          4, 1
     331: aload         6
     333: iload_1
     334: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     339: checkcast     #37                 // class java/lang/Number
     342: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     345: iload_2
     346: if_icmplt     306
     349: goto          352
     352: iload_3
     353: iload         4
     355: imul
     356: istore_3
     357: iload_3
     358: ireturn

  public static final int a();
    Code:
       0: iconst_0
       1: istore_0
       2: iconst_0
       3: istore_1
       4: getstatic     #27                 // Field height:I
       7: istore_2
       8: iload_1
       9: iload_2
      10: if_icmpge     49
      13: iconst_0
      14: istore_3
      15: getstatic     #23                 // Field width:I
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     43
      26: iload_1
      27: iload_3
      28: invokestatic  #87                 // Method visible:(II)Z
      31: ifeq          37
      34: iinc          0, 1
      37: iinc          3, 1
      40: goto          20
      43: iinc          1, 1
      46: goto          8
      49: iload_0
      50: ireturn

  public static final int b();
    Code:
       0: iconst_0
       1: istore_0
       2: iconst_0
       3: istore_1
       4: getstatic     #27                 // Field height:I
       7: istore_2
       8: iload_1
       9: iload_2
      10: if_icmpge     53
      13: iconst_0
      14: istore_3
      15: getstatic     #23                 // Field width:I
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     47
      26: iload_1
      27: iload_3
      28: invokestatic  #91                 // Method scenicScore:(II)I
      31: iload_0
      32: if_icmple     41
      35: iload_1
      36: iload_3
      37: invokestatic  #91                 // Method scenicScore:(II)I
      40: istore_0
      41: iinc          3, 1
      44: goto          20
      47: iinc          1, 1
      50: goto          8
      53: iload_0
      54: ireturn

  static {};
    Code:
       0: new           #98                 // class java/io/File
       3: dup
       4: ldc           #100                // String puzzle_input/day08.txt
       6: invokespecial #104                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: getstatic     #110                // 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           #112                // class java/io/InputStreamReader
      29: dup
      30: new           #114                // class java/io/FileInputStream
      33: dup
      34: aload         5
      36: invokespecial #117                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      39: checkcast     #119                // class java/io/InputStream
      42: aload_1
      43: invokespecial #122                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      46: checkcast     #124                // class java/io/Reader
      49: astore        5
      51: aload         5
      53: instanceof    #126                // class java/io/BufferedReader
      56: ifeq          67
      59: aload         5
      61: checkcast     #126                // class java/io/BufferedReader
      64: goto          78
      67: new           #126                // class java/io/BufferedReader
      70: dup
      71: aload         5
      73: iload         4
      75: invokespecial #129                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      78: checkcast     #131                // class java/io/Closeable
      81: astore_3
      82: aconst_null
      83: astore        4
      85: nop
      86: aload_3
      87: checkcast     #126                // class java/io/BufferedReader
      90: astore        5
      92: iconst_0
      93: istore        6
      95: aload         5
      97: invokestatic  #137                // 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  #143                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     110: astore        5
     112: aload_3
     113: aload         4
     115: invokestatic  #149                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     118: aload         5
     120: goto          143
     123: astore        6
     125: aload         6
     127: astore        4
     129: aload         6
     131: athrow
     132: astore        6
     134: aload_3
     135: aload         4
     137: invokestatic  #149                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     140: aload         6
     142: athrow
     143: nop
     144: putstatic     #12                 // Field fileList:Ljava/util/List;
     147: getstatic     #12                 // Field fileList:Ljava/util/List;
     150: checkcast     #79                 // class java/lang/Iterable
     153: astore_0
     154: iconst_0
     155: istore_1
     156: aload_0
     157: astore_2
     158: new           #151                // class java/util/ArrayList
     161: dup
     162: aload_0
     163: bipush        10
     165: invokestatic  #155                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     168: invokespecial #158                // Method java/util/ArrayList."<init>":(I)V
     171: checkcast     #160                // class java/util/Collection
     174: astore_3
     175: iconst_0
     176: istore        4
     178: aload_2
     179: invokeinterface #161,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     184: astore        5
     186: aload         5
     188: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     193: ifeq          342
     196: aload         5
     198: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     203: astore        6
     205: aload_3
     206: aload         6
     208: checkcast     #163                // class java/lang/String
     211: astore        7
     213: astore        19
     215: iconst_0
     216: istore        8
     218: aload         7
     220: checkcast     #165                // class java/lang/CharSequence
     223: invokestatic  #170                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
     226: checkcast     #79                 // class java/lang/Iterable
     229: astore        9
     231: iconst_0
     232: istore        10
     234: aload         9
     236: astore        11
     238: new           #151                // class java/util/ArrayList
     241: dup
     242: aload         9
     244: bipush        10
     246: invokestatic  #155                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     249: invokespecial #158                // Method java/util/ArrayList."<init>":(I)V
     252: checkcast     #160                // class java/util/Collection
     255: astore        12
     257: iconst_0
     258: istore        13
     260: aload         11
     262: invokeinterface #161,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     267: astore        14
     269: aload         14
     271: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     276: ifeq          323
     279: aload         14
     281: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     286: astore        15
     288: aload         12
     290: aload         15
     292: checkcast     #172                // class java/lang/Character
     295: invokevirtual #176                // Method java/lang/Character.charValue:()C
     298: istore        16
     300: astore        17
     302: iconst_0
     303: istore        18
     305: iload         16
     307: nop
     308: invokestatic  #182                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     311: aload         17
     313: swap
     314: invokeinterface #186,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     319: pop
     320: goto          269
     323: aload         12
     325: checkcast     #31                 // class java/util/List
     328: nop
     329: nop
     330: aload         19
     332: swap
     333: invokeinterface #186,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     338: pop
     339: goto          186
     342: aload_3
     343: checkcast     #31                 // class java/util/List
     346: nop
     347: putstatic     #17                 // Field forest:Ljava/util/List;
     350: getstatic     #17                 // Field forest:Ljava/util/List;
     353: iconst_0
     354: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     359: checkcast     #31                 // class java/util/List
     362: invokeinterface #189,  1          // InterfaceMethod java/util/List.size:()I
     367: putstatic     #23                 // Field width:I
     370: getstatic     #17                 // Field forest:Ljava/util/List;
     373: invokeinterface #189,  1          // InterfaceMethod java/util/List.size:()I
     378: putstatic     #27                 // Field height:I
     381: return
    Exception table:
       from    to  target type
          85   112   123   Class java/lang/Throwable
          85   112   132   any
         123   132   132   any
         132   134   132   any
}


package day12

import java.io.File
import kotlin.math.min

val fileList = File("puzzle_input/day12.txt").readLines()

// the rows of 'S' and 'E' respectively
val startLine = fileList.indexOfFirst { line -> line.contains('S') }
val goalLine = fileList.indexOfFirst { line -> line.contains('E') }
// the coordinates of 'S' and 'E' respectively
val player = Pair(startLine, fileList[startLine].indexOf('S'))
val goal = Pair(goalLine, fileList[goalLine].indexOf('E'))
// the puzzle input with 'S' -> 'a' and 'E' -> 'z'
val heightMap = fileList.map { line -> line.replaceFirst('S', 'a').replaceFirst('E', 'z') }
// a map of the amount of steps required to reach a point
val stepMap = fileList.map { line -> line.map { 0 }.toMutableList() }
val stepBackMap = stepMap

fun step(row: Int, col: Int) {
  val height = heightMap[row][col]
  val steps = stepMap[row][col] + 1

// step up
  if (row != 0 && (stepMap[row - 1][col] > steps || stepMap[row - 1][col] == 0) && heightMap[row - 1][col] <= height + 1) {
    stepMap[row - 1][col] = steps
    step(row - 1, col)
  }
// step down
  if (row != heightMap.lastIndex && (stepMap[row + 1][col] > steps || stepMap[row + 1][col] == 0) && heightMap[row + 1][col] <= height + 1) {
    stepMap[row + 1][col] = steps
    step(row + 1, col)
  }
// step left
  if (col != 0 && (stepMap[row][col - 1] > steps || stepMap[row][col - 1] == 0) && heightMap[row][col - 1] <= height + 1) {
    stepMap[row][col - 1] = steps
    step(row, col - 1)
  }
// step right
  if (col != heightMap[0].lastIndex && (stepMap[row][col + 1] > steps || stepMap[row][col + 1] == 0) && heightMap[row][col + 1] <= height + 1) {
    stepMap[row][col + 1] = steps
    step(row, col + 1)
  }
}

fun stepBack(row: Int, col: Int) {
  val height = heightMap[row][col]
  val steps = stepMap[row][col] + 1

  // step up
  if (row != 0 && (stepBackMap[row - 1][col] > steps || stepMap[row - 1][col] == 0) && heightMap[row - 1][col] >= height - 1) {
    stepBackMap[row - 1][col] = steps
    stepBack(row - 1, col)
  }
// step down
  if (row != heightMap.lastIndex && (stepBackMap[row + 1][col] > steps || stepMap[row + 1][col] == 0) && heightMap[row + 1][col] >= height - 1) {
    stepBackMap[row + 1][col] = steps
    stepBack(row + 1, col)
  }
// step left
  if (col != 0 && (stepBackMap[row][col - 1] > steps || stepMap[row][col - 1] == 0) && heightMap[row][col - 1] >= height - 1) {
    stepBackMap[row][col - 1] = steps
    stepBack(row, col - 1)
  }
// step right
  if (col != heightMap[0].lastIndex && (stepBackMap[row][col + 1] > steps || stepMap[row][col + 1] == 0) && heightMap[row][col + 1] >= height - 1) {
    stepBackMap[row][col + 1] = steps
    stepBack(row, col + 1)
  }
}

fun a(): Int {
  step(player.first, player.second)

  return stepMap[goal.first][goal.second]
}

fun b(): Int {
  stepBack(goal.first, goal.second)

  var minSteps = Int.MAX_VALUE

  stepBackMap.forEachIndexed { row, line -> line.forEachIndexed { col, steps -> if (heightMap[row][col] == 'a' && steps != 0) minSteps = min(steps, minSteps) } }

  return minSteps
}

Compiled from "DayTwelve.kt"
public final class day12.DayTwelveKt {
  private static final java.util.List<java.lang.String> fileList;

  private static final int startLine;

  private static final int goalLine;

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> player;

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> goal;

  private static final java.util.List<java.lang.String> heightMap;

  private static final java.util.List<java.util.List<java.lang.Integer>> stepMap;

  private static final java.util.List<java.util.List<java.lang.Integer>> stepBackMap;

  public static final java.util.List<java.lang.String> getFileList();
    Code:
       0: getstatic     #12                 // Field fileList:Ljava/util/List;
       3: areturn

  public static final int getStartLine();
    Code:
       0: getstatic     #18                 // Field startLine:I
       3: ireturn

  public static final int getGoalLine();
    Code:
       0: getstatic     #22                 // Field goalLine:I
       3: ireturn

  public static final kotlin.Pair<java.lang.Integer, java.lang.Integer> getPlayer();
    Code:
       0: getstatic     #29                 // Field player:Lkotlin/Pair;
       3: areturn

  public static final kotlin.Pair<java.lang.Integer, java.lang.Integer> getGoal();
    Code:
       0: getstatic     #33                 // Field goal:Lkotlin/Pair;
       3: areturn

  public static final java.util.List<java.lang.String> getHeightMap();
    Code:
       0: getstatic     #37                 // Field heightMap:Ljava/util/List;
       3: areturn

  public static final java.util.List<java.util.List<java.lang.Integer>> getStepMap();
    Code:
       0: getstatic     #42                 // Field stepMap:Ljava/util/List;
       3: areturn

  public static final java.util.List<java.util.List<java.lang.Integer>> getStepBackMap();
    Code:
       0: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
       3: areturn

  public static final void step(int, int);
    Code:
       0: getstatic     #37                 // Field heightMap:Ljava/util/List;
       3: iload_0
       4: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       9: checkcast     #56                 // class java/lang/String
      12: iload_1
      13: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
      16: istore_2
      17: getstatic     #42                 // Field stepMap:Ljava/util/List;
      20: iload_0
      21: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      26: checkcast     #50                 // class java/util/List
      29: iload_1
      30: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: checkcast     #62                 // class java/lang/Number
      38: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      41: iconst_1
      42: iadd
      43: istore_3
      44: iload_0
      45: ifeq          167
      48: getstatic     #42                 // Field stepMap:Ljava/util/List;
      51: iload_0
      52: iconst_1
      53: isub
      54: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      59: checkcast     #50                 // class java/util/List
      62: iload_1
      63: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      68: checkcast     #62                 // class java/lang/Number
      71: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      74: iload_3
      75: if_icmpgt     107
      78: getstatic     #42                 // Field stepMap:Ljava/util/List;
      81: iload_0
      82: iconst_1
      83: isub
      84: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      89: checkcast     #50                 // class java/util/List
      92: iload_1
      93: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      98: checkcast     #62                 // class java/lang/Number
     101: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     104: ifne          167
     107: getstatic     #37                 // Field heightMap:Ljava/util/List;
     110: iload_0
     111: iconst_1
     112: isub
     113: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     118: checkcast     #56                 // class java/lang/String
     121: iload_1
     122: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
     125: iload_2
     126: iconst_1
     127: iadd
     128: i2c
     129: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     132: ifgt          167
     135: getstatic     #42                 // Field stepMap:Ljava/util/List;
     138: iload_0
     139: iconst_1
     140: isub
     141: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     146: checkcast     #50                 // class java/util/List
     149: iload_1
     150: iload_3
     151: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: invokeinterface #81,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     159: pop
     160: iload_0
     161: iconst_1
     162: isub
     163: iload_1
     164: invokestatic  #83                 // Method step:(II)V
     167: iload_0
     168: getstatic     #37                 // Field heightMap:Ljava/util/List;
     171: invokestatic  #89                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     174: if_icmpeq     296
     177: getstatic     #42                 // Field stepMap:Ljava/util/List;
     180: iload_0
     181: iconst_1
     182: iadd
     183: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     188: checkcast     #50                 // class java/util/List
     191: iload_1
     192: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     197: checkcast     #62                 // class java/lang/Number
     200: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     203: iload_3
     204: if_icmpgt     236
     207: getstatic     #42                 // Field stepMap:Ljava/util/List;
     210: iload_0
     211: iconst_1
     212: iadd
     213: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     218: checkcast     #50                 // class java/util/List
     221: iload_1
     222: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     227: checkcast     #62                 // class java/lang/Number
     230: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     233: ifne          296
     236: getstatic     #37                 // Field heightMap:Ljava/util/List;
     239: iload_0
     240: iconst_1
     241: iadd
     242: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     247: checkcast     #56                 // class java/lang/String
     250: iload_1
     251: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
     254: iload_2
     255: iconst_1
     256: iadd
     257: i2c
     258: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     261: ifgt          296
     264: getstatic     #42                 // Field stepMap:Ljava/util/List;
     267: iload_0
     268: iconst_1
     269: iadd
     270: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     275: checkcast     #50                 // class java/util/List
     278: iload_1
     279: iload_3
     280: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     283: invokeinterface #81,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     288: pop
     289: iload_0
     290: iconst_1
     291: iadd
     292: iload_1
     293: invokestatic  #83                 // Method step:(II)V
     296: iload_1
     297: ifeq          419
     300: getstatic     #42                 // Field stepMap:Ljava/util/List;
     303: iload_0
     304: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     309: checkcast     #50                 // class java/util/List
     312: iload_1
     313: iconst_1
     314: isub
     315: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     320: checkcast     #62                 // class java/lang/Number
     323: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     326: iload_3
     327: if_icmpgt     359
     330: getstatic     #42                 // Field stepMap:Ljava/util/List;
     333: iload_0
     334: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     339: checkcast     #50                 // class java/util/List
     342: iload_1
     343: iconst_1
     344: isub
     345: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     350: checkcast     #62                 // class java/lang/Number
     353: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     356: ifne          419
     359: getstatic     #37                 // Field heightMap:Ljava/util/List;
     362: iload_0
     363: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     368: checkcast     #56                 // class java/lang/String
     371: iload_1
     372: iconst_1
     373: isub
     374: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
     377: iload_2
     378: iconst_1
     379: iadd
     380: i2c
     381: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     384: ifgt          419
     387: getstatic     #42                 // Field stepMap:Ljava/util/List;
     390: iload_0
     391: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     396: checkcast     #50                 // class java/util/List
     399: iload_1
     400: iconst_1
     401: isub
     402: iload_3
     403: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     406: invokeinterface #81,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     411: pop
     412: iload_0
     413: iload_1
     414: iconst_1
     415: isub
     416: invokestatic  #83                 // Method step:(II)V
     419: iload_1
     420: getstatic     #37                 // Field heightMap:Ljava/util/List;
     423: iconst_0
     424: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     429: checkcast     #91                 // class java/lang/CharSequence
     432: invokestatic  #96                 // Method kotlin/text/StringsKt.getLastIndex:(Ljava/lang/CharSequence;)I
     435: if_icmpeq     557
     438: getstatic     #42                 // Field stepMap:Ljava/util/List;
     441: iload_0
     442: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     447: checkcast     #50                 // class java/util/List
     450: iload_1
     451: iconst_1
     452: iadd
     453: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     458: checkcast     #62                 // class java/lang/Number
     461: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     464: iload_3
     465: if_icmpgt     497
     468: getstatic     #42                 // Field stepMap:Ljava/util/List;
     471: iload_0
     472: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     477: checkcast     #50                 // class java/util/List
     480: iload_1
     481: iconst_1
     482: iadd
     483: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     488: checkcast     #62                 // class java/lang/Number
     491: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     494: ifne          557
     497: getstatic     #37                 // Field heightMap:Ljava/util/List;
     500: iload_0
     501: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     506: checkcast     #56                 // class java/lang/String
     509: iload_1
     510: iconst_1
     511: iadd
     512: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
     515: iload_2
     516: iconst_1
     517: iadd
     518: i2c
     519: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     522: ifgt          557
     525: getstatic     #42                 // Field stepMap:Ljava/util/List;
     528: iload_0
     529: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     534: checkcast     #50                 // class java/util/List
     537: iload_1
     538: iconst_1
     539: iadd
     540: iload_3
     541: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     544: invokeinterface #81,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     549: pop
     550: iload_0
     551: iload_1
     552: iconst_1
     553: iadd
     554: invokestatic  #83                 // Method step:(II)V
     557: return

  public static final void stepBack(int, int);
    Code:
       0: getstatic     #37                 // Field heightMap:Ljava/util/List;
       3: iload_0
       4: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       9: checkcast     #56                 // class java/lang/String
      12: iload_1
      13: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
      16: istore_2
      17: getstatic     #42                 // Field stepMap:Ljava/util/List;
      20: iload_0
      21: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      26: checkcast     #50                 // class java/util/List
      29: iload_1
      30: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: checkcast     #62                 // class java/lang/Number
      38: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      41: iconst_1
      42: iadd
      43: istore_3
      44: iload_0
      45: ifeq          167
      48: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
      51: iload_0
      52: iconst_1
      53: isub
      54: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      59: checkcast     #50                 // class java/util/List
      62: iload_1
      63: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      68: checkcast     #62                 // class java/lang/Number
      71: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      74: iload_3
      75: if_icmpgt     107
      78: getstatic     #42                 // Field stepMap:Ljava/util/List;
      81: iload_0
      82: iconst_1
      83: isub
      84: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      89: checkcast     #50                 // class java/util/List
      92: iload_1
      93: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      98: checkcast     #62                 // class java/lang/Number
     101: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     104: ifne          167
     107: getstatic     #37                 // Field heightMap:Ljava/util/List;
     110: iload_0
     111: iconst_1
     112: isub
     113: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     118: checkcast     #56                 // class java/lang/String
     121: iload_1
     122: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
     125: iload_2
     126: iconst_1
     127: isub
     128: i2c
     129: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     132: iflt          167
     135: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
     138: iload_0
     139: iconst_1
     140: isub
     141: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     146: checkcast     #50                 // class java/util/List
     149: iload_1
     150: iload_3
     151: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: invokeinterface #81,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     159: pop
     160: iload_0
     161: iconst_1
     162: isub
     163: iload_1
     164: invokestatic  #104                // Method stepBack:(II)V
     167: iload_0
     168: getstatic     #37                 // Field heightMap:Ljava/util/List;
     171: invokestatic  #89                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     174: if_icmpeq     296
     177: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
     180: iload_0
     181: iconst_1
     182: iadd
     183: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     188: checkcast     #50                 // class java/util/List
     191: iload_1
     192: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     197: checkcast     #62                 // class java/lang/Number
     200: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     203: iload_3
     204: if_icmpgt     236
     207: getstatic     #42                 // Field stepMap:Ljava/util/List;
     210: iload_0
     211: iconst_1
     212: iadd
     213: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     218: checkcast     #50                 // class java/util/List
     221: iload_1
     222: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     227: checkcast     #62                 // class java/lang/Number
     230: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     233: ifne          296
     236: getstatic     #37                 // Field heightMap:Ljava/util/List;
     239: iload_0
     240: iconst_1
     241: iadd
     242: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     247: checkcast     #56                 // class java/lang/String
     250: iload_1
     251: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
     254: iload_2
     255: iconst_1
     256: isub
     257: i2c
     258: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     261: iflt          296
     264: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
     267: iload_0
     268: iconst_1
     269: iadd
     270: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     275: checkcast     #50                 // class java/util/List
     278: iload_1
     279: iload_3
     280: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     283: invokeinterface #81,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     288: pop
     289: iload_0
     290: iconst_1
     291: iadd
     292: iload_1
     293: invokestatic  #104                // Method stepBack:(II)V
     296: iload_1
     297: ifeq          419
     300: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
     303: iload_0
     304: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     309: checkcast     #50                 // class java/util/List
     312: iload_1
     313: iconst_1
     314: isub
     315: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     320: checkcast     #62                 // class java/lang/Number
     323: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     326: iload_3
     327: if_icmpgt     359
     330: getstatic     #42                 // Field stepMap:Ljava/util/List;
     333: iload_0
     334: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     339: checkcast     #50                 // class java/util/List
     342: iload_1
     343: iconst_1
     344: isub
     345: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     350: checkcast     #62                 // class java/lang/Number
     353: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     356: ifne          419
     359: getstatic     #37                 // Field heightMap:Ljava/util/List;
     362: iload_0
     363: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     368: checkcast     #56                 // class java/lang/String
     371: iload_1
     372: iconst_1
     373: isub
     374: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
     377: iload_2
     378: iconst_1
     379: isub
     380: i2c
     381: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     384: iflt          419
     387: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
     390: iload_0
     391: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     396: checkcast     #50                 // class java/util/List
     399: iload_1
     400: iconst_1
     401: isub
     402: iload_3
     403: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     406: invokeinterface #81,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     411: pop
     412: iload_0
     413: iload_1
     414: iconst_1
     415: isub
     416: invokestatic  #104                // Method stepBack:(II)V
     419: iload_1
     420: getstatic     #37                 // Field heightMap:Ljava/util/List;
     423: iconst_0
     424: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     429: checkcast     #91                 // class java/lang/CharSequence
     432: invokestatic  #96                 // Method kotlin/text/StringsKt.getLastIndex:(Ljava/lang/CharSequence;)I
     435: if_icmpeq     557
     438: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
     441: iload_0
     442: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     447: checkcast     #50                 // class java/util/List
     450: iload_1
     451: iconst_1
     452: iadd
     453: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     458: checkcast     #62                 // class java/lang/Number
     461: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     464: iload_3
     465: if_icmpgt     497
     468: getstatic     #42                 // Field stepMap:Ljava/util/List;
     471: iload_0
     472: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     477: checkcast     #50                 // class java/util/List
     480: iload_1
     481: iconst_1
     482: iadd
     483: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     488: checkcast     #62                 // class java/lang/Number
     491: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     494: ifne          557
     497: getstatic     #37                 // Field heightMap:Ljava/util/List;
     500: iload_0
     501: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     506: checkcast     #56                 // class java/lang/String
     509: iload_1
     510: iconst_1
     511: iadd
     512: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
     515: iload_2
     516: iconst_1
     517: isub
     518: i2c
     519: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     522: iflt          557
     525: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
     528: iload_0
     529: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     534: checkcast     #50                 // class java/util/List
     537: iload_1
     538: iconst_1
     539: iadd
     540: iload_3
     541: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     544: invokeinterface #81,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     549: pop
     550: iload_0
     551: iload_1
     552: iconst_1
     553: iadd
     554: invokestatic  #104                // Method stepBack:(II)V
     557: return

  public static final int a();
    Code:
       0: getstatic     #29                 // Field player:Lkotlin/Pair;
       3: invokevirtual #111                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       6: checkcast     #62                 // class java/lang/Number
       9: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      12: getstatic     #29                 // Field player:Lkotlin/Pair;
      15: invokevirtual #114                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      18: checkcast     #62                 // class java/lang/Number
      21: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      24: invokestatic  #83                 // Method step:(II)V
      27: getstatic     #42                 // Field stepMap:Ljava/util/List;
      30: getstatic     #33                 // Field goal:Lkotlin/Pair;
      33: invokevirtual #111                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      36: checkcast     #62                 // class java/lang/Number
      39: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      42: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      47: checkcast     #50                 // class java/util/List
      50: getstatic     #33                 // Field goal:Lkotlin/Pair;
      53: invokevirtual #114                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      56: checkcast     #62                 // class java/lang/Number
      59: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      62: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #62                 // class java/lang/Number
      70: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      73: ireturn

  public static final int b();
    Code:
       0: getstatic     #33                 // Field goal:Lkotlin/Pair;
       3: invokevirtual #111                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       6: checkcast     #62                 // class java/lang/Number
       9: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      12: getstatic     #33                 // Field goal:Lkotlin/Pair;
      15: invokevirtual #114                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      18: checkcast     #62                 // class java/lang/Number
      21: invokevirtual #65                 // Method java/lang/Number.intValue:()I
      24: invokestatic  #104                // Method stepBack:(II)V
      27: iconst_0
      28: istore_0
      29: ldc           #116                // int 2147483647
      31: istore_0
      32: getstatic     #46                 // Field stepBackMap:Ljava/util/List;
      35: checkcast     #118                // class java/lang/Iterable
      38: astore_1
      39: iconst_0
      40: istore_2
      41: iconst_0
      42: istore_3
      43: aload_1
      44: invokeinterface #122,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      49: astore        4
      51: aload         4
      53: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifeq          216
      61: aload         4
      63: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      68: astore        5
      70: iload_3
      71: iinc          3, 1
      74: istore        6
      76: iload         6
      78: ifge          84
      81: invokestatic  #135                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      84: iload         6
      86: aload         5
      88: checkcast     #50                 // class java/util/List
      91: astore        7
      93: istore        8
      95: iconst_0
      96: istore        9
      98: aload         7
     100: checkcast     #118                // class java/lang/Iterable
     103: astore        10
     105: iconst_0
     106: istore        11
     108: iconst_0
     109: istore        12
     111: aload         10
     113: invokeinterface #122,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     118: astore        13
     120: aload         13
     122: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     127: ifeq          210
     130: aload         13
     132: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     137: astore        14
     139: iload         12
     141: iinc          12, 1
     144: istore        15
     146: iload         15
     148: ifge          154
     151: invokestatic  #135                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     154: iload         15
     156: aload         14
     158: checkcast     #62                 // class java/lang/Number
     161: invokevirtual #65                 // Method java/lang/Number.intValue:()I
     164: istore        16
     166: istore        17
     168: iconst_0
     169: istore        18
     171: getstatic     #37                 // Field heightMap:Ljava/util/List;
     174: iload         8
     176: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     181: checkcast     #56                 // class java/lang/String
     184: iload         17
     186: invokevirtual #60                 // Method java/lang/String.charAt:(I)C
     189: bipush        97
     191: if_icmpne     206
     194: iload         16
     196: ifeq          206
     199: iload         16
     201: iload_0
     202: invokestatic  #140                // Method java/lang/Math.min:(II)I
     205: istore_0
     206: nop
     207: goto          120
     210: nop
     211: nop
     212: nop
     213: goto          51
     216: nop
     217: iload_0
     218: ireturn

  static {};
    Code:
       0: new           #153                // class java/io/File
       3: dup
       4: ldc           #155                // String puzzle_input/day12.txt
       6: invokespecial #159                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #165                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: putstatic     #12                 // Field fileList:Ljava/util/List;
      18: getstatic     #12                 // Field fileList:Ljava/util/List;
      21: astore_0
      22: iconst_0
      23: istore_1
      24: iconst_0
      25: istore_2
      26: aload_0
      27: invokeinterface #166,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      32: astore_3
      33: aload_3
      34: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          86
      42: aload_3
      43: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      48: astore        4
      50: aload         4
      52: checkcast     #56                 // class java/lang/String
      55: astore        5
      57: iconst_0
      58: istore        6
      60: aload         5
      62: checkcast     #91                 // class java/lang/CharSequence
      65: bipush        83
      67: iconst_0
      68: iconst_2
      69: aconst_null
      70: invokestatic  #170                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
      73: ifeq          80
      76: iload_2
      77: goto          87
      80: iinc          2, 1
      83: goto          33
      86: iconst_m1
      87: putstatic     #18                 // Field startLine:I
      90: getstatic     #12                 // Field fileList:Ljava/util/List;
      93: astore_0
      94: iconst_0
      95: istore_1
      96: iconst_0
      97: istore_2
      98: aload_0
      99: invokeinterface #166,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     104: astore_3
     105: aload_3
     106: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     111: ifeq          158
     114: aload_3
     115: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     120: astore        4
     122: aload         4
     124: checkcast     #56                 // class java/lang/String
     127: astore        5
     129: iconst_0
     130: istore        6
     132: aload         5
     134: checkcast     #91                 // class java/lang/CharSequence
     137: bipush        69
     139: iconst_0
     140: iconst_2
     141: aconst_null
     142: invokestatic  #170                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     145: ifeq          152
     148: iload_2
     149: goto          159
     152: iinc          2, 1
     155: goto          105
     158: iconst_m1
     159: putstatic     #22                 // Field goalLine:I
     162: new           #107                // class kotlin/Pair
     165: dup
     166: getstatic     #18                 // Field startLine:I
     169: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     172: getstatic     #12                 // Field fileList:Ljava/util/List;
     175: getstatic     #18                 // Field startLine:I
     178: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     183: checkcast     #91                 // class java/lang/CharSequence
     186: bipush        83
     188: iconst_0
     189: iconst_0
     190: bipush        6
     192: aconst_null
     193: invokestatic  #174                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
     196: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     199: invokespecial #177                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     202: putstatic     #29                 // Field player:Lkotlin/Pair;
     205: new           #107                // class kotlin/Pair
     208: dup
     209: getstatic     #22                 // Field goalLine:I
     212: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     215: getstatic     #12                 // Field fileList:Ljava/util/List;
     218: getstatic     #22                 // Field goalLine:I
     221: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     226: checkcast     #91                 // class java/lang/CharSequence
     229: bipush        69
     231: iconst_0
     232: iconst_0
     233: bipush        6
     235: aconst_null
     236: invokestatic  #174                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
     239: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     242: invokespecial #177                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     245: putstatic     #33                 // Field goal:Lkotlin/Pair;
     248: getstatic     #12                 // Field fileList:Ljava/util/List;
     251: checkcast     #118                // class java/lang/Iterable
     254: astore_0
     255: iconst_0
     256: istore_1
     257: aload_0
     258: astore_2
     259: new           #179                // class java/util/ArrayList
     262: dup
     263: aload_0
     264: bipush        10
     266: invokestatic  #183                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     269: invokespecial #186                // Method java/util/ArrayList."<init>":(I)V
     272: checkcast     #188                // class java/util/Collection
     275: astore_3
     276: iconst_0
     277: istore        4
     279: aload_2
     280: invokeinterface #122,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     285: astore        5
     287: aload         5
     289: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     294: ifeq          353
     297: aload         5
     299: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     304: astore        6
     306: aload_3
     307: aload         6
     309: checkcast     #56                 // class java/lang/String
     312: astore        7
     314: astore        19
     316: iconst_0
     317: istore        8
     319: aload         7
     321: bipush        83
     323: bipush        97
     325: iconst_0
     326: iconst_4
     327: aconst_null
     328: invokestatic  #192                // Method kotlin/text/StringsKt.replaceFirst$default:(Ljava/lang/String;CCZILjava/lang/Object;)Ljava/lang/String;
     331: bipush        69
     333: bipush        122
     335: iconst_0
     336: iconst_4
     337: aconst_null
     338: invokestatic  #192                // Method kotlin/text/StringsKt.replaceFirst$default:(Ljava/lang/String;CCZILjava/lang/Object;)Ljava/lang/String;
     341: aload         19
     343: swap
     344: invokeinterface #196,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     349: pop
     350: goto          287
     353: aload_3
     354: checkcast     #50                 // class java/util/List
     357: nop
     358: putstatic     #37                 // Field heightMap:Ljava/util/List;
     361: getstatic     #12                 // Field fileList:Ljava/util/List;
     364: checkcast     #118                // class java/lang/Iterable
     367: astore_0
     368: iconst_0
     369: istore_1
     370: aload_0
     371: astore_2
     372: new           #179                // class java/util/ArrayList
     375: dup
     376: aload_0
     377: bipush        10
     379: invokestatic  #183                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     382: invokespecial #186                // Method java/util/ArrayList."<init>":(I)V
     385: checkcast     #188                // class java/util/Collection
     388: astore_3
     389: iconst_0
     390: istore        4
     392: aload_2
     393: invokeinterface #122,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     398: astore        5
     400: aload         5
     402: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     407: ifeq          548
     410: aload         5
     412: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     417: astore        6
     419: aload_3
     420: aload         6
     422: checkcast     #56                 // class java/lang/String
     425: astore        7
     427: astore        19
     429: iconst_0
     430: istore        8
     432: aload         7
     434: checkcast     #91                 // class java/lang/CharSequence
     437: astore        9
     439: iconst_0
     440: istore        10
     442: aload         9
     444: astore        11
     446: new           #179                // class java/util/ArrayList
     449: dup
     450: aload         9
     452: invokeinterface #199,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     457: invokespecial #186                // Method java/util/ArrayList."<init>":(I)V
     460: checkcast     #188                // class java/util/Collection
     463: astore        12
     465: iconst_0
     466: istore        13
     468: iconst_0
     469: istore        14
     471: iload         14
     473: aload         11
     475: invokeinterface #199,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     480: if_icmpge     524
     483: aload         11
     485: iload         14
     487: invokeinterface #200,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     492: istore        15
     494: aload         12
     496: iload         15
     498: istore        16
     500: astore        17
     502: iconst_0
     503: istore        18
     505: iconst_0
     506: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     509: aload         17
     511: swap
     512: invokeinterface #196,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     517: pop
     518: iinc          14, 1
     521: goto          471
     524: aload         12
     526: checkcast     #50                 // class java/util/List
     529: nop
     530: checkcast     #188                // class java/util/Collection
     533: invokestatic  #204                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     536: aload         19
     538: swap
     539: invokeinterface #196,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     544: pop
     545: goto          400
     548: aload_3
     549: checkcast     #50                 // class java/util/List
     552: nop
     553: putstatic     #42                 // Field stepMap:Ljava/util/List;
     556: getstatic     #42                 // Field stepMap:Ljava/util/List;
     559: putstatic     #46                 // Field stepBackMap:Ljava/util/List;
     562: return
}


package com.github.nicomincuzzi

import kotlin.math.abs

class Day2Dive {
    fun horizontalPositionAndDepth(commands: List<Pair<String, Int>>): Int {
        val result = hashMapOf<String, Int>()
        for (command in commands) {
            if (calculateHorizontalPosition(result, command)) continue
            if (calculateDepth(result, command)) continue
            when (command.first) {
                "forward" -> result[command.first] = command.second
                "down" -> result["depth"] = command.second * -1
                else -> result["depth"] = command.second
            }
        }
        return calculatePlannedCourse(result, "depth")
    }

    private fun calculateHorizontalPosition(result: HashMap<String, Int>, command: Pair<String, Int>): Boolean {
        if (result.containsKey(command.first) && command.first == "forward") {
            result[command.first] = result[command.first]?.plus(command.second)!!
            return true
        }
        return false
    }

    fun horizontalPositionAndDepthPartTwo(commands: List<Pair<String, Int>>): Int {
        val result = hashMapOf<String, Int>()
        for (command in commands) {
            if (calculateHorizontalPositionTwoPart(result, command)) continue
            if (calculateDepth(result, command)) continue
            when (command.first) {
                "forward" -> {
                    result[command.first] = command.second
                    calculateAim(result, command)
                }
                "down" -> result["depth"] = command.second * -1
                else -> result["depth"] = command.second
            }
        }
        return calculatePlannedCourse(result, "aim")
    }

    private fun calculateHorizontalPositionTwoPart(result: HashMap<String, Int>, command: Pair<String, Int>): Boolean {
        if (result.containsKey(command.first) && command.first == "forward") {
            result[command.first] = result[command.first]?.plus(command.second)!!
            calculateAim(result, command)
            return true
        }
        return false
    }

    private fun calculateAim(result: HashMap<String, Int>, command: Pair<String, Int>) {
        if (!result.containsKey("depth")) {
            return
        }
        if (result.containsKey("aim")) {
            result["aim"] = result["aim"]?.plus(result["depth"]!! * command.second)!!
            return
        }
        result["aim"] = result["depth"]!! * command.second
    }

    private fun calculateDepth(result: HashMap<String, Int>, command: Pair<String, Int>): Boolean {
        if (result.containsKey("depth")) {
            var updateValue = 1
            if (command.first == "down")
                updateValue = -1
            result["depth"] = result["depth"]?.plus(command.second * updateValue)!!
            return true
        }
        return false
    }

    private fun calculatePlannedCourse(result: HashMap<String, Int>, value: String) =
        result["forward"]!! * abs(result[value]!!)
}

Compiled from "Day2Dive.kt"
public final class com.github.nicomincuzzi.Day2Dive {
  public com.github.nicomincuzzi.Day2Dive();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int horizontalPositionAndDepth(java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>>);
    Code:
       0: aload_1
       1: ldc           #16                 // String commands
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #24                 // class java/util/HashMap
       9: dup
      10: invokespecial #25                 // Method java/util/HashMap."<init>":()V
      13: astore_2
      14: aload_1
      15: invokeinterface #31,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      20: astore_3
      21: aload_3
      22: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      27: ifeq          165
      30: aload_3
      31: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      36: checkcast     #43                 // class kotlin/Pair
      39: astore        4
      41: aload_0
      42: aload_2
      43: aload         4
      45: invokespecial #47                 // Method calculateHorizontalPosition:(Ljava/util/HashMap;Lkotlin/Pair;)Z
      48: ifne          21
      51: aload_0
      52: aload_2
      53: aload         4
      55: invokespecial #50                 // Method calculateDepth:(Ljava/util/HashMap;Lkotlin/Pair;)Z
      58: ifne          21
      61: aload         4
      63: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      66: checkcast     #55                 // class java/lang/String
      69: astore        5
      71: aload         5
      73: ldc           #57                 // String forward
      75: invokestatic  #61                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      78: ifeq          104
      81: aload_2
      82: checkcast     #63                 // class java/util/Map
      85: aload         4
      87: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      90: aload         4
      92: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      95: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     100: pop
     101: goto          21
     104: aload         5
     106: ldc           #72                 // String down
     108: invokestatic  #61                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     111: ifeq          145
     114: aload_2
     115: checkcast     #63                 // class java/util/Map
     118: ldc           #74                 // String depth
     120: aload         4
     122: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     125: checkcast     #76                 // class java/lang/Number
     128: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     131: iconst_m1
     132: imul
     133: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     136: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     141: pop
     142: goto          21
     145: aload_2
     146: checkcast     #63                 // class java/util/Map
     149: ldc           #74                 // String depth
     151: aload         4
     153: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     156: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     161: pop
     162: goto          21
     165: aload_0
     166: aload_2
     167: ldc           #74                 // String depth
     169: invokespecial #90                 // Method calculatePlannedCourse:(Ljava/util/HashMap;Ljava/lang/String;)I
     172: ireturn

  private final boolean calculateHorizontalPosition(java.util.HashMap<java.lang.String, java.lang.Integer>, kotlin.Pair<java.lang.String, java.lang.Integer>);
    Code:
       0: aload_1
       1: aload_2
       2: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: invokevirtual #100                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
       8: ifeq          90
      11: aload_2
      12: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      15: ldc           #57                 // String forward
      17: invokestatic  #61                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      20: ifeq          90
      23: aload_1
      24: checkcast     #63                 // class java/util/Map
      27: astore_3
      28: aload_2
      29: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      32: astore        4
      34: aload_1
      35: aload_2
      36: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      39: invokevirtual #104                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      42: checkcast     #82                 // class java/lang/Integer
      45: dup
      46: ifnull        69
      49: invokevirtual #105                // Method java/lang/Integer.intValue:()I
      52: aload_2
      53: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      56: checkcast     #76                 // class java/lang/Number
      59: invokevirtual #80                 // Method java/lang/Number.intValue:()I
      62: iadd
      63: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: goto          71
      69: pop
      70: aconst_null
      71: dup
      72: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      75: astore        5
      77: aload_3
      78: aload         4
      80: aload         5
      82: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      87: pop
      88: iconst_1
      89: ireturn
      90: iconst_0
      91: ireturn

  public final int horizontalPositionAndDepthPartTwo(java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>>);
    Code:
       0: aload_1
       1: ldc           #16                 // String commands
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #24                 // class java/util/HashMap
       9: dup
      10: invokespecial #25                 // Method java/util/HashMap."<init>":()V
      13: astore_2
      14: aload_1
      15: invokeinterface #31,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      20: astore_3
      21: aload_3
      22: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      27: ifeq          172
      30: aload_3
      31: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      36: checkcast     #43                 // class kotlin/Pair
      39: astore        4
      41: aload_0
      42: aload_2
      43: aload         4
      45: invokespecial #113                // Method calculateHorizontalPositionTwoPart:(Ljava/util/HashMap;Lkotlin/Pair;)Z
      48: ifne          21
      51: aload_0
      52: aload_2
      53: aload         4
      55: invokespecial #50                 // Method calculateDepth:(Ljava/util/HashMap;Lkotlin/Pair;)Z
      58: ifne          21
      61: aload         4
      63: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      66: checkcast     #55                 // class java/lang/String
      69: astore        5
      71: aload         5
      73: ldc           #57                 // String forward
      75: invokestatic  #61                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      78: ifeq          111
      81: aload_2
      82: checkcast     #63                 // class java/util/Map
      85: aload         4
      87: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      90: aload         4
      92: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      95: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     100: pop
     101: aload_0
     102: aload_2
     103: aload         4
     105: invokespecial #117                // Method calculateAim:(Ljava/util/HashMap;Lkotlin/Pair;)V
     108: goto          21
     111: aload         5
     113: ldc           #72                 // String down
     115: invokestatic  #61                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     118: ifeq          152
     121: aload_2
     122: checkcast     #63                 // class java/util/Map
     125: ldc           #74                 // String depth
     127: aload         4
     129: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     132: checkcast     #76                 // class java/lang/Number
     135: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     138: iconst_m1
     139: imul
     140: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     148: pop
     149: goto          21
     152: aload_2
     153: checkcast     #63                 // class java/util/Map
     156: ldc           #74                 // String depth
     158: aload         4
     160: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     163: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     168: pop
     169: goto          21
     172: aload_0
     173: aload_2
     174: ldc           #119                // String aim
     176: invokespecial #90                 // Method calculatePlannedCourse:(Ljava/util/HashMap;Ljava/lang/String;)I
     179: ireturn

  private final boolean calculateHorizontalPositionTwoPart(java.util.HashMap<java.lang.String, java.lang.Integer>, kotlin.Pair<java.lang.String, java.lang.Integer>);
    Code:
       0: aload_1
       1: aload_2
       2: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: invokevirtual #100                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
       8: ifeq          96
      11: aload_2
      12: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      15: ldc           #57                 // String forward
      17: invokestatic  #61                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      20: ifeq          96
      23: aload_1
      24: checkcast     #63                 // class java/util/Map
      27: astore_3
      28: aload_2
      29: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      32: astore        4
      34: aload_1
      35: aload_2
      36: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      39: invokevirtual #104                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      42: checkcast     #82                 // class java/lang/Integer
      45: dup
      46: ifnull        69
      49: invokevirtual #105                // Method java/lang/Integer.intValue:()I
      52: aload_2
      53: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      56: checkcast     #76                 // class java/lang/Number
      59: invokevirtual #80                 // Method java/lang/Number.intValue:()I
      62: iadd
      63: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: goto          71
      69: pop
      70: aconst_null
      71: dup
      72: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      75: astore        5
      77: aload_3
      78: aload         4
      80: aload         5
      82: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      87: pop
      88: aload_0
      89: aload_1
      90: aload_2
      91: invokespecial #117                // Method calculateAim:(Ljava/util/HashMap;Lkotlin/Pair;)V
      94: iconst_1
      95: ireturn
      96: iconst_0
      97: ireturn

  private final void calculateAim(java.util.HashMap<java.lang.String, java.lang.Integer>, kotlin.Pair<java.lang.String, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #74                 // String depth
       3: invokevirtual #100                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
       6: ifne          10
       9: return
      10: aload_1
      11: ldc           #119                // String aim
      13: invokevirtual #100                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
      16: ifeq          98
      19: aload_1
      20: checkcast     #63                 // class java/util/Map
      23: astore_3
      24: ldc           #119                // String aim
      26: astore        4
      28: aload_1
      29: ldc           #119                // String aim
      31: invokevirtual #104                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      34: checkcast     #82                 // class java/lang/Integer
      37: dup
      38: ifnull        78
      41: invokevirtual #105                // Method java/lang/Integer.intValue:()I
      44: aload_1
      45: ldc           #74                 // String depth
      47: invokevirtual #104                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      50: dup
      51: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      54: checkcast     #76                 // class java/lang/Number
      57: invokevirtual #80                 // Method java/lang/Number.intValue:()I
      60: aload_2
      61: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      64: checkcast     #76                 // class java/lang/Number
      67: invokevirtual #80                 // Method java/lang/Number.intValue:()I
      70: imul
      71: iadd
      72: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      75: goto          80
      78: pop
      79: aconst_null
      80: dup
      81: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      84: astore        5
      86: aload_3
      87: aload         4
      89: aload         5
      91: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      96: pop
      97: return
      98: aload_1
      99: checkcast     #63                 // class java/util/Map
     102: ldc           #119                // String aim
     104: aload_1
     105: ldc           #74                 // String depth
     107: invokevirtual #104                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     110: dup
     111: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     114: checkcast     #76                 // class java/lang/Number
     117: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     120: aload_2
     121: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     124: checkcast     #76                 // class java/lang/Number
     127: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     130: imul
     131: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     134: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     139: pop
     140: return

  private final boolean calculateDepth(java.util.HashMap<java.lang.String, java.lang.Integer>, kotlin.Pair<java.lang.String, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #74                 // String depth
       3: invokevirtual #100                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
       6: ifeq          92
       9: iconst_1
      10: istore_3
      11: aload_2
      12: invokevirtual #53                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      15: ldc           #72                 // String down
      17: invokestatic  #61                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      20: ifeq          25
      23: iconst_m1
      24: istore_3
      25: aload_1
      26: checkcast     #63                 // class java/util/Map
      29: astore        4
      31: ldc           #74                 // String depth
      33: astore        5
      35: aload_1
      36: ldc           #74                 // String depth
      38: invokevirtual #104                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      41: checkcast     #82                 // class java/lang/Integer
      44: dup
      45: ifnull        70
      48: invokevirtual #105                // Method java/lang/Integer.intValue:()I
      51: aload_2
      52: invokevirtual #66                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      55: checkcast     #76                 // class java/lang/Number
      58: invokevirtual #80                 // Method java/lang/Number.intValue:()I
      61: iload_3
      62: imul
      63: iadd
      64: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: goto          72
      70: pop
      71: aconst_null
      72: dup
      73: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      76: astore        6
      78: aload         4
      80: aload         5
      82: aload         6
      84: invokeinterface #70,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      89: pop
      90: iconst_1
      91: ireturn
      92: iconst_0
      93: ireturn

  private final int calculatePlannedCourse(java.util.HashMap<java.lang.String, java.lang.Integer>, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #57                 // String forward
       3: invokevirtual #104                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
       6: dup
       7: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      10: checkcast     #76                 // class java/lang/Number
      13: invokevirtual #80                 // Method java/lang/Number.intValue:()I
      16: aload_1
      17: aload_2
      18: invokevirtual #104                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      21: dup
      22: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      25: checkcast     #76                 // class java/lang/Number
      28: invokevirtual #80                 // Method java/lang/Number.intValue:()I
      31: invokestatic  #129                // Method java/lang/Math.abs:(I)I
      34: imul
      35: ireturn
}