package day10

import java.io.File

val closings = mapOf('(' to ')', '[' to ']', '{' to '}', '<' to '>')
val partOneScores = mapOf(null to 0, ')' to 3, ']' to 57, '}' to 1197, '>' to 25137)
val partTwoScores = mapOf(')' to 1, ']' to 2, '}' to 3, '>' to 4)

fun main() {
    val lines = File("src/day10/input.txt").readLines().map { it.toList() }
    val results = lines.map { line ->
        line.let {
            line.fold(ArrayDeque<Char>()) { stack, ch ->
                if (ch in closings.keys) stack.addLast(closings[ch]!!)
                else if (ch != stack.removeLast()) return@let Pair(ch, null)
                stack
            }.let { stack -> Pair(null, stack) }
        }
    }

    println(results.map { it.first }.sumOf { partOneScores[it]!! })

    println(results.map { it.second }
        .filterNotNull()
        .map { it.reversed().fold(0L) { acc, ch -> (acc * 5) + partTwoScores[ch]!! } }
        .sorted()
        .let { it[it.size / 2] })
}

Compiled from "result.kt"
public final class day10.ResultKt {
  private static final java.util.Map<java.lang.Character, java.lang.Character> closings;

  private static final java.util.Map<java.lang.Character, java.lang.Integer> partOneScores;

  private static final java.util.Map<java.lang.Character, java.lang.Integer> partTwoScores;

  public static final java.util.Map<java.lang.Character, java.lang.Character> getClosings();
    Code:
       0: getstatic     #12                 // Field closings:Ljava/util/Map;
       3: areturn

  public static final java.util.Map<java.lang.Character, java.lang.Integer> getPartOneScores();
    Code:
       0: getstatic     #17                 // Field partOneScores:Ljava/util/Map;
       3: areturn

  public static final java.util.Map<java.lang.Character, java.lang.Integer> getPartTwoScores();
    Code:
       0: getstatic     #21                 // Field partTwoScores:Ljava/util/Map;
       3: areturn

  public static final void main();
    Code:
       0: new           #25                 // class java/io/File
       3: dup
       4: ldc           #27                 // String src/day10/input.txt
       6: invokespecial #31                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #37                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #39                 // class java/lang/Iterable
      18: astore_1
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #41                 // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #52                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          105
      62: aload         6
      64: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         4
      73: aload         7
      75: checkcast     #68                 // class java/lang/String
      78: astore        8
      80: astore        24
      82: iconst_0
      83: istore        9
      85: aload         8
      87: checkcast     #70                 // class java/lang/CharSequence
      90: invokestatic  #76                 // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
      93: aload         24
      95: swap
      96: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     101: pop
     102: goto          52
     105: aload         4
     107: checkcast     #82                 // class java/util/List
     110: nop
     111: astore_0
     112: aload_0
     113: checkcast     #39                 // class java/lang/Iterable
     116: astore_2
     117: iconst_0
     118: istore_3
     119: aload_2
     120: astore        4
     122: new           #41                 // class java/util/ArrayList
     125: dup
     126: aload_2
     127: bipush        10
     129: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     132: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
     135: checkcast     #52                 // class java/util/Collection
     138: astore        5
     140: iconst_0
     141: istore        6
     143: aload         4
     145: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     150: astore        7
     152: aload         7
     154: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     159: ifeq          378
     162: aload         7
     164: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     169: astore        8
     171: aload         5
     173: aload         8
     175: checkcast     #82                 // class java/util/List
     178: astore        9
     180: astore        24
     182: iconst_0
     183: istore        10
     185: aload         9
     187: astore        11
     189: iconst_0
     190: istore        12
     192: aload         9
     194: checkcast     #39                 // class java/lang/Iterable
     197: astore        14
     199: new           #84                 // class kotlin/collections/ArrayDeque
     202: dup
     203: invokespecial #86                 // Method kotlin/collections/ArrayDeque."<init>":()V
     206: astore        15
     208: iconst_0
     209: istore        17
     211: aload         15
     213: astore        18
     215: aload         14
     217: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     222: astore        19
     224: aload         19
     226: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     231: ifeq          345
     234: aload         19
     236: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     241: astore        20
     243: aload         18
     245: aload         20
     247: checkcast     #88                 // class java/lang/Character
     250: invokevirtual #92                 // Method java/lang/Character.charValue:()C
     253: istore        21
     255: astore        22
     257: iconst_0
     258: istore        23
     260: getstatic     #12                 // Field closings:Ljava/util/Map;
     263: invokeinterface #98,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     268: iload         21
     270: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     273: invokeinterface #107,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     278: ifeq          306
     281: aload         22
     283: getstatic     #12                 // Field closings:Ljava/util/Map;
     286: iload         21
     288: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     291: invokeinterface #111,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     296: dup
     297: invokestatic  #117                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     300: invokevirtual #120                // Method kotlin/collections/ArrayDeque.addLast:(Ljava/lang/Object;)V
     303: goto          338
     306: iload         21
     308: aload         22
     310: invokevirtual #123                // Method kotlin/collections/ArrayDeque.removeLast:()Ljava/lang/Object;
     313: checkcast     #88                 // class java/lang/Character
     316: invokevirtual #92                 // Method java/lang/Character.charValue:()C
     319: if_icmpeq     338
     322: new           #125                // class kotlin/Pair
     325: dup
     326: iload         21
     328: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     331: aconst_null
     332: invokespecial #128                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     335: goto          364
     338: aload         22
     340: astore        18
     342: goto          224
     345: aload         18
     347: astore        15
     349: iconst_0
     350: istore        17
     352: new           #125                // class kotlin/Pair
     355: dup
     356: aconst_null
     357: aload         15
     359: invokespecial #128                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     362: nop
     363: nop
     364: nop
     365: nop
     366: aload         24
     368: swap
     369: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     374: pop
     375: goto          152
     378: aload         5
     380: checkcast     #82                 // class java/util/List
     383: nop
     384: astore_1
     385: aload_1
     386: checkcast     #39                 // class java/lang/Iterable
     389: astore_2
     390: iconst_0
     391: istore_3
     392: aload_2
     393: astore        4
     395: new           #41                 // class java/util/ArrayList
     398: dup
     399: aload_2
     400: bipush        10
     402: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     405: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
     408: checkcast     #52                 // class java/util/Collection
     411: astore        5
     413: iconst_0
     414: istore        6
     416: aload         4
     418: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     423: astore        7
     425: aload         7
     427: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     432: ifeq          478
     435: aload         7
     437: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     442: astore        8
     444: aload         5
     446: aload         8
     448: checkcast     #125                // class kotlin/Pair
     451: astore        9
     453: astore        24
     455: iconst_0
     456: istore        10
     458: aload         9
     460: invokevirtual #131                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     463: checkcast     #88                 // class java/lang/Character
     466: aload         24
     468: swap
     469: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     474: pop
     475: goto          425
     478: aload         5
     480: checkcast     #82                 // class java/util/List
     483: nop
     484: checkcast     #39                 // class java/lang/Iterable
     487: astore_2
     488: iconst_0
     489: istore_3
     490: aload_2
     491: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     496: astore        4
     498: aload         4
     500: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     505: ifeq          561
     508: aload         4
     510: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     515: astore        5
     517: iload_3
     518: aload         5
     520: checkcast     #88                 // class java/lang/Character
     523: astore        6
     525: istore        24
     527: iconst_0
     528: istore        7
     530: getstatic     #17                 // Field partOneScores:Ljava/util/Map;
     533: aload         6
     535: invokeinterface #111,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     540: dup
     541: invokestatic  #117                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     544: checkcast     #133                // class java/lang/Number
     547: invokevirtual #137                // Method java/lang/Number.intValue:()I
     550: istore        25
     552: iload         24
     554: iload         25
     556: iadd
     557: istore_3
     558: goto          498
     561: iload_3
     562: istore_2
     563: getstatic     #143                // Field java/lang/System.out:Ljava/io/PrintStream;
     566: iload_2
     567: invokevirtual #148                // Method java/io/PrintStream.println:(I)V
     570: aload_1
     571: checkcast     #39                 // class java/lang/Iterable
     574: astore_2
     575: iconst_0
     576: istore_3
     577: aload_2
     578: astore        4
     580: new           #41                 // class java/util/ArrayList
     583: dup
     584: aload_2
     585: bipush        10
     587: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     590: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
     593: checkcast     #52                 // class java/util/Collection
     596: astore        5
     598: iconst_0
     599: istore        6
     601: aload         4
     603: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     608: astore        7
     610: aload         7
     612: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     617: ifeq          663
     620: aload         7
     622: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     627: astore        8
     629: aload         5
     631: aload         8
     633: checkcast     #125                // class kotlin/Pair
     636: astore        9
     638: astore        24
     640: iconst_0
     641: istore        10
     643: aload         9
     645: invokevirtual #151                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     648: checkcast     #84                 // class kotlin/collections/ArrayDeque
     651: aload         24
     653: swap
     654: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     659: pop
     660: goto          610
     663: aload         5
     665: checkcast     #82                 // class java/util/List
     668: nop
     669: checkcast     #39                 // class java/lang/Iterable
     672: invokestatic  #155                // Method kotlin/collections/CollectionsKt.filterNotNull:(Ljava/lang/Iterable;)Ljava/util/List;
     675: checkcast     #39                 // class java/lang/Iterable
     678: astore_2
     679: nop
     680: iconst_0
     681: istore_3
     682: aload_2
     683: astore        4
     685: new           #41                 // class java/util/ArrayList
     688: dup
     689: aload_2
     690: bipush        10
     692: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     695: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
     698: checkcast     #52                 // class java/util/Collection
     701: astore        5
     703: iconst_0
     704: istore        6
     706: aload         4
     708: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     713: astore        7
     715: aload         7
     717: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     722: ifeq          868
     725: aload         7
     727: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     732: astore        8
     734: aload         5
     736: aload         8
     738: checkcast     #84                 // class kotlin/collections/ArrayDeque
     741: astore        9
     743: astore        24
     745: iconst_0
     746: istore        10
     748: aload         9
     750: checkcast     #39                 // class java/lang/Iterable
     753: invokestatic  #158                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     756: checkcast     #39                 // class java/lang/Iterable
     759: astore        11
     761: lconst_0
     762: lstore        12
     764: iconst_0
     765: istore        14
     767: lload         12
     769: lstore        15
     771: aload         11
     773: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     778: astore        17
     780: aload         17
     782: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     787: ifeq          850
     790: aload         17
     792: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     797: astore        18
     799: lload         15
     801: aload         18
     803: checkcast     #88                 // class java/lang/Character
     806: invokevirtual #92                 // Method java/lang/Character.charValue:()C
     809: istore        19
     811: lstore        20
     813: iconst_0
     814: istore        22
     816: lload         20
     818: iconst_5
     819: i2l
     820: lmul
     821: getstatic     #21                 // Field partTwoScores:Ljava/util/Map;
     824: iload         19
     826: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     829: invokeinterface #111,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     834: dup
     835: invokestatic  #117                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     838: checkcast     #133                // class java/lang/Number
     841: invokevirtual #162                // Method java/lang/Number.longValue:()J
     844: ladd
     845: lstore        15
     847: goto          780
     850: lload         15
     852: nop
     853: invokestatic  #167                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     856: aload         24
     858: swap
     859: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     864: pop
     865: goto          715
     868: aload         5
     870: checkcast     #82                 // class java/util/List
     873: nop
     874: checkcast     #39                 // class java/lang/Iterable
     877: invokestatic  #170                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     880: astore_3
     881: iconst_0
     882: istore        4
     884: aload_3
     885: aload_3
     886: invokeinterface #173,  1          // InterfaceMethod java/util/List.size:()I
     891: iconst_2
     892: idiv
     893: invokeinterface #176,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     898: checkcast     #133                // class java/lang/Number
     901: invokevirtual #162                // Method java/lang/Number.longValue:()J
     904: lstore_2
     905: getstatic     #143                // Field java/lang/System.out:Ljava/io/PrintStream;
     908: lload_2
     909: invokevirtual #179                // Method java/io/PrintStream.println:(J)V
     912: return

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

