private typealias MapOfHeights = List<List<Char>>

private fun Char.elevation() =
    when (this) {
        'S' -> 0 // a
        'E' -> 25 // z
        else ->
            ('a'..'z').indexOf(this)
    }

private fun MapOfHeights.getFirstPositionOf(mark: Char): Position {
    forEachIndexed { index, row ->
        if (row.contains(mark)) {
            return row.indexOf(mark) to index
        }
    }
    return -1 to -1
}

private fun MapOfHeights.getAllPositionsWithElevation(elevation: Int): List<Position> {
    val positions = mutableListOf<Position>()
    forEachIndexed { colIndex, items ->
        items.forEachIndexed { rowIndex, item ->
            if (item.elevation() == elevation) {
                positions.add(rowIndex to colIndex)
            }
        }
    }
    return positions
}

private fun MapOfHeights.getPossibleMoves(position: Position): List<Position> {
    val currentHeight = this[position.y][position.x].elevation()
    val directions = listOf(-1 to 0, 0 to -1, 1 to 0, 0 to 1)
    return directions
        .map { direction -> position + direction }
        .filter { it.x in first().indices && it.y in indices }
        .filter { this[it.y][it.x].elevation() - currentHeight <= 1 }
}

private fun MapOfHeights.findShortestPathLength(
    start: Position,
    destination: Position
): Int {
    val queue = mutableListOf(start)
    val visited = mutableSetOf(start)
    val predecessors = mutableMapOf<Position, Position>()

    while (queue.isNotEmpty()) {
        val currentItem = queue.popHead()
        val availableMoves = getPossibleMoves(currentItem)
        availableMoves.forEach { next ->
            if (!visited.contains(next)) {
                visited.add(next)
                predecessors[next] = currentItem
                queue.add(next)

                if (next == destination) {
                    queue.clear()
                    return@forEach
                }
            }
        }
    }
    var lenth = 0
    var crawl: Position? = destination
    while (predecessors[crawl] != null) {
        crawl = predecessors[crawl]
        lenth++
    }

    return lenth
}

fun main() {
    fun part1(mapOfHeights: MapOfHeights): Int {
        val (start, destination) = mapOfHeights.getFirstPositionOf('S') to mapOfHeights.getFirstPositionOf('E')
        return mapOfHeights.findShortestPathLength(start, destination)
    }

    fun part2(mapOfHeights: MapOfHeights): Int {
        val allStartingPoints = mapOfHeights.getAllPositionsWithElevation(0)
        val destination = mapOfHeights.getFirstPositionOf('E')
        val allPaths = allStartingPoints.map { startingPoint ->
            mapOfHeights.findShortestPathLength(
                startingPoint, destination
            )
        }
        return allPaths.filter { it != 0 }.min()
    }

    val testInput = readInput("Day12_test").map { it.toList() }
    check(part1(testInput) == 31)
    check(part2(testInput) == 29)

    val input = readInput("Day12").map { it.toList() }
    println(part1(input))
    println(part2(input))
}

Compiled from "Day12.kt"
public final class Day12Kt {
  private static final int elevation(char);
    Code:
       0: iload_0
       1: lookupswitch  { // 2
                    69: 32
                    83: 28
               default: 37
          }
      28: iconst_0
      29: goto          58
      32: bipush        25
      34: goto          58
      37: new           #8                  // class kotlin/ranges/CharRange
      40: dup
      41: bipush        97
      43: bipush        122
      45: invokespecial #12                 // Method kotlin/ranges/CharRange."<init>":(CC)V
      48: checkcast     #14                 // class java/lang/Iterable
      51: iload_0
      52: invokestatic  #20                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      55: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.indexOf:(Ljava/lang/Iterable;Ljava/lang/Object;)I
      58: ireturn

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> getFirstPositionOf(java.util.List<? extends java.util.List<java.lang.Character>>, char);
    Code:
       0: aload_0
       1: checkcast     #14                 // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: iconst_0
       8: istore        4
      10: aload_2
      11: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      16: astore        5
      18: aload         5
      20: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      25: ifeq          108
      28: aload         5
      30: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      35: astore        6
      37: iload         4
      39: iinc          4, 1
      42: istore        7
      44: iload         7
      46: ifge          52
      49: invokestatic  #49                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      52: iload         7
      54: aload         6
      56: checkcast     #51                 // class java/util/List
      59: astore        8
      61: istore        9
      63: iconst_0
      64: istore        10
      66: aload         8
      68: iload_1
      69: invokestatic  #20                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      72: invokeinterface #55,  2           // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
      77: ifeq          103
      80: aload         8
      82: iload_1
      83: invokestatic  #20                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      86: invokeinterface #58,  2           // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
      91: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: iload         9
      96: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: invokestatic  #69                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     102: areturn
     103: nop
     104: nop
     105: goto          18
     108: nop
     109: iconst_m1
     110: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     113: iconst_m1
     114: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     117: invokestatic  #69                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     120: areturn

  private static final java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>> getAllPositionsWithElevation(java.util.List<? extends java.util.List<java.lang.Character>>, int);
    Code:
       0: new           #87                 // class java/util/ArrayList
       3: dup
       4: invokespecial #89                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #51                 // class java/util/List
      10: astore_2
      11: aload_0
      12: checkcast     #14                 // class java/lang/Iterable
      15: astore_3
      16: iconst_0
      17: istore        4
      19: iconst_0
      20: istore        5
      22: aload_3
      23: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      28: astore        6
      30: aload         6
      32: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      37: ifeq          191
      40: aload         6
      42: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      47: astore        7
      49: iload         5
      51: iinc          5, 1
      54: istore        8
      56: iload         8
      58: ifge          64
      61: invokestatic  #49                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      64: iload         8
      66: aload         7
      68: checkcast     #51                 // class java/util/List
      71: astore        9
      73: istore        10
      75: iconst_0
      76: istore        11
      78: aload         9
      80: checkcast     #14                 // class java/lang/Iterable
      83: astore        12
      85: iconst_0
      86: istore        13
      88: iconst_0
      89: istore        14
      91: aload         12
      93: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      98: astore        15
     100: aload         15
     102: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     107: ifeq          185
     110: aload         15
     112: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     117: astore        16
     119: iload         14
     121: iinc          14, 1
     124: istore        17
     126: iload         17
     128: ifge          134
     131: invokestatic  #49                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     134: iload         17
     136: aload         16
     138: checkcast     #16                 // class java/lang/Character
     141: invokevirtual #93                 // Method java/lang/Character.charValue:()C
     144: istore        18
     146: istore        19
     148: iconst_0
     149: istore        20
     151: iload         18
     153: invokestatic  #95                 // Method elevation:(C)I
     156: iload_1
     157: if_icmpne     180
     160: aload_2
     161: iload         19
     163: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     166: iload         10
     168: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     171: invokestatic  #69                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     174: invokeinterface #98,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     179: pop
     180: nop
     181: nop
     182: goto          100
     185: nop
     186: nop
     187: nop
     188: goto          30
     191: nop
     192: aload_2
     193: areturn