  static {};
    Code:
       0: iconst_4
       1: anewarray     #125                // class kotlin/Pair
       4: astore_0
       5: aload_0
       6: iconst_0
       7: bipush        40
       9: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      12: bipush        41
      14: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      17: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      20: aastore
      21: aload_0
      22: iconst_1
      23: bipush        91
      25: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      28: bipush        93
      30: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      33: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      36: aastore
      37: aload_0
      38: iconst_2
      39: bipush        123
      41: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      44: bipush        125
      46: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      49: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      52: aastore
      53: aload_0
      54: iconst_3
      55: bipush        60
      57: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      60: bipush        62
      62: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      65: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      68: aastore
      69: aload_0
      70: invokestatic  #237                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      73: putstatic     #12                 // Field closings:Ljava/util/Map;
      76: iconst_5
      77: anewarray     #125                // class kotlin/Pair
      80: astore_0
      81: aload_0
      82: iconst_0
      83: aconst_null
      84: iconst_0
      85: invokestatic  #242                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      91: aastore
      92: aload_0
      93: iconst_1
      94: bipush        41
      96: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      99: iconst_3
     100: invokestatic  #242                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     103: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     106: aastore
     107: aload_0
     108: iconst_2
     109: bipush        93
     111: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     114: bipush        57
     116: invokestatic  #242                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     119: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     122: aastore
     123: aload_0
     124: iconst_3
     125: bipush        125
     127: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     130: sipush        1197
     133: invokestatic  #242                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     136: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     139: aastore
     140: aload_0
     141: iconst_4
     142: bipush        62
     144: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     147: sipush        25137
     150: invokestatic  #242                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     153: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     156: aastore
     157: aload_0
     158: invokestatic  #237                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     161: putstatic     #17                 // Field partOneScores:Ljava/util/Map;
     164: iconst_4
     165: anewarray     #125                // class kotlin/Pair
     168: astore_0
     169: aload_0
     170: iconst_0
     171: bipush        41
     173: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     176: iconst_1
     177: invokestatic  #242                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     180: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     183: aastore
     184: aload_0
     185: iconst_1
     186: bipush        93
     188: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     191: iconst_2
     192: invokestatic  #242                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     195: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     198: aastore
     199: aload_0
     200: iconst_2
     201: bipush        125
     203: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     206: iconst_3
     207: invokestatic  #242                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     210: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     213: aastore
     214: aload_0
     215: iconst_3
     216: bipush        62
     218: invokestatic  #102                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     221: iconst_4
     222: invokestatic  #242                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     225: invokestatic  #231                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     228: aastore
     229: aload_0
     230: invokestatic  #237                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     233: putstatic     #21                 // Field partTwoScores:Ljava/util/Map;
     236: return
}


package day21

import java.io.File

fun Int.mod(m: Int) = ((this - 1) % m) + 1

class Die(val sides: Int) {
    var value = 1
    var rolled = 0
    fun roll() : Int {
        return value.also {
            value = (value + 1).mod(sides)
            rolled++
        }
    }
}