  private static final java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>> getPossibleMoves(java.util.List<? extends java.util.List<java.lang.Character>>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #115                // Method UtilsKt.getY:(Lkotlin/Pair;)I
       5: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      10: checkcast     #51                 // class java/util/List
      13: aload_1
      14: invokestatic  #122                // Method UtilsKt.getX:(Lkotlin/Pair;)I
      17: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      22: checkcast     #16                 // class java/lang/Character
      25: invokevirtual #93                 // Method java/lang/Character.charValue:()C
      28: invokestatic  #95                 // Method elevation:(C)I
      31: istore_2
      32: iconst_4
      33: anewarray     #124                // class kotlin/Pair
      36: astore        4
      38: aload         4
      40: iconst_0
      41: iconst_m1
      42: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      45: iconst_0
      46: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: invokestatic  #69                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      52: aastore
      53: aload         4
      55: iconst_1
      56: iconst_0
      57: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      60: iconst_m1
      61: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      64: invokestatic  #69                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      67: aastore
      68: aload         4
      70: iconst_2
      71: iconst_1
      72: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      75: iconst_0
      76: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      79: invokestatic  #69                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      82: aastore
      83: aload         4
      85: iconst_3
      86: iconst_0
      87: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      90: iconst_1
      91: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: invokestatic  #69                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      97: aastore
      98: aload         4
     100: invokestatic  #128                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     103: astore_3
     104: aload_3
     105: checkcast     #14                 // class java/lang/Iterable
     108: astore        4
     110: nop
     111: iconst_0
     112: istore        5
     114: aload         4
     116: astore        6
     118: new           #87                 // class java/util/ArrayList
     121: dup
     122: aload         4
     124: bipush        10
     126: invokestatic  #132                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     129: invokespecial #135                // Method java/util/ArrayList."<init>":(I)V
     132: checkcast     #137                // class java/util/Collection
     135: astore        7
     137: iconst_0
     138: istore        8
     140: aload         6
     142: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     147: astore        9
     149: aload         9
     151: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     156: ifeq          200
     159: aload         9
     161: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     166: astore        10
     168: aload         7
     170: aload         10
     172: checkcast     #124                // class kotlin/Pair
     175: astore        11
     177: astore        15
     179: iconst_0
     180: istore        12
     182: aload_1
     183: aload         11
     185: invokestatic  #141                // Method UtilsKt.plus:(Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
     188: aload         15
     190: swap
     191: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     196: pop
     197: goto          149
     200: aload         7
     202: checkcast     #51                 // class java/util/List
     205: nop
     206: checkcast     #14                 // class java/lang/Iterable
     209: astore        4
     211: nop
     212: iconst_0
     213: istore        5
     215: aload         4
     217: astore        6
     219: new           #87                 // class java/util/ArrayList
     222: dup
     223: invokespecial #89                 // Method java/util/ArrayList."<init>":()V
     226: checkcast     #137                // class java/util/Collection
     229: astore        7
     231: iconst_0
     232: istore        8
     234: aload         6
     236: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     241: astore        9
     243: aload         9
     245: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     250: ifeq          382
     253: aload         9
     255: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     260: astore        10
     262: aload         10
     264: checkcast     #124                // class kotlin/Pair
     267: astore        11
     269: iconst_0
     270: istore        12
     272: aload_0
     273: invokestatic  #146                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     276: checkcast     #137                // class java/util/Collection
     279: invokeinterface #150,  1          // InterfaceMethod java/util/Collection.size:()I
     284: istore        13
     286: aload         11
     288: invokestatic  #122                // Method UtilsKt.getX:(Lkotlin/Pair;)I
     291: istore        14
     293: iconst_0
     294: iload         14
     296: if_icmpgt     314
     299: iload         14
     301: iload         13
     303: if_icmpge     310
     306: iconst_1
     307: goto          315
     310: iconst_0
     311: goto          315
     314: iconst_0
     315: ifeq          365
     318: aload_0
     319: checkcast     #137                // class java/util/Collection
     322: invokeinterface #150,  1          // InterfaceMethod java/util/Collection.size:()I
     327: istore        13
     329: aload         11
     331: invokestatic  #115                // Method UtilsKt.getY:(Lkotlin/Pair;)I
     334: istore        14
     336: iconst_0
     337: iload         14
     339: if_icmpgt     357
     342: iload         14
     344: iload         13
     346: if_icmpge     353
     349: iconst_1
     350: goto          358
     353: iconst_0
     354: goto          358
     357: iconst_0
     358: ifeq          365
     361: iconst_1
     362: goto          366
     365: iconst_0
     366: ifeq          243
     369: aload         7
     371: aload         10
     373: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     378: pop
     379: goto          243
     382: aload         7
     384: checkcast     #51                 // class java/util/List
     387: nop
     388: checkcast     #14                 // class java/lang/Iterable
     391: astore        4
     393: nop
     394: iconst_0
     395: istore        5
     397: aload         4
     399: astore        6
     401: new           #87                 // class java/util/ArrayList
     404: dup
     405: invokespecial #89                 // Method java/util/ArrayList."<init>":()V
     408: checkcast     #137                // class java/util/Collection
     411: astore        7
     413: iconst_0
     414: istore        8
     416: aload         6
     418: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     423: astore        9
     425: aload         9
     427: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     432: ifeq          514
     435: aload         9
     437: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     442: astore        10
     444: aload         10
     446: checkcast     #124                // class kotlin/Pair
     449: astore        11
     451: iconst_0
     452: istore        12
     454: aload_0
     455: aload         11
     457: invokestatic  #115                // Method UtilsKt.getY:(Lkotlin/Pair;)I
     460: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     465: checkcast     #51                 // class java/util/List
     468: aload         11
     470: invokestatic  #122                // Method UtilsKt.getX:(Lkotlin/Pair;)I
     473: invokeinterface #119,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     478: checkcast     #16                 // class java/lang/Character
     481: invokevirtual #93                 // Method java/lang/Character.charValue:()C
     484: invokestatic  #95                 // Method elevation:(C)I
     487: iload_2
     488: isub
     489: iconst_1
     490: if_icmpgt     497
     493: iconst_1
     494: goto          498
     497: iconst_0
     498: ifeq          425
     501: aload         7
     503: aload         10
     505: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     510: pop
     511: goto          425
     514: aload         7
     516: checkcast     #51                 // class java/util/List
     519: nop
     520: areturn

  private static final int findShortestPathLength(java.util.List<? extends java.util.List<java.lang.Character>>, kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: iconst_1
       1: anewarray     #124                // class kotlin/Pair
       4: astore        4
       6: aload         4
       8: iconst_0
       9: aload_1
      10: aastore
      11: aload         4
      13: invokestatic  #178                // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      16: astore_3
      17: iconst_1
      18: anewarray     #124                // class kotlin/Pair
      21: astore        5
      23: aload         5
      25: iconst_0
      26: aload_1
      27: aastore
      28: aload         5
      30: invokestatic  #184                // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
      33: astore        4
      35: new           #186                // class java/util/LinkedHashMap
      38: dup
      39: invokespecial #187                // Method java/util/LinkedHashMap."<init>":()V
      42: checkcast     #189                // class java/util/Map
      45: astore        5
      47: aload_3
      48: checkcast     #137                // class java/util/Collection
      51: invokeinterface #192,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      56: ifne          63
      59: iconst_1
      60: goto          64
      63: iconst_0
      64: ifeq          202
      67: aload_3
      68: invokestatic  #195                // Method UtilsKt.popHead:(Ljava/util/List;)Ljava/lang/Object;
      71: checkcast     #124                // class kotlin/Pair
      74: astore        6
      76: aload_0
      77: aload         6
      79: invokestatic  #197                // Method getPossibleMoves:(Ljava/util/List;Lkotlin/Pair;)Ljava/util/List;
      82: astore        7
      84: aload         7
      86: checkcast     #14                 // class java/lang/Iterable
      89: astore        8
      91: iconst_0
      92: istore        9
      94: aload         8
      96: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     101: astore        10
     103: aload         10
     105: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     110: ifeq          198
     113: aload         10
     115: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     120: astore        11
     122: aload         11
     124: checkcast     #124                // class kotlin/Pair
     127: astore        12
     129: iconst_0
     130: istore        13
     132: aload         4
     134: aload         12
     136: invokeinterface #200,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     141: ifne          193
     144: aload         4
     146: aload         12
     148: invokeinterface #201,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     153: pop
     154: aload         5
     156: aload         12
     158: aload         6
     160: invokeinterface #205,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     165: pop
     166: aload_3
     167: aload         12
     169: invokeinterface #98,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     174: pop
     175: aload         12
     177: aload_2
     178: invokestatic  #211                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     181: ifeq          193
     184: aload_3
     185: invokeinterface #214,  1          // InterfaceMethod java/util/List.clear:()V
     190: goto          194
     193: nop
     194: nop
     195: goto          103
     198: nop
     199: goto          47
     202: iconst_0
     203: istore        6
     205: aload_2
     206: astore        7
     208: aload         5
     210: aload         7
     212: invokeinterface #217,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     217: ifnull        240
     220: aload         5
     222: aload         7
     224: invokeinterface #217,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     229: checkcast     #124                // class kotlin/Pair
     232: astore        7
     234: iinc          6, 1
     237: goto          208
     240: iload         6
     242: ireturn

  public static final void main();
    Code:
       0: ldc           #236                // String Day12_test
       2: invokestatic  #240                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: checkcast     #14                 // class java/lang/Iterable
       8: astore_1
       9: iconst_0
      10: istore_2
      11: aload_1
      12: astore_3
      13: new           #87                 // class java/util/ArrayList
      16: dup
      17: aload_1
      18: bipush        10
      20: invokestatic  #132                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      23: invokespecial #135                // Method java/util/ArrayList."<init>":(I)V
      26: checkcast     #137                // class java/util/Collection
      29: astore        4
      31: iconst_0
      32: istore        5
      34: aload_3
      35: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        6
      42: aload         6
      44: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          95
      52: aload         6
      54: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        7
      61: aload         4
      63: aload         7
      65: checkcast     #242                // class java/lang/String
      68: astore        8
      70: astore        11
      72: iconst_0
      73: istore        9
      75: aload         8
      77: checkcast     #244                // class java/lang/CharSequence
      80: invokestatic  #250                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
      83: aload         11
      85: swap
      86: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: goto          42
      95: aload         4
      97: checkcast     #51                 // class java/util/List
     100: nop
     101: astore_0
     102: aload_0
     103: invokestatic  #254                // Method main$part1:(Ljava/util/List;)I
     106: bipush        31
     108: if_icmpne     115
     111: iconst_1
     112: goto          116
     115: iconst_0
     116: ifne          130
     119: new           #256                // class java/lang/IllegalStateException
     122: dup
     123: ldc_w         #258                // String Check failed.
     126: invokespecial #261                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     129: athrow
     130: aload_0
     131: invokestatic  #264                // Method main$part2:(Ljava/util/List;)I
     134: bipush        29
     136: if_icmpne     143
     139: iconst_1
     140: goto          144
     143: iconst_0
     144: ifne          158
     147: new           #256                // class java/lang/IllegalStateException
     150: dup
     151: ldc_w         #258                // String Check failed.
     154: invokespecial #261                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     157: athrow
     158: ldc_w         #266                // String Day12
     161: invokestatic  #240                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
     164: checkcast     #14                 // class java/lang/Iterable
     167: astore_2
     168: iconst_0
     169: istore_3
     170: aload_2
     171: astore        4
     173: new           #87                 // class java/util/ArrayList
     176: dup
     177: aload_2
     178: bipush        10
     180: invokestatic  #132                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     183: invokespecial #135                // Method java/util/ArrayList."<init>":(I)V
     186: checkcast     #137                // class java/util/Collection
     189: astore        5
     191: iconst_0
     192: istore        6
     194: aload         4
     196: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     201: astore        7
     203: aload         7
     205: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     210: ifeq          256
     213: aload         7
     215: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     220: astore        8
     222: aload         5
     224: aload         8
     226: checkcast     #242                // class java/lang/String
     229: astore        9
     231: astore        11
     233: iconst_0
     234: istore        10
     236: aload         9
     238: checkcast     #244                // class java/lang/CharSequence
     241: invokestatic  #250                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
     244: aload         11
     246: swap
     247: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     252: pop
     253: goto          203
     256: aload         5
     258: checkcast     #51                 // class java/util/List
     261: nop
     262: astore_1
     263: aload_1
     264: invokestatic  #254                // Method main$part1:(Ljava/util/List;)I
     267: istore_2
     268: getstatic     #272                // Field java/lang/System.out:Ljava/io/PrintStream;
     271: iload_2
     272: invokevirtual #277                // Method java/io/PrintStream.println:(I)V
     275: aload_1
     276: invokestatic  #264                // Method main$part2:(Ljava/util/List;)I
     279: istore_2
     280: getstatic     #272                // Field java/lang/System.out:Ljava/io/PrintStream;
     283: iload_2
     284: invokevirtual #277                // Method java/io/PrintStream.println:(I)V
     287: return

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

  private static final int main$part1(java.util.List<? extends java.util.List<java.lang.Character>>);
    Code:
       0: aload_0
       1: bipush        83
       3: invokestatic  #290                // Method getFirstPositionOf:(Ljava/util/List;C)Lkotlin/Pair;
       6: aload_0
       7: bipush        69
       9: invokestatic  #290                // Method getFirstPositionOf:(Ljava/util/List;C)Lkotlin/Pair;
      12: invokestatic  #69                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      15: astore_1
      16: aload_1
      17: invokevirtual #293                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      20: checkcast     #124                // class kotlin/Pair
      23: astore_2
      24: aload_1
      25: invokevirtual #296                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      28: checkcast     #124                // class kotlin/Pair
      31: astore_3
      32: aload_0
      33: aload_2
      34: aload_3
      35: invokestatic  #298                // Method findShortestPathLength:(Ljava/util/List;Lkotlin/Pair;Lkotlin/Pair;)I
      38: ireturn

  private static final int main$part2(java.util.List<? extends java.util.List<java.lang.Character>>);
    Code:
       0: aload_0
       1: iconst_0
       2: invokestatic  #301                // Method getAllPositionsWithElevation:(Ljava/util/List;I)Ljava/util/List;
       5: astore_1
       6: aload_0
       7: bipush        69
       9: invokestatic  #290                // Method getFirstPositionOf:(Ljava/util/List;C)Lkotlin/Pair;
      12: astore_2
      13: aload_1
      14: checkcast     #14                 // class java/lang/Iterable
      17: astore        4
      19: iconst_0
      20: istore        5
      22: aload         4
      24: astore        6
      26: new           #87                 // class java/util/ArrayList
      29: dup
      30: aload         4
      32: bipush        10
      34: invokestatic  #132                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      37: invokespecial #135                // Method java/util/ArrayList."<init>":(I)V
      40: checkcast     #137                // class java/util/Collection
      43: astore        7
      45: iconst_0
      46: istore        8
      48: aload         6
      50: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      55: astore        9
      57: aload         9
      59: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      64: ifeq          113
      67: aload         9
      69: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      74: astore        10
      76: aload         7
      78: aload         10
      80: checkcast     #124                // class kotlin/Pair
      83: astore        11
      85: astore        13
      87: iconst_0
      88: istore        12
      90: aload_0
      91: aload         11
      93: aload_2
      94: invokestatic  #298                // Method findShortestPathLength:(Ljava/util/List;Lkotlin/Pair;Lkotlin/Pair;)I
      97: nop
      98: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     101: aload         13
     103: swap
     104: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     109: pop
     110: goto          57
     113: aload         7
     115: checkcast     #51                 // class java/util/List
     118: nop
     119: astore_3
     120: aload_3
     121: checkcast     #14                 // class java/lang/Iterable
     124: astore        4
     126: iconst_0
     127: istore        5
     129: aload         4
     131: astore        6
     133: new           #87                 // class java/util/ArrayList
     136: dup
     137: invokespecial #89                 // Method java/util/ArrayList."<init>":()V
     140: checkcast     #137                // class java/util/Collection
     143: astore        7
     145: iconst_0
     146: istore        8
     148: aload         6
     150: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     155: astore        9
     157: aload         9
     159: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     164: ifeq          215
     167: aload         9
     169: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     174: astore        10
     176: aload         10
     178: checkcast     #303                // class java/lang/Number
     181: invokevirtual #306                // Method java/lang/Number.intValue:()I
     184: istore        11
     186: iconst_0
     187: istore        12
     189: iload         11
     191: ifeq          198
     194: iconst_1
     195: goto          199
     198: iconst_0
     199: ifeq          157
     202: aload         7
     204: aload         10
     206: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     211: pop
     212: goto          157
     215: aload         7
     217: checkcast     #51                 // class java/util/List
     220: nop
     221: checkcast     #14                 // class java/lang/Iterable
     224: invokestatic  #310                // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     227: checkcast     #303                // class java/lang/Number
     230: invokevirtual #306                // Method java/lang/Number.intValue:()I
     233: ireturn
}


import kotlin.math.abs

fun main() {
    fun getValuesInEachCycle(input: List<String>): List<Int> {
        val valuesInCycles = mutableListOf(1)
        var valueAfterLastCycle = valuesInCycles.first()
        input.forEach { instruction ->
            when {
                instruction.startsWith("noop") -> {
                    valuesInCycles.add(valueAfterLastCycle)
                }

                instruction.startsWith("addx") -> {
                    val (_, value) = instruction.splitWords()
                    repeat(2) { valuesInCycles.add((valueAfterLastCycle)) }
                    valueAfterLastCycle += value.toInt()
                }
            }
        }
        return valuesInCycles
    }

    fun part1(input: List<String>): Int {
        val indexes = listOf(20, 60, 100, 140, 180, 220)
        val cycles = getValuesInEachCycle(input)
        return indexes.sumOf { if (it < cycles.size) cycles[it] * it else 0 }
    }

    fun part2(input: List<String>) {
        getValuesInEachCycle(input)
            .dropHead()
            .chunked(40)
            .map { row ->
                row.forEachIndexed { index, x ->
                    print(
                        when {
                            abs(x - index) <= 1 -> "#"
                            else -> "."
                        }
                    )
                }
                println()
            }
    }

    val testInput = readInput("Day10_test")
    check(part1(testInput) == 13_140)
    part2(testInput)

    val input = readInput("Day10")
    println(part1(input))
    part2(input)
}

Compiled from "Day10.kt"
public final class Day10Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day10_test
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method main$part1:(Ljava/util/List;)I
      10: sipush        13140
      13: if_icmpne     20
      16: iconst_1
      17: goto          21
      20: iconst_0
      21: ifne          34
      24: new           #20                 // class java/lang/IllegalStateException
      27: dup
      28: ldc           #22                 // String Check failed.
      30: invokespecial #26                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      33: athrow
      34: aload_0
      35: invokestatic  #30                 // Method main$part2:(Ljava/util/List;)V
      38: ldc           #32                 // String Day10
      40: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      43: astore_1
      44: aload_1
      45: invokestatic  #18                 // Method main$part1:(Ljava/util/List;)I
      48: istore_2
      49: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      52: iload_2
      53: invokevirtual #44                 // Method java/io/PrintStream.println:(I)V
      56: aload_1
      57: invokestatic  #30                 // Method main$part2:(Ljava/util/List;)V
      60: return

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

  private static final java.util.List<java.lang.Integer> main$getValuesInEachCycle(java.util.List<java.lang.String>);
    Code:
       0: iconst_1
       1: anewarray     #59                 // class java/lang/Integer
       4: astore_2
       5: aload_2
       6: iconst_0
       7: iconst_1
       8: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      11: aastore
      12: aload_2
      13: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      16: astore_1
      17: iconst_0
      18: istore_2
      19: aload_1
      20: invokestatic  #73                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      23: checkcast     #75                 // class java/lang/Number
      26: invokevirtual #79                 // Method java/lang/Number.intValue:()I
      29: istore_2
      30: aload_0
      31: checkcast     #81                 // class java/lang/Iterable
      34: astore_3
      35: iconst_0
      36: istore        4
      38: aload_3
      39: invokeinterface #85,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        5
      46: aload         5
      48: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          182
      56: aload         5
      58: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        6
      65: aload         6
      67: checkcast     #97                 // class java/lang/String
      70: astore        7
      72: iconst_0
      73: istore        8
      75: nop
      76: aload         7
      78: ldc           #99                 // String noop
      80: iconst_0
      81: iconst_2
      82: aconst_null
      83: invokestatic  #105                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      86: ifeq          103
      89: aload_1
      90: iload_2
      91: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: invokeinterface #109,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      99: pop
     100: goto          177
     103: aload         7
     105: ldc           #111                // String addx
     107: iconst_0
     108: iconst_2
     109: aconst_null
     110: invokestatic  #105                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     113: ifeq          177
     116: aload         7
     118: invokestatic  #114                // Method UtilsKt.splitWords:(Ljava/lang/String;)Ljava/util/List;
     121: iconst_1
     122: invokeinterface #118,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     127: checkcast     #97                 // class java/lang/String
     130: astore        9
     132: iconst_2
     133: istore        10
     135: iconst_0
     136: istore        11
     138: iload         11
     140: iload         10
     142: if_icmpge     169
     145: iload         11
     147: istore        12
     149: iconst_0
     150: istore        13
     152: aload_1
     153: iload_2
     154: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     157: invokeinterface #109,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     162: pop
     163: iinc          11, 1
     166: goto          138
     169: iload_2
     170: aload         9
     172: invokestatic  #122                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     175: iadd
     176: istore_2
     177: nop
     178: nop
     179: goto          46
     182: nop
     183: aload_1
     184: areturn

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: bipush        6
       2: anewarray     #59                 // class java/lang/Integer
       5: astore_2
       6: aload_2
       7: iconst_0
       8: bipush        20
      10: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: aastore
      14: aload_2
      15: iconst_1
      16: bipush        60
      18: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      21: aastore
      22: aload_2
      23: iconst_2
      24: bipush        100
      26: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: aastore
      30: aload_2
      31: iconst_3
      32: sipush        140
      35: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      38: aastore
      39: aload_2
      40: iconst_4
      41: sipush        180
      44: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: aastore
      48: aload_2
      49: iconst_5
      50: sipush        220
      53: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      56: aastore
      57: aload_2
      58: invokestatic  #140                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      61: astore_1
      62: aload_0
      63: invokestatic  #142                // Method main$getValuesInEachCycle:(Ljava/util/List;)Ljava/util/List;
      66: astore_2
      67: aload_1
      68: checkcast     #81                 // class java/lang/Iterable
      71: astore_3
      72: iconst_0
      73: istore        4
      75: aload_3
      76: invokeinterface #85,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      81: astore        5
      83: aload         5
      85: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      90: ifeq          163
      93: aload         5
      95: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     100: astore        6
     102: iload         4
     104: aload         6
     106: checkcast     #75                 // class java/lang/Number
     109: invokevirtual #79                 // Method java/lang/Number.intValue:()I
     112: istore        7
     114: istore        9
     116: iconst_0
     117: istore        8
     119: iload         7
     121: aload_2
     122: invokeinterface #145,  1          // InterfaceMethod java/util/List.size:()I
     127: if_icmpge     150
     130: aload_2
     131: iload         7
     133: invokeinterface #118,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     138: checkcast     #75                 // class java/lang/Number
     141: invokevirtual #79                 // Method java/lang/Number.intValue:()I
     144: iload         7
     146: imul
     147: goto          151
     150: iconst_0
     151: istore        10
     153: iload         9
     155: iload         10
     157: iadd
     158: istore        4
     160: goto          83
     163: iload         4
     165: ireturn

  private static final void main$part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #142                // Method main$getValuesInEachCycle:(Ljava/util/List;)Ljava/util/List;
       4: invokestatic  #152                // Method UtilsKt.dropHead:(Ljava/util/List;)Ljava/util/List;
       7: checkcast     #81                 // class java/lang/Iterable
      10: bipush        40
      12: invokestatic  #156                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
      15: checkcast     #81                 // class java/lang/Iterable
      18: astore_1
      19: nop
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #158                // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #162                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #164                // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #166                // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #85,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          216
      63: aload         6
      65: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        7
      72: aload         4
      74: aload         7
      76: checkcast     #49                 // class java/util/List
      79: astore        8
      81: astore        20
      83: iconst_0
      84: istore        9
      86: aload         8
      88: checkcast     #81                 // class java/lang/Iterable
      91: astore        10
      93: iconst_0
      94: istore        11
      96: iconst_0
      97: istore        12
      99: aload         10
     101: invokeinterface #85,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     106: astore        13
     108: aload         13
     110: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     115: ifeq          194
     118: aload         13
     120: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     125: astore        14
     127: iload         12
     129: iinc          12, 1
     132: istore        15
     134: iload         15
     136: ifge          142
     139: invokestatic  #169                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     142: iload         15
     144: aload         14
     146: checkcast     #75                 // class java/lang/Number
     149: invokevirtual #79                 // Method java/lang/Number.intValue:()I
     152: istore        16
     154: istore        17
     156: iconst_0
     157: istore        18
     159: nop
     160: iload         16
     162: iload         17
     164: isub
     165: invokestatic  #175                // Method java/lang/Math.abs:(I)I
     168: iconst_1
     169: if_icmpgt     177
     172: ldc           #177                // String #
     174: goto          179
     177: ldc           #179                // String .
     179: astore        19
     181: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
     184: aload         19
     186: invokevirtual #183                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     189: nop
     190: nop
     191: goto          108
     194: nop
     195: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
     198: invokevirtual #185                // Method java/io/PrintStream.println:()V
     201: nop
     202: aload         20
     204: getstatic     #191                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     207: invokeinterface #192,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     212: pop
     213: goto          53
     216: aload         4
     218: checkcast     #49                 // class java/util/List
     221: nop
     222: pop
     223: return
}


import java.lang.IllegalArgumentException
import kotlin.math.abs

typealias Point = Pair<Int, Int>

private fun Point.isTouching(point: Point) = abs(first - point.first) < 2 && abs(second - point.second) < 2
fun main() {
    fun parseInput(name: String) = readInput(name).map { it.splitWords() }
        .map { (direction, steps) -> direction to steps.toInt() }

    fun getAllKnotsPositions(moves: List<Pair<String, Int>>, numOfKnots: Int): List<List<Point>> {

        fun getNextHeadPosition(position: Point, direction: String) = when (direction) {
            "L" -> Pair(position.first - 1, position.second)
            "R" -> Pair(position.first + 1, position.second)
            "U" -> Pair(position.first, position.second + 1)
            "D" -> Pair(position.first, position.second - 1)
            else -> throw IllegalArgumentException("Wrong direction $direction")
        }

        fun followingPosition(currentPosition: Point, leaderPosition: Point) = Point(
            currentPosition.first + leaderPosition.first.compareTo(currentPosition.first),
            currentPosition.second + leaderPosition.second.compareTo(currentPosition.second)
        )

        val startingPoint = 0 to 0
        val knotsPositions = List(numOfKnots) { mutableListOf(startingPoint) }
        moves.forEach { (direction, steps) ->
            repeat(steps) {
                val headPositions = knotsPositions.head()
                headPositions.add(getNextHeadPosition(headPositions.last(), direction))
                knotsPositions.forEachIndexed { index, currentKnotPositions ->
                    if (index == 0) return@forEachIndexed
                    val previousKnotPosition = knotsPositions[index - 1].last()
                    val currentKnotPosition = currentKnotPositions.last()

                    if (!previousKnotPosition.isTouching(currentKnotPosition)) {
                        currentKnotPositions.add(followingPosition(currentKnotPosition, previousKnotPosition))
                    } else {
                        currentKnotPositions.add(currentKnotPosition)
                    }
                }
            }
        }
        return knotsPositions
    }

    fun part1(input: List<Pair<String, Int>>): Int {
        return getAllKnotsPositions(input, 2).last().distinct().size
    }

    fun part2(input: List<Pair<String, Int>>): Int {
        return getAllKnotsPositions(input, 10).last().distinct().size
    }

    val testInput = parseInput("Day09_test")
    val testInputPart2 = parseInput("Day09_test2")
    check(part1(testInput) == 13)
    check(part2(testInput) == 1)
    check(part2(testInputPart2) == 36)

    val input = parseInput("Day09")
    println(part1(input))
    println(part2(input))
}

Compiled from "Day09.kt"
public final class Day09Kt {
  private static final boolean isTouching(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       4: checkcast     #15                 // class java/lang/Number
       7: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      10: aload_1
      11: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      14: checkcast     #15                 // class java/lang/Number
      17: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      20: isub
      21: invokestatic  #25                 // Method java/lang/Math.abs:(I)I
      24: iconst_2
      25: if_icmpge     60
      28: aload_0
      29: invokevirtual #28                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      32: checkcast     #15                 // class java/lang/Number
      35: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      38: aload_1
      39: invokevirtual #28                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      42: checkcast     #15                 // class java/lang/Number
      45: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      48: isub
      49: invokestatic  #25                 // Method java/lang/Math.abs:(I)I
      52: iconst_2
      53: if_icmpge     60
      56: iconst_1
      57: goto          61
      60: iconst_0
      61: ireturn

  public static final void main();
    Code:
       0: ldc           #35                 // String Day09_test
       2: invokestatic  #39                 // Method main$parseInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: ldc           #41                 // String Day09_test2
       8: invokestatic  #39                 // Method main$parseInput:(Ljava/lang/String;)Ljava/util/List;
      11: astore_1
      12: aload_0
      13: invokestatic  #45                 // Method main$part1:(Ljava/util/List;)I
      16: bipush        13
      18: if_icmpne     25
      21: iconst_1
      22: goto          26
      25: iconst_0
      26: ifne          39
      29: new           #47                 // class java/lang/IllegalStateException
      32: dup
      33: ldc           #49                 // String Check failed.
      35: invokespecial #53                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      38: athrow
      39: aload_0
      40: invokestatic  #56                 // Method main$part2:(Ljava/util/List;)I
      43: iconst_1
      44: if_icmpne     51
      47: iconst_1
      48: goto          52
      51: iconst_0
      52: ifne          65
      55: new           #47                 // class java/lang/IllegalStateException
      58: dup
      59: ldc           #49                 // String Check failed.
      61: invokespecial #53                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      64: athrow
      65: aload_1
      66: invokestatic  #56                 // Method main$part2:(Ljava/util/List;)I
      69: bipush        36
      71: if_icmpne     78
      74: iconst_1
      75: goto          79
      78: iconst_0
      79: ifne          92
      82: new           #47                 // class java/lang/IllegalStateException
      85: dup
      86: ldc           #49                 // String Check failed.
      88: invokespecial #53                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      91: athrow
      92: ldc           #58                 // String Day09
      94: invokestatic  #39                 // Method main$parseInput:(Ljava/lang/String;)Ljava/util/List;
      97: astore_2
      98: aload_2
      99: invokestatic  #45                 // Method main$part1:(Ljava/util/List;)I
     102: istore_3
     103: getstatic     #64                 // Field java/lang/System.out:Ljava/io/PrintStream;
     106: iload_3
     107: invokevirtual #70                 // Method java/io/PrintStream.println:(I)V
     110: aload_2
     111: invokestatic  #56                 // Method main$part2:(Ljava/util/List;)I
     114: istore_3
     115: getstatic     #64                 // Field java/lang/System.out:Ljava/io/PrintStream;
     118: iload_3
     119: invokevirtual #70                 // Method java/io/PrintStream.println:(I)V
     122: return

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

  private static final java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>> main$parseInput(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #87                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       4: checkcast     #89                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #91                 // class java/util/ArrayList
      15: dup
      16: aload_1
      17: bipush        10
      19: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      22: invokespecial #99                 // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #101                // class java/util/Collection
      28: astore        4
      30: iconst_0
      31: istore        5
      33: aload_3
      34: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        6
      41: aload         6
      43: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          91
      51: aload         6
      53: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        7
      60: aload         4
      62: aload         7
      64: checkcast     #116                // class java/lang/String
      67: astore        8
      69: astore        12
      71: iconst_0
      72: istore        9
      74: aload         8
      76: invokestatic  #119                // Method UtilsKt.splitWords:(Ljava/lang/String;)Ljava/util/List;
      79: aload         12
      81: swap
      82: invokeinterface #123,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      87: pop
      88: goto          41
      91: aload         4
      93: checkcast     #76                 // class java/util/List
      96: nop
      97: checkcast     #89                 // class java/lang/Iterable
     100: astore_1
     101: nop
     102: iconst_0
     103: istore_2
     104: aload_1
     105: astore_3
     106: new           #91                 // class java/util/ArrayList
     109: dup
     110: aload_1
     111: bipush        10
     113: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     116: invokespecial #99                 // Method java/util/ArrayList."<init>":(I)V
     119: checkcast     #101                // class java/util/Collection
     122: astore        4
     124: iconst_0
     125: istore        5
     127: aload_3
     128: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     133: astore        6
     135: aload         6
     137: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     142: ifeq          219
     145: aload         6
     147: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     152: astore        7
     154: aload         4
     156: aload         7
     158: checkcast     #76                 // class java/util/List
     161: astore        8
     163: astore        12
     165: iconst_0
     166: istore        9
     168: aload         8
     170: iconst_0
     171: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     176: checkcast     #116                // class java/lang/String
     179: astore        10
     181: aload         8
     183: iconst_1
     184: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     189: checkcast     #116                // class java/lang/String
     192: astore        11
     194: aload         10
     196: aload         11
     198: invokestatic  #133                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     201: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     204: invokestatic  #143                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     207: aload         12
     209: swap
     210: invokeinterface #123,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     215: pop
     216: goto          135
     219: aload         4
     221: checkcast     #76                 // class java/util/List
     224: nop
     225: areturn

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> main$getAllKnotsPositions$getNextHeadPosition(kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.lang.String);
    Code:
       0: aload_1
       1: astore_2
       2: aload_2
       3: invokevirtual #166                // Method java/lang/String.hashCode:()I
       6: lookupswitch  { // 4
                    68: 60
                    76: 84
                    82: 48
                    85: 72
               default: 209
          }
      48: aload_2
      49: ldc           #168                // String R
      51: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      54: ifne          122
      57: goto          209
      60: aload_2
      61: ldc           #173                // String D
      63: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      66: ifne          180
      69: goto          209
      72: aload_2
      73: ldc           #175                // String U
      75: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      78: ifne          151
      81: goto          209
      84: aload_2
      85: ldc           #177                // String L
      87: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      90: ifeq          209
      93: new           #9                  // class kotlin/Pair
      96: dup
      97: aload_0
      98: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     101: checkcast     #15                 // class java/lang/Number
     104: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     107: iconst_1
     108: isub
     109: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: aload_0
     113: invokevirtual #28                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     116: invokespecial #180                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     119: goto          236
     122: new           #9                  // class kotlin/Pair
     125: dup
     126: aload_0
     127: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     130: checkcast     #15                 // class java/lang/Number
     133: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     136: iconst_1
     137: iadd
     138: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     141: aload_0
     142: invokevirtual #28                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     145: invokespecial #180                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     148: goto          236
     151: new           #9                  // class kotlin/Pair
     154: dup
     155: aload_0
     156: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     159: aload_0
     160: invokevirtual #28                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     163: checkcast     #15                 // class java/lang/Number
     166: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     169: iconst_1
     170: iadd
     171: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     174: invokespecial #180                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     177: goto          236
     180: new           #9                  // class kotlin/Pair
     183: dup
     184: aload_0
     185: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     188: aload_0
     189: invokevirtual #28                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     192: checkcast     #15                 // class java/lang/Number
     195: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     198: iconst_1
     199: isub
     200: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     203: invokespecial #180                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     206: goto          236
     209: new           #182                // class java/lang/IllegalArgumentException
     212: dup
     213: new           #184                // class java/lang/StringBuilder
     216: dup
     217: invokespecial #186                // Method java/lang/StringBuilder."<init>":()V
     220: ldc           #188                // String Wrong direction
     222: invokevirtual #192                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     225: aload_1
     226: invokevirtual #192                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     229: invokevirtual #196                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     232: invokespecial #197                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     235: athrow
     236: areturn

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> main$getAllKnotsPositions$followingPosition(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: new           #9                  // class kotlin/Pair
       3: dup
       4: aload_0
       5: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       8: checkcast     #15                 // class java/lang/Number
      11: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      14: aload_1
      15: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      18: checkcast     #15                 // class java/lang/Number
      21: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      24: aload_0
      25: invokevirtual #13                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      28: checkcast     #15                 // class java/lang/Number
      31: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      34: invokestatic  #207                // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      37: iadd
      38: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: aload_0
      42: invokevirtual #28                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      45: checkcast     #15                 // class java/lang/Number
      48: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      51: aload_1
      52: invokevirtual #28                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      55: checkcast     #15                 // class java/lang/Number
      58: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      61: aload_0
      62: invokevirtual #28                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      65: checkcast     #15                 // class java/lang/Number
      68: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      71: invokestatic  #207                // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      74: iadd
      75: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: invokespecial #180                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      81: areturn

  private static final java.util.List<java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>> main$getAllKnotsPositions(java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>>, int);
    Code:
       0: iconst_0
       1: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       4: iconst_0
       5: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       8: invokestatic  #143                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      11: astore_2
      12: new           #91                 // class java/util/ArrayList
      15: dup
      16: iload_1
      17: invokespecial #99                 // Method java/util/ArrayList."<init>":(I)V
      20: astore        4
      22: iconst_0
      23: istore        5
      25: iload         5
      27: iload_1
      28: if_icmpge     75
      31: iload         5
      33: istore        6
      35: aload         4
      37: iload         6
      39: istore        7
      41: astore        27
      43: iconst_0
      44: istore        8
      46: iconst_1
      47: anewarray     #9                  // class kotlin/Pair
      50: astore        9
      52: aload         9
      54: iconst_0
      55: aload_2
      56: aastore
      57: aload         9
      59: invokestatic  #216                // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      62: aload         27
      64: swap
      65: invokevirtual #217                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      68: pop
      69: iinc          5, 1
      72: goto          25
      75: aload         4
      77: checkcast     #76                 // class java/util/List
      80: astore_3
      81: aload_0
      82: checkcast     #89                 // class java/lang/Iterable
      85: astore        4
      87: iconst_0
      88: istore        5
      90: aload         4
      92: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      97: astore        6
      99: aload         6
     101: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     106: ifeq          358
     109: aload         6
     111: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     116: astore        7
     118: aload         7
     120: checkcast     #9                  // class kotlin/Pair
     123: astore        8
     125: iconst_0
     126: istore        9
     128: aload         8
     130: invokevirtual #220                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     133: checkcast     #116                // class java/lang/String
     136: astore        10
     138: aload         8
     140: invokevirtual #223                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     143: checkcast     #15                 // class java/lang/Number
     146: invokevirtual #19                 // Method java/lang/Number.intValue:()I
     149: istore        11
     151: iconst_0
     152: istore        12
     154: iload         12
     156: iload         11
     158: if_icmpge     353
     161: iload         12
     163: istore        13
     165: iconst_0
     166: istore        14
     168: aload_3
     169: invokestatic  #227                // Method UtilsKt.head:(Ljava/util/List;)Ljava/lang/Object;
     172: checkcast     #76                 // class java/util/List
     175: astore        15
     177: aload         15
     179: aload         15
     181: invokestatic  #230                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     184: checkcast     #9                  // class kotlin/Pair
     187: aload         10
     189: invokestatic  #232                // Method main$getAllKnotsPositions$getNextHeadPosition:(Lkotlin/Pair;Ljava/lang/String;)Lkotlin/Pair;
     192: invokeinterface #233,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     197: pop
     198: aload_3
     199: checkcast     #89                 // class java/lang/Iterable
     202: astore        16
     204: iconst_0
     205: istore        17
     207: iconst_0
     208: istore        18
     210: aload         16
     212: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     217: astore        19
     219: aload         19
     221: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     226: ifeq          345
     229: aload         19
     231: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     236: astore        20
     238: iload         18
     240: iinc          18, 1
     243: istore        21
     245: iload         21
     247: ifge          253
     250: invokestatic  #236                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     253: iload         21
     255: aload         20
     257: checkcast     #76                 // class java/util/List
     260: astore        22
     262: istore        23
     264: iconst_0
     265: istore        24
     267: iload         23
     269: ifeq          341
     272: aload_3
     273: iload         23
     275: iconst_1
     276: isub
     277: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     282: checkcast     #76                 // class java/util/List
     285: invokestatic  #230                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     288: checkcast     #9                  // class kotlin/Pair
     291: astore        25
     293: aload         22
     295: invokestatic  #230                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     298: checkcast     #9                  // class kotlin/Pair
     301: astore        26
     303: aload         25
     305: aload         26
     307: invokestatic  #238                // Method isTouching:(Lkotlin/Pair;Lkotlin/Pair;)Z
     310: ifne          330
     313: aload         22
     315: aload         26
     317: aload         25
     319: invokestatic  #240                // Method main$getAllKnotsPositions$followingPosition:(Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
     322: invokeinterface #233,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     327: goto          339
     330: aload         22
     332: aload         26
     334: invokeinterface #233,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     339: pop
     340: nop
     341: nop
     342: goto          219
     345: nop
     346: nop
     347: iinc          12, 1
     350: goto          154
     353: nop
     354: nop
     355: goto          99
     358: nop
     359: aload_3
     360: areturn

  private static final int main$part1(java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>>);
    Code:
       0: aload_0
       1: iconst_2
       2: invokestatic  #263                // Method main$getAllKnotsPositions:(Ljava/util/List;I)Ljava/util/List;
       5: invokestatic  #230                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
       8: checkcast     #89                 // class java/lang/Iterable
      11: invokestatic  #267                // Method kotlin/collections/CollectionsKt.distinct:(Ljava/lang/Iterable;)Ljava/util/List;
      14: invokeinterface #270,  1          // InterfaceMethod java/util/List.size:()I
      19: ireturn

  private static final int main$part2(java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>>);
    Code:
       0: aload_0
       1: bipush        10
       3: invokestatic  #263                // Method main$getAllKnotsPositions:(Ljava/util/List;I)Ljava/util/List;
       6: invokestatic  #230                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
       9: checkcast     #89                 // class java/lang/Iterable
      12: invokestatic  #267                // Method kotlin/collections/CollectionsKt.distinct:(Ljava/lang/Iterable;)Ljava/util/List;
      15: invokeinterface #270,  1          // InterfaceMethod java/util/List.size:()I
      20: ireturn
}