fun partOne(initialPositions: List<Int>) {
    val positions = initialPositions.toTypedArray()
    val scores = arrayOf(0, 0)
    val die = Die(100)
    var player = 0

    while (scores.maxOrNull()!! < 1000) {
        val score = (0..2).map { die.roll() }.sum()
        positions[player] = (positions[player] + score).mod(10)
        scores[player] += positions[player]
        player = (player + 1) % 2
    }

    println(scores.minOrNull()!! * die.rolled)
}

data class PlayerState(val number: Int, val position: Int, val score: Int)

fun partTwo(initialPositions: List<Int>) {
    val states = mutableMapOf(
        listOf(PlayerState(0, initialPositions[0], 0), PlayerState(1, initialPositions[1], 0)) to 1L
    )
    val wins = arrayOf(0L, 0L)

    while (states.isNotEmpty()) {
        val iterator = states.iterator()
        val (players, count) = iterator.next()
        iterator.remove()
        // Next player always comes first in list
        val (player, position, score) = players[0]

        (1..3).map { die1 ->
            (1..3).map { die2 ->
                (1..3).map { die3 ->
                    val newPosition = (position + die1 + die2 + die3).mod(10)
                    val newScore = score + newPosition
                    if (newScore >= 21) {
                        wins[player] += count
                    } else {
                        val newPlayerState = PlayerState(player, newPosition, newScore)
                        val newGameState = listOf(players[1], newPlayerState)
                        states[newGameState] = count + (states[newGameState] ?: 0)
                    }
                }
            }
        }
    }

    println(wins.maxOrNull())
}

fun main() {
    val initialPositions = File("src/day21/input.txt").readLines().map { it.last().digitToInt() }
    partOne(initialPositions)
    partTwo(initialPositions)
}

Compiled from "result.kt"
public final class day21.ResultKt {
  public static final int mod(int, int);
    Code:
       0: iload_0
       1: iconst_1
       2: isub
       3: iload_1
       4: irem
       5: iconst_1
       6: iadd
       7: ireturn

  public static final void partOne(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #15                 // String initialPositions
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #23                 // class java/util/Collection
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: aload         4
      18: iconst_0
      19: anewarray     #25                 // class java/lang/Integer
      22: invokeinterface #29,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
      27: checkcast     #31                 // class "[Ljava/lang/Integer;"
      30: astore_1
      31: iconst_2
      32: anewarray     #25                 // class java/lang/Integer
      35: astore_3
      36: aload_3
      37: iconst_0
      38: iconst_0
      39: invokestatic  #35                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      42: aastore
      43: aload_3
      44: iconst_1
      45: iconst_0
      46: invokestatic  #35                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: aastore
      50: aload_3
      51: astore_2
      52: new           #37                 // class day21/Die
      55: dup
      56: bipush        100
      58: invokespecial #41                 // Method day21/Die."<init>":(I)V
      61: astore_3
      62: iconst_0
      63: istore        4
      65: aload_2
      66: checkcast     #43                 // class "[Ljava/lang/Comparable;"
      69: invokestatic  #49                 // Method kotlin/collections/ArraysKt.maxOrNull:([Ljava/lang/Comparable;)Ljava/lang/Comparable;
      72: dup
      73: invokestatic  #53                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      76: checkcast     #55                 // class java/lang/Number
      79: invokevirtual #59                 // Method java/lang/Number.intValue:()I
      82: sipush        1000
      85: if_icmpge     263
      88: new           #61                 // class kotlin/ranges/IntRange
      91: dup
      92: iconst_0
      93: iconst_2
      94: invokespecial #64                 // Method kotlin/ranges/IntRange."<init>":(II)V
      97: checkcast     #66                 // class java/lang/Iterable
     100: astore        6
     102: iconst_0
     103: istore        7
     105: aload         6
     107: astore        8
     109: new           #68                 // class java/util/ArrayList
     112: dup
     113: aload         6
     115: bipush        10
     117: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     120: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
     123: checkcast     #23                 // class java/util/Collection
     126: astore        9
     128: iconst_0
     129: istore        10
     131: aload         8
     133: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     138: astore        11
     140: aload         11
     142: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     147: ifeq          190
     150: aload         11
     152: checkcast     #87                 // class kotlin/collections/IntIterator
     155: invokevirtual #90                 // Method kotlin/collections/IntIterator.nextInt:()I
     158: istore        12
     160: aload         9
     162: iload         12
     164: istore        13
     166: astore        15
     168: iconst_0
     169: istore        14
     171: aload_3
     172: invokevirtual #93                 // Method day21/Die.roll:()I
     175: invokestatic  #35                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     178: aload         15
     180: swap
     181: invokeinterface #97,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     186: pop
     187: goto          140
     190: aload         9
     192: checkcast     #99                 // class java/util/List
     195: nop
     196: checkcast     #66                 // class java/lang/Iterable
     199: invokestatic  #103                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     202: istore        5
     204: aload_1
     205: iload         4
     207: aload_1
     208: iload         4
     210: aaload
     211: invokevirtual #104                // Method java/lang/Integer.intValue:()I
     214: iload         5
     216: iadd
     217: bipush        10
     219: invokestatic  #106                // Method mod:(II)I
     222: invokestatic  #35                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     225: aastore
     226: iload         4
     228: istore        6
     230: aload_2
     231: iload         6
     233: aload_2
     234: iload         6
     236: aaload
     237: invokevirtual #104                // Method java/lang/Integer.intValue:()I
     240: aload_1
     241: iload         4
     243: aaload
     244: invokevirtual #104                // Method java/lang/Integer.intValue:()I
     247: iadd
     248: invokestatic  #35                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     251: aastore
     252: iload         4
     254: iconst_1
     255: iadd
     256: iconst_2
     257: irem
     258: istore        4
     260: goto          65
     263: aload_2
     264: checkcast     #43                 // class "[Ljava/lang/Comparable;"
     267: invokestatic  #109                // Method kotlin/collections/ArraysKt.minOrNull:([Ljava/lang/Comparable;)Ljava/lang/Comparable;
     270: dup
     271: invokestatic  #53                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     274: checkcast     #55                 // class java/lang/Number
     277: invokevirtual #59                 // Method java/lang/Number.intValue:()I
     280: aload_3
     281: invokevirtual #112                // Method day21/Die.getRolled:()I
     284: imul
     285: istore        5
     287: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     290: iload         5
     292: invokevirtual #123                // Method java/io/PrintStream.println:(I)V
     295: return

  public static final void partTwo(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #15                 // String initialPositions
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_1
       7: anewarray     #146                // class kotlin/Pair
      10: astore_2
      11: aload_2
      12: iconst_0
      13: iconst_2
      14: anewarray     #148                // class day21/PlayerState
      17: astore_3
      18: aload_3
      19: iconst_0
      20: new           #148                // class day21/PlayerState
      23: dup
      24: iconst_0
      25: aload_0
      26: iconst_0
      27: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      32: checkcast     #55                 // class java/lang/Number
      35: invokevirtual #59                 // Method java/lang/Number.intValue:()I
      38: iconst_0
      39: invokespecial #155                // Method day21/PlayerState."<init>":(III)V
      42: aastore
      43: aload_3
      44: iconst_1
      45: new           #148                // class day21/PlayerState
      48: dup
      49: iconst_1
      50: aload_0
      51: iconst_1
      52: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      57: checkcast     #55                 // class java/lang/Number
      60: invokevirtual #59                 // Method java/lang/Number.intValue:()I
      63: iconst_0
      64: invokespecial #155                // Method day21/PlayerState."<init>":(III)V
      67: aastore
      68: aload_3
      69: invokestatic  #159                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      72: lconst_1
      73: invokestatic  #164                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      76: invokestatic  #170                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      79: aastore
      80: aload_2
      81: invokestatic  #176                // Method kotlin/collections/MapsKt.mutableMapOf:([Lkotlin/Pair;)Ljava/util/Map;
      84: astore_1
      85: iconst_2
      86: anewarray     #161                // class java/lang/Long
      89: astore_3
      90: aload_3
      91: iconst_0
      92: lconst_0
      93: invokestatic  #164                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      96: aastore
      97: aload_3
      98: iconst_1
      99: lconst_0
     100: invokestatic  #164                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     103: aastore
     104: aload_3
     105: astore_2
     106: aload_1
     107: invokeinterface #181,  1          // InterfaceMethod java/util/Map.isEmpty:()Z
     112: ifne          119
     115: iconst_1
     116: goto          120
     119: iconst_0
     120: ifeq          669
     123: aload_1
     124: invokeinterface #185,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     129: invokeinterface #188,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     134: astore_3
     135: aload_3
     136: invokeinterface #192,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     141: checkcast     #194                // class java/util/Map$Entry
     144: astore        4
     146: aload         4
     148: invokeinterface #197,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     153: checkcast     #99                 // class java/util/List
     156: astore        5
     158: aload         4
     160: invokeinterface #200,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     165: checkcast     #55                 // class java/lang/Number
     168: invokevirtual #204                // Method java/lang/Number.longValue:()J
     171: lstore        6
     173: aload_3
     174: invokeinterface #208,  1          // InterfaceMethod java/util/Iterator.remove:()V
     179: aload         5
     181: iconst_0
     182: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     187: checkcast     #148                // class day21/PlayerState
     190: astore        8
     192: aload         8
     194: invokevirtual #211                // Method day21/PlayerState.component1:()I
     197: istore        9
     199: aload         8
     201: invokevirtual #214                // Method day21/PlayerState.component2:()I
     204: istore        10
     206: aload         8
     208: invokevirtual #217                // Method day21/PlayerState.component3:()I
     211: istore        11
     213: new           #61                 // class kotlin/ranges/IntRange
     216: dup
     217: iconst_1
     218: iconst_3
     219: invokespecial #64                 // Method kotlin/ranges/IntRange."<init>":(II)V
     222: checkcast     #66                 // class java/lang/Iterable
     225: astore        12
     227: iconst_0
     228: istore        13
     230: aload         12
     232: astore        14
     234: new           #68                 // class java/util/ArrayList
     237: dup
     238: aload         12
     240: bipush        10
     242: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     245: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
     248: checkcast     #23                 // class java/util/Collection
     251: astore        15
     253: iconst_0
     254: istore        16
     256: aload         14
     258: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     263: astore        17
     265: aload         17
     267: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     272: ifeq          659
     275: aload         17
     277: checkcast     #87                 // class kotlin/collections/IntIterator
     280: invokevirtual #90                 // Method kotlin/collections/IntIterator.nextInt:()I
     283: istore        18
     285: aload         15
     287: iload         18
     289: istore        19
     291: astore        47
     293: iconst_0
     294: istore        20
     296: new           #61                 // class kotlin/ranges/IntRange
     299: dup
     300: iconst_1
     301: iconst_3
     302: invokespecial #64                 // Method kotlin/ranges/IntRange."<init>":(II)V
     305: checkcast     #66                 // class java/lang/Iterable
     308: astore        21
     310: iconst_0
     311: istore        22
     313: aload         21
     315: astore        23
     317: new           #68                 // class java/util/ArrayList
     320: dup
     321: aload         21
     323: bipush        10
     325: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     328: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
     331: checkcast     #23                 // class java/util/Collection
     334: astore        24
     336: iconst_0
     337: istore        25
     339: aload         23
     341: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     346: astore        26
     348: aload         26
     350: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     355: ifeq          640
     358: aload         26
     360: checkcast     #87                 // class kotlin/collections/IntIterator
     363: invokevirtual #90                 // Method kotlin/collections/IntIterator.nextInt:()I
     366: istore        27
     368: aload         24
     370: iload         27
     372: istore        28
     374: astore        29
     376: iconst_0
     377: istore        30
     379: new           #61                 // class kotlin/ranges/IntRange
     382: dup
     383: iconst_1
     384: iconst_3
     385: invokespecial #64                 // Method kotlin/ranges/IntRange."<init>":(II)V
     388: checkcast     #66                 // class java/lang/Iterable
     391: astore        31
     393: iconst_0
     394: istore        32
     396: aload         31
     398: astore        33
     400: new           #68                 // class java/util/ArrayList
     403: dup
     404: aload         31
     406: bipush        10
     408: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     411: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
     414: checkcast     #23                 // class java/util/Collection
     417: astore        34
     419: iconst_0
     420: istore        35
     422: aload         33
     424: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     429: astore        36
     431: aload         36
     433: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     438: ifeq          621
     441: aload         36
     443: checkcast     #87                 // class kotlin/collections/IntIterator
     446: invokevirtual #90                 // Method kotlin/collections/IntIterator.nextInt:()I
     449: istore        37
     451: aload         34
     453: iload         37
     455: istore        38
     457: astore        39
     459: iconst_0
     460: istore        40
     462: iload         10
     464: iload         19
     466: iadd
     467: iload         28
     469: iadd
     470: iload         38
     472: iadd
     473: bipush        10
     475: invokestatic  #106                // Method mod:(II)I
     478: istore        41
     480: iload         11
     482: iload         41
     484: iadd
     485: istore        42
     487: iload         42
     489: bipush        21
     491: if_icmplt     514
     494: aload_2
     495: iload         9
     497: aload_2
     498: iload         9
     500: aaload
     501: invokevirtual #218                // Method java/lang/Long.longValue:()J
     504: lload         6
     506: ladd
     507: invokestatic  #164                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     510: aastore
     511: goto          606
     514: new           #148                // class day21/PlayerState
     517: dup
     518: iload         9
     520: iload         41
     522: iload         42
     524: invokespecial #155                // Method day21/PlayerState."<init>":(III)V
     527: astore        43
     529: iconst_2
     530: anewarray     #148                // class day21/PlayerState
     533: astore        44
     535: aload         44
     537: iconst_0
     538: aload         5
     540: iconst_1
     541: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     546: aastore
     547: aload         44
     549: iconst_1
     550: aload         43
     552: aastore
     553: aload         44
     555: invokestatic  #159                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     558: astore        45
     560: aload_1
     561: astore        44
     563: lload         6
     565: aload_1
     566: aload         45
     568: invokeinterface #221,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     573: checkcast     #161                // class java/lang/Long
     576: dup
     577: ifnull        586
     580: invokevirtual #218                // Method java/lang/Long.longValue:()J
     583: goto          588
     586: pop
     587: lconst_0
     588: ladd
     589: invokestatic  #164                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     592: astore        46
     594: aload         44
     596: aload         45
     598: aload         46
     600: invokeinterface #225,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     605: pop
     606: nop
     607: aload         39
     609: getstatic     #231                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     612: invokeinterface #97,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     617: pop
     618: goto          431
     621: aload         34
     623: checkcast     #99                 // class java/util/List
     626: nop
     627: nop
     628: aload         29
     630: swap
     631: invokeinterface #97,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     636: pop
     637: goto          348
     640: aload         24
     642: checkcast     #99                 // class java/util/List
     645: nop
     646: nop
     647: aload         47
     649: swap
     650: invokeinterface #97,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     655: pop
     656: goto          265
     659: aload         15
     661: checkcast     #99                 // class java/util/List
     664: nop
     665: pop
     666: goto          106
     669: aload_2
     670: checkcast     #43                 // class "[Ljava/lang/Comparable;"
     673: invokestatic  #49                 // Method kotlin/collections/ArraysKt.maxOrNull:([Ljava/lang/Comparable;)Ljava/lang/Comparable;
     676: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     679: swap
     680: invokevirtual #233                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     683: return

  public static final void main();
    Code:
       0: new           #257                // class java/io/File
       3: dup
       4: ldc_w         #259                // String src/day21/input.txt
       7: invokespecial #262                // Method java/io/File."<init>":(Ljava/lang/String;)V
      10: aconst_null
      11: iconst_1
      12: aconst_null
      13: invokestatic  #268                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      16: checkcast     #66                 // class java/lang/Iterable
      19: astore_1
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #68                 // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #23                 // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          112
      63: aload         6
      65: invokeinterface #192,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        7
      72: aload         4
      74: aload         7
      76: checkcast     #270                // class java/lang/String
      79: astore        8
      81: astore        10
      83: iconst_0
      84: istore        9
      86: aload         8
      88: checkcast     #272                // class java/lang/CharSequence
      91: invokestatic  #278                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
      94: invokestatic  #284                // Method kotlin/text/CharsKt.digitToInt:(C)I
      97: invokestatic  #35                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     100: aload         10
     102: swap
     103: invokeinterface #97,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     108: pop
     109: goto          53
     112: aload         4
     114: checkcast     #99                 // class java/util/List
     117: nop
     118: astore_0
     119: aload_0
     120: invokestatic  #286                // Method partOne:(Ljava/util/List;)V
     123: aload_0
     124: invokestatic  #288                // Method partTwo:(Ljava/util/List;)V
     127: return

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


package dev.pankowski.garcon.domain

import java.text.BreakIterator
import java.util.*
import java.util.Collections.unmodifiableList

/**
 * Calculates [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance)
 * between given char sequences.
 */
fun levenshtein(a: CharSequence, b: CharSequence): Int {
  val aLength = a.length
  val bLength = b.length

  var cost = IntArray(aLength + 1) { it }
  var newCost = IntArray(aLength + 1) { 0 }

  for (j in 1..bLength) {
    newCost[0] = j

    for (i in 1..aLength) {
      val insertCost = cost[i] + 1
      val deleteCost = newCost[i - 1] + 1
      val replaceCost = cost[i - 1] + if (a[i - 1] == b[j - 1]) 0 else 1

      newCost[i] = minOf(insertCost, deleteCost, replaceCost)
    }

    run { val temp = cost; cost = newCost; newCost = temp }
    // Or: cost = newCost.also { newCost = cost }
  }

  return cost[aLength]
}

/**
 * Calculates [Damerau-Levenshtein distance](https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance)
 * between given char sequences.
 */
fun damerauLevenshtein(a: CharSequence, b: CharSequence): Int {
  fun distance(a: CharSequence, b: CharSequence): Int {
    assert(a.length >= 2)
    assert(b.length >= 2)

    fun levenshteinCost(cost0: IntArray, cost1: IntArray, i: Int, j: Int): Int {
      val insertCost = cost0[i] + 1
      val deleteCost = cost1[i - 1] + 1
      val replaceCost = cost0[i - 1] + if (a[i - 1] == b[j - 1]) 0 else 1
      return minOf(insertCost, deleteCost, replaceCost)
    }

    fun damerauCost(cost0: IntArray, cost1: IntArray, cost2: IntArray, i: Int, j: Int): Int {
      val levenshteinCost = levenshteinCost(cost1, cost2, i, j)
      if (a[i - 1] == b[j - 2] && a[i - 2] == b[j - 1]) {
        val transpositionCost = cost0[i - 2] + 1
        return minOf(levenshteinCost, transpositionCost)
      }
      return levenshteinCost
    }

    val aLength = a.length
    val bLength = b.length

    // First seed row, corresponding to j = 0
    val cost0 = IntArray(aLength + 1) { it }

    // Second seed row, corresponding to j = 1
    val cost1 = IntArray(aLength + 1)
    cost1[0] = 1
    for (i in 1..aLength) cost1[i] = levenshteinCost(cost0, cost1, i, 1)

    val cost2 = IntArray(aLength + 1)

    tailrec fun cost(cost0: IntArray, cost1: IntArray, cost2: IntArray, j: Int): Int {
      cost2[0] = j
      cost2[1] = levenshteinCost(cost1, cost2, 1, j)
      for (i in 2..aLength) cost2[i] = damerauCost(cost0, cost1, cost2, i, j)

      return if (j == bLength) cost2[aLength]
      else cost(cost1, cost2, cost0, j + 1)
    }

    return cost(cost0, cost1, cost2, 2)
  }

  // Analyze input and eliminate simple cases:
  // - Order strings by length, so that we have longer (l) and shorter (s).
  // - Exit early when shorter string has zero or one character.
  // This leaves us with l.length >= s.length >= 2.
  val (l, s) = if (a.length >= b.length) Pair(a, b) else Pair(b, a)
  return when {
    s.isEmpty() -> l.length
    s.length == 1 -> if (l.contains(s[0])) l.length - 1 else l.length
    else -> distance(l, s)
  }
}

fun String.extractWords(locale: Locale): List<String> {
  val it = BreakIterator.getWordInstance(locale)
  it.setText(this)

  tailrec fun collectWords(start: Int, end: Int, words: List<String>): List<String> {
    if (end == BreakIterator.DONE) return words
    val word = this.substring(start, end)
    val newWords =
      if (Character.isLetterOrDigit(word[0])) words + word
      else words
    return collectWords(end, it.next(), newWords)
  }

  return unmodifiableList(collectWords(it.first(), it.next(), emptyList()))
}

fun CharSequence.ellipsize(at: Int) =
  when {
    length <= at -> this
    else -> substring(0, at) + Typography.ellipsis
  }

fun CharSequence.oneLinePreview(maxLength: Int) =
  replace("\\s*\\n+\\s*".toRegex(), " ").ellipsize(maxLength)

Compiled from "Texts.kt"
public final class dev.pankowski.garcon.domain.TextsKt {
  public static final int levenshtein(java.lang.CharSequence, java.lang.CharSequence);
    Code:
       0: aload_0
       1: ldc           #9                  // String a
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String b
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      18: istore_2
      19: aload_1
      20: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      25: istore_3
      26: aconst_null
      27: astore        4
      29: iconst_0
      30: istore        5
      32: iload_2
      33: iconst_1
      34: iadd
      35: istore        6
      37: iload         6
      39: newarray       int
      41: astore        7
      43: iload         5
      45: iload         6
      47: if_icmpge     67
      50: iload         5
      52: istore        8
      54: aload         7
      56: iload         8
      58: iload         8
      60: iastore
      61: iinc          5, 1
      64: goto          43
      67: aload         7
      69: astore        4
      71: aconst_null
      72: astore        5
      74: iconst_0
      75: istore        6
      77: iload_2
      78: iconst_1
      79: iadd
      80: istore        7
      82: iload         7
      84: newarray       int
      86: astore        8
      88: iload         6
      90: iload         7
      92: if_icmpge     111
      95: iload         6
      97: istore        9
      99: aload         8
     101: iload         9
     103: iconst_0
     104: iastore
     105: iinc          6, 1
     108: goto          88
     111: aload         8
     113: astore        5
     115: iconst_1
     116: istore        6
     118: iload         6
     120: iload_3
     121: if_icmpgt     255
     124: aload         5
     126: iconst_0
     127: iload         6
     129: iastore
     130: iconst_1
     131: istore        7
     133: iload         7
     135: iload_2
     136: if_icmpgt     226
     139: aload         4
     141: iload         7
     143: iaload
     144: iconst_1
     145: iadd
     146: istore        8
     148: aload         5
     150: iload         7
     152: iconst_1
     153: isub
     154: iaload
     155: iconst_1
     156: iadd
     157: istore        9
     159: aload         4
     161: iload         7
     163: iconst_1
     164: isub
     165: iaload
     166: aload_0
     167: iload         7
     169: iconst_1
     170: isub
     171: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     176: aload_1
     177: iload         6
     179: iconst_1
     180: isub
     181: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     186: if_icmpne     193
     189: iconst_0
     190: goto          194
     193: iconst_1
     194: iadd
     195: istore        10
     197: aload         5
     199: iload         7
     201: iload         8
     203: iload         9
     205: iload         10
     207: invokestatic  #33                 // Method java/lang/Math.min:(II)I
     210: invokestatic  #33                 // Method java/lang/Math.min:(II)I
     213: iastore
     214: iload         7
     216: iload_2
     217: if_icmpeq     226
     220: iinc          7, 1
     223: goto          139
     226: nop
     227: iconst_0
     228: istore        7
     230: aload         4
     232: astore        8
     234: aload         5
     236: astore        4
     238: aload         8
     240: astore        5
     242: nop
     243: iload         6
     245: iload_3
     246: if_icmpeq     255
     249: iinc          6, 1
     252: goto          124
     255: aload         4
     257: iload_2
     258: iaload
     259: ireturn

  public static final int damerauLevenshtein(java.lang.CharSequence, java.lang.CharSequence);
    Code:
       0: aload_0
       1: ldc           #9                  // String a
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String b
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      18: aload_1
      19: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      24: if_icmplt     39
      27: new           #52                 // class kotlin/Pair
      30: dup
      31: aload_0
      32: aload_1
      33: invokespecial #56                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      36: goto          48
      39: new           #52                 // class kotlin/Pair
      42: dup
      43: aload_1
      44: aload_0
      45: invokespecial #56                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      48: astore_2
      49: aload_2
      50: invokevirtual #60                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
      53: checkcast     #19                 // class java/lang/CharSequence
      56: astore_3
      57: aload_2
      58: invokevirtual #63                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
      61: checkcast     #19                 // class java/lang/CharSequence
      64: astore        4
      66: nop
      67: aload         4
      69: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      74: ifne          81
      77: iconst_1
      78: goto          82
      81: iconst_0
      82: ifeq          94
      85: aload_3
      86: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      91: goto          149
      94: aload         4
      96: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     101: iconst_1
     102: if_icmpne     143
     105: aload_3
     106: aload         4
     108: iconst_0
     109: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     114: iconst_0
     115: iconst_2
     116: aconst_null
     117: invokestatic  #69                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     120: ifeq          134
     123: aload_3
     124: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     129: iconst_1
     130: isub
     131: goto          149
     134: aload_3
     135: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     140: goto          149
     143: aload_3
     144: aload         4
     146: invokestatic  #72                 // Method damerauLevenshtein$distance:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)I
     149: ireturn

  public static final java.util.List<java.lang.String> extractWords(java.lang.String, java.util.Locale);
    Code:
       0: aload_0
       1: ldc           #79                 // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #81                 // String locale
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokestatic  #87                 // Method java/text/BreakIterator.getWordInstance:(Ljava/util/Locale;)Ljava/text/BreakIterator;
      16: astore_2
      17: aload_2
      18: aload_0
      19: invokevirtual #91                 // Method java/text/BreakIterator.setText:(Ljava/lang/String;)V
      22: aload_0
      23: aload_2
      24: aload_2
      25: invokevirtual #94                 // Method java/text/BreakIterator.first:()I
      28: aload_2
      29: invokevirtual #97                 // Method java/text/BreakIterator.next:()I
      32: invokestatic  #103                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      35: invokestatic  #107                // Method extractWords$collectWords:(Ljava/lang/String;Ljava/text/BreakIterator;IILjava/util/List;)Ljava/util/List;
      38: invokestatic  #113                // Method java/util/Collections.unmodifiableList:(Ljava/util/List;)Ljava/util/List;
      41: dup
      42: ldc           #115                // String unmodifiableList(...)
      44: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      47: areturn

  public static final java.lang.CharSequence ellipsize(java.lang.CharSequence, int);
    Code:
       0: aload_0
       1: ldc           #79                 // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: nop
       7: aload_0
       8: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      13: iload_1
      14: if_icmpgt     21
      17: aload_0
      18: goto          54
      21: new           #127                // class java/lang/StringBuilder
      24: dup
      25: invokespecial #130                // Method java/lang/StringBuilder."<init>":()V
      28: aload_0
      29: iconst_0
      30: iload_1
      31: invokeinterface #134,  3          // InterfaceMethod java/lang/CharSequence.subSequence:(II)Ljava/lang/CharSequence;
      36: invokevirtual #138                // Method java/lang/Object.toString:()Ljava/lang/String;
      39: invokevirtual #142                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: sipush        8230
      45: invokevirtual #145                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #146                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: checkcast     #19                 // class java/lang/CharSequence
      54: areturn

  public static final java.lang.CharSequence oneLinePreview(java.lang.CharSequence, int);
    Code:
       0: aload_0
       1: ldc           #79                 // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore_2
       8: new           #151                // class kotlin/text/Regex
      11: dup
      12: ldc           #153                // String \\s*\\n+\\s*
      14: invokespecial #155                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      17: astore_3
      18: ldc           #157                // String
      20: astore        4
      22: aload_3
      23: aload_2
      24: aload         4
      26: invokevirtual #161                // Method kotlin/text/Regex.replace:(Ljava/lang/CharSequence;Ljava/lang/String;)Ljava/lang/String;
      29: checkcast     #19                 // class java/lang/CharSequence
      32: iload_1
      33: invokestatic  #163                // Method ellipsize:(Ljava/lang/CharSequence;I)Ljava/lang/CharSequence;
      36: areturn

  private static final int damerauLevenshtein$distance$levenshteinCost(java.lang.CharSequence, java.lang.CharSequence, int[], int[], int, int);
    Code:
       0: aload_2
       1: iload         4
       3: iaload
       4: iconst_1
       5: iadd
       6: istore        6
       8: aload_3
       9: iload         4
      11: iconst_1
      12: isub
      13: iaload
      14: iconst_1
      15: iadd
      16: istore        7
      18: aload_2
      19: iload         4
      21: iconst_1
      22: isub
      23: iaload
      24: aload_0
      25: iload         4
      27: iconst_1
      28: isub
      29: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      34: aload_1
      35: iload         5
      37: iconst_1
      38: isub
      39: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      44: if_icmpne     51
      47: iconst_0
      48: goto          52
      51: iconst_1
      52: iadd
      53: istore        8
      55: iload         6
      57: iload         7
      59: iload         8
      61: invokestatic  #33                 // Method java/lang/Math.min:(II)I
      64: invokestatic  #33                 // Method java/lang/Math.min:(II)I
      67: ireturn

  private static final int damerauLevenshtein$distance$damerauCost(java.lang.CharSequence, java.lang.CharSequence, int[], int[], int[], int, int);
    Code:
       0: aload_0
       1: aload_1
       2: aload_3
       3: aload         4
       5: iload         5
       7: iload         6
       9: invokestatic  #175                // Method damerauLevenshtein$distance$levenshteinCost:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;[I[III)I
      12: istore        7
      14: aload_0
      15: iload         5
      17: iconst_1
      18: isub
      19: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      24: aload_1
      25: iload         6
      27: iconst_2
      28: isub
      29: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      34: if_icmpne     78
      37: aload_0
      38: iload         5
      40: iconst_2
      41: isub
      42: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      47: aload_1
      48: iload         6
      50: iconst_1
      51: isub
      52: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      57: if_icmpne     78
      60: aload_2
      61: iload         5
      63: iconst_2
      64: isub
      65: iaload
      66: iconst_1
      67: iadd
      68: istore        8
      70: iload         7
      72: iload         8
      74: invokestatic  #33                 // Method java/lang/Math.min:(II)I
      77: ireturn
      78: iload         7
      80: ireturn

  private static final int damerauLevenshtein$distance$cost(int, int, java.lang.CharSequence, java.lang.CharSequence, int[], int[], int[], int);
    Code:
       0: aload         6
       2: iconst_0
       3: iload         7
       5: iastore
       6: aload         6
       8: iconst_1
       9: aload_2
      10: aload_3
      11: aload         5
      13: aload         6
      15: iconst_1
      16: iload         7
      18: invokestatic  #175                // Method damerauLevenshtein$distance$levenshteinCost:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;[I[III)I
      21: iastore
      22: iconst_2
      23: istore        8
      25: iload         8
      27: iload_0
      28: if_icmpgt     63
      31: aload         6
      33: iload         8
      35: aload_2
      36: aload_3
      37: aload         4
      39: aload         5
      41: aload         6
      43: iload         8
      45: iload         7
      47: invokestatic  #182                // Method damerauLevenshtein$distance$damerauCost:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;[I[I[III)I
      50: iastore
      51: iload         8
      53: iload_0
      54: if_icmpeq     63
      57: iinc          8, 1
      60: goto          31
      63: iload         7
      65: iload_1
      66: if_icmpne     76
      69: aload         6
      71: iload_0
      72: iaload
      73: goto          113
      76: aload         5
      78: astore        8
      80: aload         6
      82: astore        9
      84: aload         4
      86: astore        10
      88: iload         7
      90: iconst_1
      91: iadd
      92: istore        11
      94: aload         8
      96: astore        4
      98: aload         9
     100: astore        5
     102: aload         10
     104: astore        6
     106: iload         11
     108: istore        7
     110: goto          0
     113: ireturn

  private static final int damerauLevenshtein$distance(java.lang.CharSequence, java.lang.CharSequence);
    Code:
       0: aload_0
       1: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
       6: iconst_2
       7: if_icmplt     14
      10: iconst_1
      11: goto          15
      14: iconst_0
      15: istore_2
      16: getstatic     #188                // Field kotlin/_Assertions.ENABLED:Z
      19: ifeq          38
      22: iload_2
      23: ifne          38
      26: ldc           #190                // String Assertion failed
      28: astore_3
      29: new           #192                // class java/lang/AssertionError
      32: dup
      33: aload_3
      34: invokespecial #195                // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
      37: athrow
      38: aload_1
      39: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      44: iconst_2
      45: if_icmplt     52
      48: iconst_1
      49: goto          53
      52: iconst_0
      53: istore_2
      54: getstatic     #188                // Field kotlin/_Assertions.ENABLED:Z
      57: ifeq          76
      60: iload_2
      61: ifne          76
      64: ldc           #190                // String Assertion failed
      66: astore_3
      67: new           #192                // class java/lang/AssertionError
      70: dup
      71: aload_3
      72: invokespecial #195                // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
      75: athrow
      76: aload_0
      77: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      82: istore_2
      83: aload_1
      84: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      89: istore_3
      90: iconst_0
      91: istore        5
      93: iload_2
      94: iconst_1
      95: iadd
      96: istore        6
      98: iload         6
     100: newarray       int
     102: astore        7
     104: iload         5
     106: iload         6
     108: if_icmpge     128
     111: iload         5
     113: istore        8
     115: aload         7
     117: iload         8
     119: iload         8
     121: iastore
     122: iinc          5, 1
     125: goto          104
     128: aload         7
     130: astore        4
     132: iload_2
     133: iconst_1
     134: iadd
     135: newarray       int
     137: astore        5
     139: aload         5
     141: iconst_0
     142: iconst_1
     143: iastore
     144: iconst_1
     145: istore        6
     147: iload         6
     149: iload_2
     150: if_icmpgt     182
     153: aload         5
     155: iload         6
     157: aload_0
     158: aload_1
     159: aload         4
     161: aload         5
     163: iload         6
     165: iconst_1
     166: invokestatic  #175                // Method damerauLevenshtein$distance$levenshteinCost:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;[I[III)I
     169: iastore
     170: iload         6
     172: iload_2
     173: if_icmpeq     182
     176: iinc          6, 1
     179: goto          153
     182: iload_2
     183: iconst_1
     184: iadd
     185: newarray       int
     187: astore        6
     189: iload_2
     190: iload_3
     191: aload_0
     192: aload_1
     193: aload         4
     195: aload         5
     197: aload         6
     199: iconst_2
     200: invokestatic  #197                // Method damerauLevenshtein$distance$cost:(IILjava/lang/CharSequence;Ljava/lang/CharSequence;[I[I[II)I
     203: ireturn

  private static final java.util.List<java.lang.String> extractWords$collectWords(java.lang.String, java.text.BreakIterator, int, int, java.util.List<java.lang.String>);
    Code:
       0: iload_3
       1: iconst_m1
       2: if_icmpne     8
       5: aload         4
       7: areturn
       8: aload_0
       9: iload_2
      10: iload_3
      11: invokevirtual #204                // Method java/lang/String.substring:(II)Ljava/lang/String;
      14: dup
      15: ldc           #206                // String substring(...)
      17: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      20: astore        5
      22: aload         5
      24: iconst_0
      25: invokevirtual #207                // Method java/lang/String.charAt:(I)C
      28: invokestatic  #213                // Method java/lang/Character.isLetterOrDigit:(C)Z
      31: ifeq          47
      34: aload         4
      36: checkcast     #215                // class java/util/Collection
      39: aload         5
      41: invokestatic  #219                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
      44: goto          49
      47: aload         4
      49: astore        6
      51: iload_3
      52: istore        7
      54: aload_1
      55: invokevirtual #97                 // Method java/text/BreakIterator.next:()I
      58: istore        8
      60: iload         7
      62: istore_2
      63: iload         8
      65: istore_3
      66: aload         6
      68: astore        4
      70: goto          0
}


package com.gitTraining

fun computeFibbonaciNumber(position: Int, recursion: Boolean = false): Int {
    if (recursion) return recursiveFibbonachi(position)

    if (position == 0) return 0
    if (position < 0) {
        val positionIsOdd = position % 2 == -1
        return if (positionIsOdd) computeFibbonaciNumber(-position) else (computeFibbonaciNumber(-position) * -1)
    }

    if (position == 1 || position == 2) return 1

    var smallFibbonachiNumber = 1
    var largeFibbonachiNumber = 1

    var currentPosition = 2
    while (currentPosition < position) {
        val nextFibbonachiNumber = smallFibbonachiNumber + largeFibbonachiNumber
        smallFibbonachiNumber = largeFibbonachiNumber
        largeFibbonachiNumber = nextFibbonachiNumber
        currentPosition ++
    }
    return largeFibbonachiNumber
}

fun computeFibbonachiArray(start: Int, end: Int, efficient: Boolean = false): List<Int> {
    if (!efficient) return (start..end).map { computeFibbonaciNumber(it) }
    if (start > end) return listOf()
    if (start == end) return listOf(computeFibbonaciNumber(start))
    val output = mutableListOf(computeFibbonaciNumber(start), computeFibbonaciNumber(start + 1))
    (2..(end-start)).forEach { output.add(output[it-2] + output[it-1]) }
    return output
}
fun recursiveFibbonachi(initialPosition: Int, left: Int = 0, right: Int = 1, position: Int = initialPosition): Int {
    if (initialPosition == 0) return 0
    if (position == 0) return left
    if (initialPosition > 0) {
        return recursiveFibbonachi(initialPosition, right, left + right, position - 1)
    } else {
        return recursiveFibbonachi(initialPosition, right - left, left, position + 1)
    }
}

Compiled from "Fibbonaci.kt"
public final class com.gitTraining.FibbonaciKt {
  public static final int computeFibbonaciNumber(int, boolean);
    Code:
       0: iload_1
       1: ifeq          15
       4: iload_0
       5: iconst_0
       6: iconst_0
       7: iconst_0
       8: bipush        14
      10: aconst_null
      11: invokestatic  #10                 // Method recursiveFibbonachi$default:(IIIIILjava/lang/Object;)I
      14: ireturn
      15: iload_0
      16: ifne          21
      19: iconst_0
      20: ireturn
      21: iload_0
      22: ifge          64
      25: iload_0
      26: iconst_2
      27: irem
      28: iconst_m1
      29: if_icmpne     36
      32: iconst_1
      33: goto          37
      36: iconst_0
      37: istore_2
      38: iload_2
      39: ifeq          53
      42: iload_0
      43: ineg
      44: iconst_0
      45: iconst_2
      46: aconst_null
      47: invokestatic  #14                 // Method computeFibbonaciNumber$default:(IZILjava/lang/Object;)I
      50: goto          63
      53: iload_0
      54: ineg
      55: iconst_0
      56: iconst_2
      57: aconst_null
      58: invokestatic  #14                 // Method computeFibbonaciNumber$default:(IZILjava/lang/Object;)I
      61: iconst_m1
      62: imul
      63: ireturn
      64: iload_0
      65: tableswitch   { // 1 to 2
                     1: 88
                     2: 88
               default: 90
          }
      88: iconst_1
      89: ireturn
      90: iconst_1
      91: istore_2
      92: iconst_1
      93: istore_3
      94: iconst_2
      95: istore        4
      97: iload         4
      99: iload_0
     100: if_icmpge     119
     103: iload_2
     104: iload_3
     105: iadd
     106: istore        5
     108: iload_3
     109: istore_2
     110: iload         5
     112: istore_3
     113: iinc          4, 1
     116: goto          97
     119: iload_3
     120: ireturn

  public static int computeFibbonaciNumber$default(int, boolean, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_1
       8: iload_0
       9: iload_1
      10: invokestatic  #25                 // Method computeFibbonaciNumber:(IZ)I
      13: ireturn

  public static final java.util.List<java.lang.Integer> computeFibbonachiArray(int, int, boolean);
    Code:
       0: iload_2
       1: ifne          114
       4: new           #31                 // class kotlin/ranges/IntRange
       7: dup
       8: iload_0
       9: iload_1
      10: invokespecial #35                 // Method kotlin/ranges/IntRange."<init>":(II)V
      13: checkcast     #37                 // class java/lang/Iterable
      16: astore_3
      17: iconst_0
      18: istore        4
      20: aload_3
      21: astore        5
      23: new           #39                 // class java/util/ArrayList
      26: dup
      27: aload_3
      28: bipush        10
      30: invokestatic  #45                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #48                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #50                 // class java/util/Collection
      39: astore        6
      41: iconst_0
      42: istore        7
      44: aload         5
      46: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        8
      53: aload         8
      55: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          107
      63: aload         8
      65: checkcast     #62                 // class kotlin/collections/IntIterator
      68: invokevirtual #66                 // Method kotlin/collections/IntIterator.nextInt:()I
      71: istore        9
      73: aload         6
      75: iload         9
      77: istore        10
      79: astore        12
      81: iconst_0
      82: istore        11
      84: iload         10
      86: iconst_0
      87: iconst_2
      88: aconst_null
      89: invokestatic  #14                 // Method computeFibbonaciNumber$default:(IZILjava/lang/Object;)I
      92: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      95: aload         12
      97: swap
      98: invokeinterface #76,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     103: pop
     104: goto          53
     107: aload         6
     109: checkcast     #78                 // class java/util/List
     112: nop
     113: areturn
     114: iload_0
     115: iload_1
     116: if_icmple     123
     119: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     122: areturn
     123: iload_0
     124: iload_1
     125: if_icmpne     142
     128: iload_0
     129: iconst_0
     130: iconst_2
     131: aconst_null
     132: invokestatic  #14                 // Method computeFibbonaciNumber$default:(IZILjava/lang/Object;)I
     135: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     141: areturn
     142: iconst_2
     143: anewarray     #68                 // class java/lang/Integer
     146: astore        4
     148: aload         4
     150: iconst_0
     151: iload_0
     152: iconst_0
     153: iconst_2
     154: aconst_null
     155: invokestatic  #14                 // Method computeFibbonaciNumber$default:(IZILjava/lang/Object;)I
     158: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     161: aastore
     162: aload         4
     164: iconst_1
     165: iload_0
     166: iconst_1
     167: iadd
     168: iconst_0
     169: iconst_2
     170: aconst_null
     171: invokestatic  #14                 // Method computeFibbonaciNumber$default:(IZILjava/lang/Object;)I
     174: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     177: aastore
     178: aload         4
     180: invokestatic  #90                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
     183: astore_3
     184: new           #31                 // class kotlin/ranges/IntRange
     187: dup
     188: iconst_2
     189: iload_1
     190: iload_0
     191: isub
     192: invokespecial #35                 // Method kotlin/ranges/IntRange."<init>":(II)V
     195: checkcast     #37                 // class java/lang/Iterable
     198: astore        4
     200: iconst_0
     201: istore        5
     203: aload         4
     205: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     210: astore        6
     212: aload         6
     214: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     219: ifeq          286
     222: aload         6
     224: checkcast     #62                 // class kotlin/collections/IntIterator
     227: invokevirtual #66                 // Method kotlin/collections/IntIterator.nextInt:()I
     230: istore        7
     232: iload         7
     234: istore        8
     236: iconst_0
     237: istore        9
     239: aload_3
     240: aload_3
     241: iload         8
     243: iconst_2
     244: isub
     245: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     250: checkcast     #96                 // class java/lang/Number
     253: invokevirtual #99                 // Method java/lang/Number.intValue:()I
     256: aload_3
     257: iload         8
     259: iconst_1
     260: isub
     261: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     266: checkcast     #96                 // class java/lang/Number
     269: invokevirtual #99                 // Method java/lang/Number.intValue:()I
     272: iadd
     273: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     276: invokeinterface #100,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     281: pop
     282: nop
     283: goto          212
     286: nop
     287: aload_3
     288: areturn

  public static java.util.List computeFibbonachiArray$default(int, int, boolean, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_4
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_2
       8: iload_0
       9: iload_1
      10: iload_2
      11: invokestatic  #123                // Method computeFibbonachiArray:(IIZ)Ljava/util/List;
      14: areturn

  public static final int recursiveFibbonachi(int, int, int, int);
    Code:
       0: iload_0
       1: ifne          6
       4: iconst_0
       5: ireturn
       6: iload_3
       7: ifne          12
      10: iload_1
      11: ireturn
      12: iload_0
      13: ifle          28
      16: iload_0
      17: iload_2
      18: iload_1
      19: iload_2
      20: iadd
      21: iload_3
      22: iconst_1
      23: isub
      24: invokestatic  #127                // Method recursiveFibbonachi:(IIII)I
      27: ireturn
      28: iload_0
      29: iload_2
      30: iload_1
      31: isub
      32: iload_1
      33: iload_3
      34: iconst_1
      35: iadd
      36: invokestatic  #127                // Method recursiveFibbonachi:(IIII)I
      39: ireturn

  public static int recursiveFibbonachi$default(int, int, int, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_2
       3: iand
       4: ifeq          9
       7: iconst_0
       8: istore_1
       9: iload         4
      11: iconst_4
      12: iand
      13: ifeq          18
      16: iconst_1
      17: istore_2
      18: iload         4
      20: bipush        8
      22: iand
      23: ifeq          28
      26: iload_0
      27: istore_3
      28: iload_0
      29: iload_1
      30: iload_2
      31: iload_3
      32: invokestatic  #127                // Method recursiveFibbonachi:(IIII)I
      35: ireturn
}