package com.oocode

fun scratchCardScoreFrom(input: String): Int =
    input.split("\n").mapIndexed { index, line -> scratchCardComparisonFrom(index + 1, line).score() }.sum()

fun scratchCardsFrom(input: String): Map<Int, List<ScratchCardComparison>> {
    val scratchCardComparisons =
        input.split("\n").mapIndexed { index, line -> scratchCardComparisonFrom(index + 1, line) }
    val scratchCardComparisonsByCardNumber = scratchCardComparisons.associateBy { it.cardNumber }

    val withCopies = mutableListOf<ScratchCardComparison>()
    IntRange(1, scratchCardComparisons.size).forEach {
        iterateWithCopies(it, scratchCardComparisonsByCardNumber) { scratchCard ->
            withCopies.add(scratchCard)
        }
    }
    return withCopies.groupBy { it.cardNumber }
}

fun scratchCardNumberFrom(input: String) = scratchCardsFrom(input).values.sumOf { it.size }

fun iterateWithCopies(
    cardNumber: Int,
    scratchCards: Map<Int, ScratchCardComparison>,
    f: (scratchCard: ScratchCardComparison) -> Any
) {
    if (cardNumber > scratchCards.size) return
    val head = scratchCards[cardNumber]!!
    f(head)
    val rangeOfCardsToCopy = IntRange(cardNumber + 1, cardNumber + head.numberOfCorrectGuesses())
    rangeOfCardsToCopy.forEach {
        iterateWithCopies(it, scratchCards, f)
    }
}

fun scratchCardComparisonFrom(cardNumber: Int, line: String): ScratchCardComparison =
    line.split(":")[1].split("|").let {
        val winningNumbers = numbersFrom(it[0])
        val guesses = numbersFrom(it[1])
        return ScratchCardComparison(cardNumber, winningNumbers, guesses)
    }

private fun numbersFrom(s: String) =
    s.trim().split(Regex("\\s+"))
        .map { it.toInt() }
        .toSet()

data class ScratchCardComparison(
    val cardNumber: Int,
    private val winningNumbers: Set<Int>,
    private val guesses: Set<Int>
) {
    fun score() = numberOfCorrectGuesses().let {
        if (it == 0) 0 else twoToPowerOf(it - 1)
    }

    fun numberOfCorrectGuesses() = winningNumbers.intersect(guesses).size
}

fun twoToPowerOf(i: Int) = IntRange(0, i - 1)
    .fold(1, { accumlator, _ -> accumlator * 2 })

Compiled from "ScratchCard.kt"
public final class com.oocode.ScratchCardKt {
  public static final int scratchCardScoreFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #21                 // String \n
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #29                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #31                 // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #41                 // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #43                 // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: iconst_0
      59: istore        6
      61: aload_3
      62: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      67: astore        7
      69: aload         7
      71: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          148
      79: aload         7
      81: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: astore        8
      88: aload         4
      90: iload         6
      92: iinc          6, 1
      95: istore        9
      97: iload         9
      99: ifge          105
     102: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     105: iload         9
     107: aload         8
     109: checkcast     #19                 // class java/lang/String
     112: astore        10
     114: istore        11
     116: astore        13
     118: iconst_0
     119: istore        12
     121: iload         11
     123: iconst_1
     124: iadd
     125: aload         10
     127: invokestatic  #65                 // Method scratchCardComparisonFrom:(ILjava/lang/String;)Lcom/oocode/ScratchCardComparison;
     130: invokevirtual #71                 // Method com/oocode/ScratchCardComparison.score:()I
     133: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     136: aload         13
     138: swap
     139: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     144: pop
     145: goto          69
     148: aload         4
     150: checkcast     #83                 // class java/util/List
     153: nop
     154: checkcast     #29                 // class java/lang/Iterable
     157: invokestatic  #87                 // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     160: ireturn

  public static final java.util.Map<java.lang.Integer, java.util.List<com.oocode.ScratchCardComparison>> scratchCardsFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #21                 // String \n
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #29                 // class java/lang/Iterable
      32: astore_2
      33: iconst_0
      34: istore_3
      35: aload_2
      36: astore        4
      38: new           #31                 // class java/util/ArrayList
      41: dup
      42: aload_2
      43: bipush        10
      45: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      48: invokespecial #41                 // Method java/util/ArrayList."<init>":(I)V
      51: checkcast     #43                 // class java/util/Collection
      54: astore        5
      56: iconst_0
      57: istore        6
      59: iconst_0
      60: istore        7
      62: aload         4
      64: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      69: astore        8
      71: aload         8
      73: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      78: ifeq          144
      81: aload         8
      83: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      88: astore        9
      90: aload         5
      92: iload         7
      94: iinc          7, 1
      97: istore        10
      99: iload         10
     101: ifge          107
     104: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     107: iload         10
     109: aload         9
     111: checkcast     #19                 // class java/lang/String
     114: astore        11
     116: istore        12
     118: astore        18
     120: iconst_0
     121: istore        13
     123: iload         12
     125: iconst_1
     126: iadd
     127: aload         11
     129: invokestatic  #65                 // Method scratchCardComparisonFrom:(ILjava/lang/String;)Lcom/oocode/ScratchCardComparison;
     132: aload         18
     134: swap
     135: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     140: pop
     141: goto          71
     144: aload         5
     146: checkcast     #83                 // class java/util/List
     149: nop
     150: astore_1
     151: aload_1
     152: checkcast     #29                 // class java/lang/Iterable
     155: astore_3
     156: iconst_0
     157: istore        4
     159: aload_3
     160: bipush        10
     162: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     165: invokestatic  #111                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     168: bipush        16
     170: invokestatic  #117                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     173: istore        5
     175: aload_3
     176: astore        6
     178: new           #119                // class java/util/LinkedHashMap
     181: dup
     182: iload         5
     184: invokespecial #120                // Method java/util/LinkedHashMap."<init>":(I)V
     187: checkcast     #122                // class java/util/Map
     190: astore        7
     192: iconst_0
     193: istore        8
     195: aload         6
     197: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     202: astore        9
     204: aload         9
     206: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     211: ifeq          259
     214: aload         9
     216: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     221: astore        10
     223: aload         7
     225: aload         10
     227: checkcast     #67                 // class com/oocode/ScratchCardComparison
     230: astore        11
     232: astore        18
     234: iconst_0
     235: istore        12
     237: aload         11
     239: invokevirtual #125                // Method com/oocode/ScratchCardComparison.getCardNumber:()I
     242: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     245: aload         18
     247: swap
     248: aload         10
     250: invokeinterface #129,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     255: pop
     256: goto          204
     259: aload         7
     261: nop
     262: astore_2
     263: new           #31                 // class java/util/ArrayList
     266: dup
     267: invokespecial #131                // Method java/util/ArrayList."<init>":()V
     270: checkcast     #83                 // class java/util/List
     273: astore_3
     274: new           #133                // class kotlin/ranges/IntRange
     277: dup
     278: iconst_1
     279: aload_1
     280: invokeinterface #136,  1          // InterfaceMethod java/util/List.size:()I
     285: invokespecial #139                // Method kotlin/ranges/IntRange."<init>":(II)V
     288: checkcast     #29                 // class java/lang/Iterable
     291: astore        4
     293: iconst_0
     294: istore        5
     296: aload         4
     298: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     303: astore        6
     305: aload         6
     307: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     312: ifeq          349
     315: aload         6
     317: checkcast     #141                // class kotlin/collections/IntIterator
     320: invokevirtual #144                // Method kotlin/collections/IntIterator.nextInt:()I
     323: istore        7
     325: iload         7
     327: istore        8
     329: iconst_0
     330: istore        9
     332: iload         8
     334: aload_2
     335: aload_3
     336: invokedynamic #164,  0            // InvokeDynamic #0:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
     341: invokestatic  #168                // Method iterateWithCopies:(ILjava/util/Map;Lkotlin/jvm/functions/Function1;)V
     344: nop
     345: nop
     346: goto          305
     349: nop
     350: aload_3
     351: checkcast     #29                 // class java/lang/Iterable
     354: astore        4
     356: iconst_0
     357: istore        5
     359: aload         4
     361: astore        6
     363: new           #119                // class java/util/LinkedHashMap
     366: dup
     367: invokespecial #169                // Method java/util/LinkedHashMap."<init>":()V
     370: checkcast     #122                // class java/util/Map
     373: astore        7
     375: iconst_0
     376: istore        8
     378: aload         6
     380: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     385: astore        9
     387: aload         9
     389: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     394: ifeq          502
     397: aload         9
     399: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     404: astore        10
     406: aload         10
     408: checkcast     #67                 // class com/oocode/ScratchCardComparison
     411: astore        11
     413: iconst_0
     414: istore        12
     416: aload         11
     418: invokevirtual #125                // Method com/oocode/ScratchCardComparison.getCardNumber:()I
     421: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     424: astore        13
     426: aload         7
     428: astore        14
     430: iconst_0
     431: istore        15
     433: aload         14
     435: aload         13
     437: invokeinterface #172,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     442: astore        16
     444: aload         16
     446: ifnonnull     481
     449: iconst_0
     450: istore        17
     452: new           #31                 // class java/util/ArrayList
     455: dup
     456: invokespecial #131                // Method java/util/ArrayList."<init>":()V
     459: checkcast     #83                 // class java/util/List
     462: astore        17
     464: aload         14
     466: aload         13
     468: aload         17
     470: invokeinterface #129,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     475: pop
     476: aload         17
     478: goto          483
     481: aload         16
     483: nop
     484: checkcast     #83                 // class java/util/List
     487: astore        11
     489: aload         11
     491: aload         10
     493: invokeinterface #173,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     498: pop
     499: goto          387
     502: aload         7
     504: nop
     505: areturn

  public static final int scratchCardNumberFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #207                // Method scratchCardsFrom:(Ljava/lang/String;)Ljava/util/Map;
      10: invokeinterface #211,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      15: checkcast     #29                 // class java/lang/Iterable
      18: astore_1
      19: iconst_0
      20: istore_2
      21: aload_1
      22: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      27: astore_3
      28: aload_3
      29: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          76
      37: aload_3
      38: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      43: astore        4
      45: iload_2
      46: aload         4
      48: checkcast     #83                 // class java/util/List
      51: astore        5
      53: istore        7
      55: iconst_0
      56: istore        6
      58: aload         5
      60: invokeinterface #136,  1          // InterfaceMethod java/util/List.size:()I
      65: istore        8
      67: iload         7
      69: iload         8
      71: iadd
      72: istore_2
      73: goto          28
      76: iload_2
      77: ireturn

  public static final void iterateWithCopies(int, java.util.Map<java.lang.Integer, com.oocode.ScratchCardComparison>, kotlin.jvm.functions.Function1<? super com.oocode.ScratchCardComparison, ? extends java.lang.Object>);
    Code:
       0: aload_1
       1: ldc           #215                // String scratchCards
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #217                // String f
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_0
      13: aload_1
      14: invokeinterface #218,  1          // InterfaceMethod java/util/Map.size:()I
      19: if_icmple     23
      22: return
      23: aload_1
      24: iload_0
      25: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: invokeinterface #172,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      33: dup
      34: invokestatic  #222                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      37: checkcast     #67                 // class com/oocode/ScratchCardComparison
      40: astore_3
      41: aload_2
      42: aload_3
      43: invokeinterface #226,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      48: pop
      49: new           #133                // class kotlin/ranges/IntRange
      52: dup
      53: iload_0
      54: iconst_1
      55: iadd
      56: iload_0
      57: aload_3
      58: invokevirtual #229                // Method com/oocode/ScratchCardComparison.numberOfCorrectGuesses:()I
      61: iadd
      62: invokespecial #139                // Method kotlin/ranges/IntRange."<init>":(II)V
      65: astore        4
      67: aload         4
      69: checkcast     #29                 // class java/lang/Iterable
      72: astore        5
      74: iconst_0
      75: istore        6
      77: aload         5
      79: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      84: astore        7
      86: aload         7
      88: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      93: ifeq          125
      96: aload         7
      98: checkcast     #141                // class kotlin/collections/IntIterator
     101: invokevirtual #144                // Method kotlin/collections/IntIterator.nextInt:()I
     104: istore        8
     106: iload         8
     108: istore        9
     110: iconst_0
     111: istore        10
     113: iload         9
     115: aload_1
     116: aload_2
     117: invokestatic  #168                // Method iterateWithCopies:(ILjava/util/Map;Lkotlin/jvm/functions/Function1;)V
     120: nop
     121: nop
     122: goto          86
     125: nop
     126: return

  public static final com.oocode.ScratchCardComparison scratchCardComparisonFrom(int, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #236                // String line
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #238                // String :
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: iconst_1
      30: invokeinterface #241,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: checkcast     #17                 // class java/lang/CharSequence
      38: iconst_1
      39: anewarray     #19                 // class java/lang/String
      42: astore_2
      43: aload_2
      44: iconst_0
      45: ldc           #243                // String |
      47: aastore
      48: aload_2
      49: iconst_0
      50: iconst_0
      51: bipush        6
      53: aconst_null
      54: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      57: astore_3
      58: iconst_0
      59: istore        4
      61: aload_3
      62: iconst_0
      63: invokeinterface #241,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      68: checkcast     #19                 // class java/lang/String
      71: invokestatic  #247                // Method numbersFrom:(Ljava/lang/String;)Ljava/util/Set;
      74: astore        5
      76: aload_3
      77: iconst_1
      78: invokeinterface #241,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      83: checkcast     #19                 // class java/lang/String
      86: invokestatic  #247                // Method numbersFrom:(Ljava/lang/String;)Ljava/util/Set;
      89: astore        6
      91: new           #67                 // class com/oocode/ScratchCardComparison
      94: dup
      95: iload_0
      96: aload         5
      98: aload         6
     100: invokespecial #250                // Method com/oocode/ScratchCardComparison."<init>":(ILjava/util/Set;Ljava/util/Set;)V
     103: areturn

  private static final java.util.Set<java.lang.Integer> numbersFrom(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #17                 // class java/lang/CharSequence
       4: invokestatic  #259                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
       7: invokevirtual #263                // Method java/lang/Object.toString:()Ljava/lang/String;
      10: checkcast     #17                 // class java/lang/CharSequence
      13: astore_1
      14: new           #265                // class kotlin/text/Regex
      17: dup
      18: ldc_w         #267                // String \\s+
      21: invokespecial #270                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      24: astore_2
      25: iconst_0
      26: istore_3
      27: aload_2
      28: aload_1
      29: iload_3
      30: invokevirtual #274                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      33: checkcast     #29                 // class java/lang/Iterable
      36: astore_1
      37: nop
      38: iconst_0
      39: istore_2
      40: aload_1
      41: astore_3
      42: new           #31                 // class java/util/ArrayList
      45: dup
      46: aload_1
      47: bipush        10
      49: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      52: invokespecial #41                 // Method java/util/ArrayList."<init>":(I)V
      55: checkcast     #43                 // class java/util/Collection
      58: astore        4
      60: iconst_0
      61: istore        5
      63: aload_3
      64: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      69: astore        6
      71: aload         6
      73: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      78: ifeq          125
      81: aload         6
      83: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      88: astore        7
      90: aload         4
      92: aload         7
      94: checkcast     #19                 // class java/lang/String
      97: astore        8
      99: astore        10
     101: iconst_0
     102: istore        9
     104: aload         8
     106: invokestatic  #277                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     109: nop
     110: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     113: aload         10
     115: swap
     116: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          71
     125: aload         4
     127: checkcast     #83                 // class java/util/List
     130: nop
     131: checkcast     #29                 // class java/lang/Iterable
     134: invokestatic  #281                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     137: areturn

  public static final int twoToPowerOf(int);
    Code:
       0: new           #133                // class kotlin/ranges/IntRange
       3: dup
       4: iconst_0
       5: iload_0
       6: iconst_1
       7: isub
       8: invokespecial #139                // Method kotlin/ranges/IntRange."<init>":(II)V
      11: checkcast     #29                 // class java/lang/Iterable
      14: astore_1
      15: iconst_1
      16: istore_2
      17: iconst_0
      18: istore_3
      19: iload_2
      20: istore        4
      22: aload_1
      23: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      28: astore        5
      30: aload         5
      32: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      37: ifeq          66
      40: aload         5
      42: checkcast     #141                // class kotlin/collections/IntIterator
      45: invokevirtual #144                // Method kotlin/collections/IntIterator.nextInt:()I
      48: istore        6
      50: iload         4
      52: istore        7
      54: iconst_0
      55: istore        8
      57: iload         7
      59: iconst_2
      60: imul
      61: istore        4
      63: goto          30
      66: iload         4
      68: ireturn

  private static final java.lang.Object scratchCardsFrom$lambda$4$lambda$3(java.util.List, com.oocode.ScratchCardComparison);
    Code:
       0: aload_1
       1: ldc_w         #297                // String scratchCard
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: invokeinterface #173,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      14: invokestatic  #302                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      17: areturn
}


package com.oocode

fun directionsFrom(input: String): CamelMap {
    val lines = input.split("\n")
    val instructions = lines[0]
        .map { if (it == 'L') Choice.Left else Choice.Right }
    val nodes = lines.drop(2).map { nodeFrom(it) }
    return CamelMap(instructions, nodes)
}

enum class Choice { Left, Right }

data class CamelMap(
    private val instructions: List<Choice>,
    private val nodes: List<Node>
) {
    private val nodesByName = nodes.associateBy { it.name }

    fun numberOfSteps(): Long {
        val startNodes = nodes.filter { it.name.endsWith("A") }
        val numberOfStepsForEveryStartingNode = startNodes.map { numberOfSteps(it) }
        return findLCMOfListOfNumbers(numberOfStepsForEveryStartingNode)
    }

    private fun numberOfSteps(startNode: Node): Long {
        var currentNode = startNode
        var result = 0L
        while (true) {
            instructions.forEach { instruction ->
                if (currentNode.name.endsWith("Z"))
                    return result
                result++
                currentNode = nodesByName[currentNode.follow(instruction)]!!
            }
        }
    }
}

fun nodeFrom(line: String): Node = line
    .replace("(", "")
    .replace(")", "")
    .split("=")
    .let {
        val name = it[0].trim()
        val children = it[1].split(",")
        return Node(name, Children(children[0].trim(), children[1].trim()))
    }

data class Children(val left: String, val right: String)
data class Node(val name: String, val children: Children) {
    fun follow(instruction: Choice) =
        if(instruction==Choice.Left) children.left else children.right
}

// Copied from https://www.baeldung.com/kotlin/lcm (and then replaced Int with Long)
// because I'm not interested in this part of the solution.
// I would expect this to be a thing you could find in a library
fun findLCM(a: Long, b: Long): Long {
    val larger = if (a > b) a else b
    val maxLcm = a * b
    var lcm = larger
    while (lcm <= maxLcm) {
        if (lcm % a == 0L && lcm % b == 0L) {
            return lcm
        }
        lcm += larger
    }
    return maxLcm
}
fun findLCMOfListOfNumbers(numbers: List<Long>): Long {
    var result = numbers[0]
    for (i in 1 until numbers.size) {
        result = findLCM(result, numbers[i])
    }
    return result
}

Compiled from "CamelMap.kt"
public final class com.oocode.CamelMapKt {
  public static final com.oocode.CamelMap directionsFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #21                 // String \n
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_1
      30: aload_1
      31: iconst_0
      32: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      37: checkcast     #17                 // class java/lang/CharSequence
      40: astore_3
      41: nop
      42: iconst_0
      43: istore        4
      45: aload_3
      46: astore        5
      48: new           #35                 // class java/util/ArrayList
      51: dup
      52: aload_3
      53: invokeinterface #39,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      58: invokespecial #43                 // Method java/util/ArrayList."<init>":(I)V
      61: checkcast     #45                 // class java/util/Collection
      64: astore        6
      66: iconst_0
      67: istore        7
      69: iconst_0
      70: istore        8
      72: iload         8
      74: aload         5
      76: invokeinterface #39,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      81: if_icmpge     137
      84: aload         5
      86: iload         8
      88: invokeinterface #49,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      93: istore        9
      95: aload         6
      97: iload         9
      99: istore        10
     101: astore        13
     103: iconst_0
     104: istore        11
     106: iload         10
     108: bipush        76
     110: if_icmpne     119
     113: getstatic     #55                 // Field com/oocode/Choice.Left:Lcom/oocode/Choice;
     116: goto          122
     119: getstatic     #58                 // Field com/oocode/Choice.Right:Lcom/oocode/Choice;
     122: aload         13
     124: swap
     125: invokeinterface #62,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     130: pop
     131: iinc          8, 1
     134: goto          72
     137: aload         6
     139: checkcast     #29                 // class java/util/List
     142: nop
     143: astore_2
     144: aload_1
     145: checkcast     #64                 // class java/lang/Iterable
     148: iconst_2
     149: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     152: checkcast     #64                 // class java/lang/Iterable
     155: astore        4
     157: iconst_0
     158: istore        5
     160: aload         4
     162: astore        6
     164: new           #35                 // class java/util/ArrayList
     167: dup
     168: aload         4
     170: bipush        10
     172: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     175: invokespecial #43                 // Method java/util/ArrayList."<init>":(I)V
     178: checkcast     #45                 // class java/util/Collection
     181: astore        7
     183: iconst_0
     184: istore        8
     186: aload         6
     188: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     193: astore        9
     195: aload         9
     197: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     202: ifeq          245
     205: aload         9
     207: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     212: astore        10
     214: aload         7
     216: aload         10
     218: checkcast     #19                 // class java/lang/String
     221: astore        11
     223: astore        13
     225: iconst_0
     226: istore        12
     228: aload         11
     230: invokestatic  #92                 // Method nodeFrom:(Ljava/lang/String;)Lcom/oocode/Node;
     233: aload         13
     235: swap
     236: invokeinterface #62,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     241: pop
     242: goto          195
     245: aload         7
     247: checkcast     #29                 // class java/util/List
     250: nop
     251: astore_3
     252: new           #94                 // class com/oocode/CamelMap
     255: dup
     256: aload_2
     257: aload_3
     258: invokespecial #97                 // Method com/oocode/CamelMap."<init>":(Ljava/util/List;Ljava/util/List;)V
     261: areturn

  public static final com.oocode.Node nodeFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #121                // String line
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: ldc           #123                // String (
       9: ldc           #125                // String
      11: iconst_0
      12: iconst_4
      13: aconst_null
      14: invokestatic  #129                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      17: ldc           #131                // String )
      19: ldc           #125                // String
      21: iconst_0
      22: iconst_4
      23: aconst_null
      24: invokestatic  #129                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      27: checkcast     #17                 // class java/lang/CharSequence
      30: iconst_1
      31: anewarray     #19                 // class java/lang/String
      34: astore_1
      35: aload_1
      36: iconst_0
      37: ldc           #133                // String =
      39: aastore
      40: aload_1
      41: iconst_0
      42: iconst_0
      43: bipush        6
      45: aconst_null
      46: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      49: astore_2
      50: iconst_0
      51: istore_3
      52: aload_2
      53: iconst_0
      54: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      59: checkcast     #19                 // class java/lang/String
      62: checkcast     #17                 // class java/lang/CharSequence
      65: invokestatic  #137                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      68: invokevirtual #141                // Method java/lang/Object.toString:()Ljava/lang/String;
      71: astore        4
      73: aload_2
      74: iconst_1
      75: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      80: checkcast     #17                 // class java/lang/CharSequence
      83: iconst_1
      84: anewarray     #19                 // class java/lang/String
      87: astore        5
      89: aload         5
      91: iconst_0
      92: ldc           #143                // String ,
      94: aastore
      95: aload         5
      97: iconst_0
      98: iconst_0
      99: bipush        6
     101: aconst_null
     102: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     105: astore        6
     107: new           #145                // class com/oocode/Node
     110: dup
     111: aload         4
     113: new           #147                // class com/oocode/Children
     116: dup
     117: aload         6
     119: iconst_0
     120: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     125: checkcast     #19                 // class java/lang/String
     128: checkcast     #17                 // class java/lang/CharSequence
     131: invokestatic  #137                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     134: invokevirtual #141                // Method java/lang/Object.toString:()Ljava/lang/String;
     137: aload         6
     139: iconst_1
     140: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     145: checkcast     #19                 // class java/lang/String
     148: checkcast     #17                 // class java/lang/CharSequence
     151: invokestatic  #137                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     154: invokevirtual #141                // Method java/lang/Object.toString:()Ljava/lang/String;
     157: invokespecial #150                // Method com/oocode/Children."<init>":(Ljava/lang/String;Ljava/lang/String;)V
     160: invokespecial #153                // Method com/oocode/Node."<init>":(Ljava/lang/String;Lcom/oocode/Children;)V
     163: areturn

  public static final long findLCM(long, long);
    Code:
       0: lload_0
       1: lload_2
       2: lcmp
       3: ifle          10
       6: lload_0
       7: goto          11
      10: lload_2
      11: lstore        4
      13: lload_0
      14: lload_2
      15: lmul
      16: lstore        6
      18: lload         4
      20: lstore        8
      22: lload         8
      24: lload         6
      26: lcmp
      27: ifgt          61
      30: lload         8
      32: lload_0
      33: lrem
      34: lconst_0
      35: lcmp
      36: ifne          51
      39: lload         8
      41: lload_2
      42: lrem
      43: lconst_0
      44: lcmp
      45: ifne          51
      48: lload         8
      50: lreturn
      51: lload         8
      53: lload         4
      55: ladd
      56: lstore        8
      58: goto          22
      61: lload         6
      63: lreturn

  public static final long findLCMOfListOfNumbers(java.util.List<java.lang.Long>);
    Code:
       0: aload_0
       1: ldc           #169                // String numbers
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iconst_0
       8: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #171                // class java/lang/Number
      16: invokevirtual #175                // Method java/lang/Number.longValue:()J
      19: lstore_1
      20: iconst_1
      21: istore_3
      22: aload_0
      23: invokeinterface #178,  1          // InterfaceMethod java/util/List.size:()I
      28: istore        4
      30: iload_3
      31: iload         4
      33: if_icmpge     60
      36: lload_1
      37: aload_0
      38: iload_3
      39: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      44: checkcast     #171                // class java/lang/Number
      47: invokevirtual #175                // Method java/lang/Number.longValue:()J
      50: invokestatic  #180                // Method findLCM:(JJ)J
      53: lstore_1
      54: iinc          3, 1
      57: goto          30
      60: lload_1
      61: lreturn
}

Compiled from "CamelMap.kt"
public final class com.oocode.CamelMap {
  private final java.util.List<com.oocode.Choice> instructions;

  private final java.util.List<com.oocode.Node> nodes;

  private final java.util.Map<java.lang.String, com.oocode.Node> nodesByName;

  public com.oocode.CamelMap(java.util.List<? extends com.oocode.Choice>, java.util.List<com.oocode.Node>);
    Code:
       0: aload_1
       1: ldc           #10                 // String instructions
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String nodes
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #21                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #24                 // Field instructions:Ljava/util/List;
      21: aload_0
      22: aload_2
      23: putfield      #26                 // Field nodes:Ljava/util/List;
      26: aload_0
      27: aload_0
      28: getfield      #26                 // Field nodes:Ljava/util/List;
      31: checkcast     #28                 // class java/lang/Iterable
      34: astore_3
      35: astore        13
      37: iconst_0
      38: istore        4
      40: aload_3
      41: bipush        10
      43: invokestatic  #34                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      46: invokestatic  #40                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      49: bipush        16
      51: invokestatic  #46                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      54: istore        5
      56: aload_3
      57: astore        6
      59: new           #48                 // class java/util/LinkedHashMap
      62: dup
      63: iload         5
      65: invokespecial #51                 // Method java/util/LinkedHashMap."<init>":(I)V
      68: checkcast     #53                 // class java/util/Map
      71: astore        7
      73: iconst_0
      74: istore        8
      76: aload         6
      78: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      83: astore        9
      85: aload         9
      87: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      92: ifeq          137
      95: aload         9
      97: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     102: astore        10
     104: aload         7
     106: aload         10
     108: checkcast     #69                 // class com/oocode/Node
     111: astore        11
     113: astore        14
     115: iconst_0
     116: istore        12
     118: aload         11
     120: invokevirtual #73                 // Method com/oocode/Node.getName:()Ljava/lang/String;
     123: aload         14
     125: swap
     126: aload         10
     128: invokeinterface #77,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     133: pop
     134: goto          85
     137: aload         7
     139: nop
     140: aload         13
     142: swap
     143: putfield      #81                 // Field nodesByName:Ljava/util/Map;
     146: return

  public final long numberOfSteps();
    Code:
       0: aload_0
       1: getfield      #26                 // Field nodes:Ljava/util/List;
       4: checkcast     #28                 // class java/lang/Iterable
       7: astore_2
       8: iconst_0
       9: istore_3
      10: aload_2
      11: astore        4
      13: new           #102                // class java/util/ArrayList
      16: dup
      17: invokespecial #103                // Method java/util/ArrayList."<init>":()V
      20: checkcast     #105                // class java/util/Collection
      23: astore        5
      25: iconst_0
      26: istore        6
      28: aload         4
      30: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      35: astore        7
      37: aload         7
      39: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          95
      47: aload         7
      49: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      54: astore        8
      56: aload         8
      58: checkcast     #69                 // class com/oocode/Node
      61: astore        9
      63: iconst_0
      64: istore        10
      66: aload         9
      68: invokevirtual #73                 // Method com/oocode/Node.getName:()Ljava/lang/String;
      71: ldc           #107                // String A
      73: iconst_0
      74: iconst_2
      75: aconst_null
      76: invokestatic  #113                // Method kotlin/text/StringsKt.endsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      79: ifeq          37
      82: aload         5
      84: aload         8
      86: invokeinterface #117,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: goto          37
      95: aload         5
      97: checkcast     #98                 // class java/util/List
     100: nop
     101: astore_1
     102: aload_1
     103: checkcast     #28                 // class java/lang/Iterable
     106: astore_3
     107: iconst_0
     108: istore        4
     110: aload_3
     111: astore        5
     113: new           #102                // class java/util/ArrayList
     116: dup
     117: aload_3
     118: bipush        10
     120: invokestatic  #34                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     123: invokespecial #118                // Method java/util/ArrayList."<init>":(I)V
     126: checkcast     #105                // class java/util/Collection
     129: astore        6
     131: iconst_0
     132: istore        7
     134: aload         5
     136: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     141: astore        8
     143: aload         8
     145: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     150: ifeq          197
     153: aload         8
     155: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     160: astore        9
     162: aload         6
     164: aload         9
     166: checkcast     #69                 // class com/oocode/Node
     169: astore        10
     171: astore        12
     173: iconst_0
     174: istore        11
     176: aload_0
     177: aload         10
     179: invokespecial #121                // Method numberOfSteps:(Lcom/oocode/Node;)J
     182: invokestatic  #127                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     185: aload         12
     187: swap
     188: invokeinterface #117,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     193: pop
     194: goto          143
     197: aload         6
     199: checkcast     #98                 // class java/util/List
     202: nop
     203: astore_2
     204: aload_2
     205: invokestatic  #133                // Method com/oocode/CamelMapKt.findLCMOfListOfNumbers:(Ljava/util/List;)J
     208: lreturn

  private final long numberOfSteps(com.oocode.Node);
    Code:
       0: aconst_null
       1: astore_2
       2: aload_1
       3: astore_2
       4: lconst_0
       5: lstore        9
       7: nop
       8: aload_0
       9: getfield      #24                 // Field instructions:Ljava/util/List;
      12: checkcast     #28                 // class java/lang/Iterable
      15: astore_3
      16: iconst_0
      17: istore        4
      19: aload_3
      20: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      25: astore        5
      27: aload         5
      29: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          111
      37: aload         5
      39: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      44: astore        6
      46: aload         6
      48: checkcast     #149                // class com/oocode/Choice
      51: astore        7
      53: iconst_0
      54: istore        8
      56: aload_2
      57: checkcast     #69                 // class com/oocode/Node
      60: invokevirtual #73                 // Method com/oocode/Node.getName:()Ljava/lang/String;
      63: ldc           #151                // String Z
      65: iconst_0
      66: iconst_2
      67: aconst_null
      68: invokestatic  #113                // Method kotlin/text/StringsKt.endsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      71: ifeq          77
      74: lload         9
      76: lreturn
      77: lload         9
      79: lconst_1
      80: ladd
      81: lstore        9
      83: aload_0
      84: getfield      #81                 // Field nodesByName:Ljava/util/Map;
      87: aload_2
      88: checkcast     #69                 // class com/oocode/Node
      91: aload         7
      93: invokevirtual #155                // Method com/oocode/Node.follow:(Lcom/oocode/Choice;)Ljava/lang/String;
      96: invokeinterface #159,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     101: dup
     102: invokestatic  #163                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     105: astore_2
     106: nop
     107: nop
     108: goto          27
     111: nop
     112: goto          7

  private final java.util.List<com.oocode.Choice> component1();
    Code:
       0: aload_0
       1: getfield      #24                 // Field instructions:Ljava/util/List;
       4: areturn

  private final java.util.List<com.oocode.Node> component2();
    Code:
       0: aload_0
       1: getfield      #26                 // Field nodes:Ljava/util/List;
       4: areturn

  public final com.oocode.CamelMap copy(java.util.List<? extends com.oocode.Choice>, java.util.List<com.oocode.Node>);
    Code:
       0: aload_1
       1: ldc           #10                 // String instructions
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String nodes
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class com/oocode/CamelMap
      15: dup
      16: aload_1
      17: aload_2
      18: invokespecial #183                // Method "<init>":(Ljava/util/List;Ljava/util/List;)V
      21: areturn

  public static com.oocode.CamelMap copy$default(com.oocode.CamelMap, java.util.List, java.util.List, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #24                 // Field instructions:Ljava/util/List;
      10: astore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #26                 // Field nodes:Ljava/util/List;
      21: astore_2
      22: aload_0
      23: aload_1
      24: aload_2
      25: invokevirtual #187                // Method copy:(Ljava/util/List;Ljava/util/List;)Lcom/oocode/CamelMap;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #190                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #191                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #193                // String CamelMap(instructions=
       9: invokevirtual #197                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #24                 // Field instructions:Ljava/util/List;
      16: invokevirtual #200                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: ldc           #202                // String , nodes=
      21: invokevirtual #197                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #26                 // Field nodes:Ljava/util/List;
      28: invokevirtual #200                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #205                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #207                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #24                 // Field instructions:Ljava/util/List;
       4: invokevirtual #211                // Method java/lang/Object.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #26                 // Field nodes:Ljava/util/List;
      16: invokevirtual #211                // Method java/lang/Object.hashCode:()I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class com/oocode/CamelMap
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class com/oocode/CamelMap
      20: astore_2
      21: aload_0
      22: getfield      #24                 // Field instructions:Ljava/util/List;
      25: aload_2
      26: getfield      #24                 // Field instructions:Ljava/util/List;
      29: invokestatic  #217                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #26                 // Field nodes:Ljava/util/List;
      41: aload_2
      42: getfield      #26                 // Field nodes:Ljava/util/List;
      45: invokestatic  #217                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      48: ifne          53
      51: iconst_0
      52: ireturn
      53: iconst_1
      54: ireturn
}


package descriptive

import java.util.*
import kotlin.math.floor
import kotlin.math.sqrt

object Descriptive {
    fun mean (a:List<Double>):Double{
        var res=0.0
        for (i in a){
            res+=i
        }
        return res/a.size
    }
    fun median(a:List<Double>):Double{
        val sorted=a.sorted()
        if (sorted.size%2==0){
            val i1=sorted.size/2
            val i2=i1-1
            return (sorted[i1]+sorted[i2])/2
        }else{
            val i= floor((sorted.size/2).toDouble()).toInt()
            return sorted[i]
        }
    }
    fun mode(a:List<Double>):Double{
        val res= mutableMapOf<Double,Int>()
        val listnya= mutableListOf<Pair<Double,Int>>()
        for (i in a){
            if (res.containsKey(i)){
                res[i]=res[i]!!+1
            }else{
                res[i]=1
            }
        }
        for ((k,v) in res){
            var a = Pair(k,v)
            listnya.add(a)
        }
        listnya.sortBy { it.second }
        return listnya.last().first
    }
    fun varians(a:List<Double>):Double{
        val mean= mean(a)
        var difftotal=0.0
        for (i in a){
            var diff=i-mean
            difftotal+=diff*diff
        }
        var res=difftotal/a.size
        return res
    }
    fun standardDeviaton(a:List<Double>):Double{
        return(sqrt(varians(a)))
    }
}
fun main(){
    var a=mutableListOf<Double>(5.0,2.0,2.0,2.0,7.0,4.0,1.0)
    println(a.sorted())
    println(Descriptive.median(a))
    println(Descriptive.mode(a))
    println(Descriptive.varians(a))
    println(Descriptive.standardDeviaton(a))
    var c=Random(10)
    println(c)
}

Compiled from "Descriptive.kt"
public final class descriptive.DescriptiveKt {
  public static final void main();
    Code:
       0: bipush        7
       2: anewarray     #8                  // class java/lang/Double
       5: astore_1
       6: aload_1
       7: iconst_0
       8: ldc2_w        #9                  // double 5.0d
      11: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      14: aastore
      15: aload_1
      16: iconst_1
      17: ldc2_w        #15                 // double 2.0d
      20: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      23: aastore
      24: aload_1
      25: iconst_2
      26: ldc2_w        #15                 // double 2.0d
      29: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      32: aastore
      33: aload_1
      34: iconst_3
      35: ldc2_w        #15                 // double 2.0d
      38: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      41: aastore
      42: aload_1
      43: iconst_4
      44: ldc2_w        #17                 // double 7.0d
      47: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      50: aastore
      51: aload_1
      52: iconst_5
      53: ldc2_w        #19                 // double 4.0d
      56: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      59: aastore
      60: aload_1
      61: bipush        6
      63: dconst_1
      64: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      67: aastore
      68: aload_1
      69: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      72: astore_0
      73: aload_0
      74: checkcast     #28                 // class java/lang/Iterable
      77: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      80: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      83: swap
      84: invokevirtual #44                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      87: getstatic     #50                 // Field descriptive/Descriptive.INSTANCE:Ldescriptive/Descriptive;
      90: aload_0
      91: invokevirtual #54                 // Method descriptive/Descriptive.median:(Ljava/util/List;)D
      94: dstore_1
      95: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      98: dload_1
      99: invokevirtual #57                 // Method java/io/PrintStream.println:(D)V
     102: getstatic     #50                 // Field descriptive/Descriptive.INSTANCE:Ldescriptive/Descriptive;
     105: aload_0
     106: invokevirtual #60                 // Method descriptive/Descriptive.mode:(Ljava/util/List;)D
     109: dstore_1
     110: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
     113: dload_1
     114: invokevirtual #57                 // Method java/io/PrintStream.println:(D)V
     117: getstatic     #50                 // Field descriptive/Descriptive.INSTANCE:Ldescriptive/Descriptive;
     120: aload_0
     121: invokevirtual #63                 // Method descriptive/Descriptive.varians:(Ljava/util/List;)D
     124: dstore_1
     125: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
     128: dload_1
     129: invokevirtual #57                 // Method java/io/PrintStream.println:(D)V
     132: getstatic     #50                 // Field descriptive/Descriptive.INSTANCE:Ldescriptive/Descriptive;
     135: aload_0
     136: invokevirtual #66                 // Method descriptive/Descriptive.standardDeviaton:(Ljava/util/List;)D
     139: dstore_1
     140: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
     143: dload_1
     144: invokevirtual #57                 // Method java/io/PrintStream.println:(D)V
     147: new           #68                 // class java/util/Random
     150: dup
     151: ldc2_w        #69                 // long 10l
     154: invokespecial #74                 // Method java/util/Random."<init>":(J)V
     157: astore_1
     158: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
     161: aload_1
     162: invokevirtual #44                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     165: return

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

Compiled from "Descriptive.kt"
public final class descriptive.Descriptive {
  public static final descriptive.Descriptive INSTANCE;

  private descriptive.Descriptive();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final double mean(java.util.List<java.lang.Double>);
    Code:
       0: aload_1
       1: ldc           #16                 // String a
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: dconst_0
       7: dstore_2
       8: aload_1
       9: invokeinterface #28,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      14: astore        4
      16: aload         4
      18: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          49
      26: aload         4
      28: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #40                 // class java/lang/Number
      36: invokevirtual #44                 // Method java/lang/Number.doubleValue:()D
      39: dstore        5
      41: dload_2
      42: dload         5
      44: dadd
      45: dstore_2
      46: goto          16
      49: dload_2
      50: aload_1
      51: invokeinterface #48,  1           // InterfaceMethod java/util/List.size:()I
      56: i2d
      57: ddiv
      58: dreturn

  public final double median(java.util.List<java.lang.Double>);
    Code:
       0: aload_1
       1: ldc           #16                 // String a
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #55                 // class java/lang/Iterable
      10: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      13: astore_2
      14: aload_2
      15: invokeinterface #48,  1           // InterfaceMethod java/util/List.size:()I
      20: iconst_2
      21: irem
      22: ifne          71
      25: aload_2
      26: invokeinterface #48,  1           // InterfaceMethod java/util/List.size:()I
      31: iconst_2
      32: idiv
      33: istore_3
      34: iload_3
      35: iconst_1
      36: isub
      37: istore        4
      39: aload_2
      40: iload_3
      41: invokeinterface #65,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      46: checkcast     #40                 // class java/lang/Number
      49: invokevirtual #44                 // Method java/lang/Number.doubleValue:()D
      52: aload_2
      53: iload         4
      55: invokeinterface #65,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #40                 // class java/lang/Number
      63: invokevirtual #44                 // Method java/lang/Number.doubleValue:()D
      66: dadd
      67: iconst_2
      68: i2d
      69: ddiv
      70: dreturn
      71: aload_2
      72: invokeinterface #48,  1           // InterfaceMethod java/util/List.size:()I
      77: iconst_2
      78: idiv
      79: i2d
      80: invokestatic  #71                 // Method java/lang/Math.floor:(D)D
      83: d2i
      84: istore_3
      85: aload_2
      86: iload_3
      87: invokeinterface #65,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      92: checkcast     #40                 // class java/lang/Number
      95: invokevirtual #44                 // Method java/lang/Number.doubleValue:()D
      98: dreturn

  public final double mode(java.util.List<java.lang.Double>);
    Code:
       0: aload_1
       1: ldc           #16                 // String a
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #77                 // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #78                 // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #80                 // class java/util/Map
      16: astore_2
      17: new           #82                 // class java/util/ArrayList
      20: dup
      21: invokespecial #83                 // Method java/util/ArrayList."<init>":()V
      24: checkcast     #24                 // class java/util/List
      27: astore_3
      28: aload_1
      29: invokeinterface #28,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      34: astore        4
      36: aload         4
      38: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          143
      46: aload         4
      48: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: checkcast     #40                 // class java/lang/Number
      56: invokevirtual #44                 // Method java/lang/Number.doubleValue:()D
      59: dstore        5
      61: aload_2
      62: dload         5
      64: invokestatic  #89                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      67: invokeinterface #93,  2           // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      72: ifeq          120
      75: dload         5
      77: invokestatic  #89                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      80: astore        8
      82: aload_2
      83: aload         8
      85: aload_2
      86: dload         5
      88: invokestatic  #89                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      91: invokeinterface #96,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      96: dup
      97: invokestatic  #100                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     100: checkcast     #40                 // class java/lang/Number
     103: invokevirtual #103                // Method java/lang/Number.intValue:()I
     106: iconst_1
     107: iadd
     108: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     111: invokeinterface #112,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     116: pop
     117: goto          36
     120: dload         5
     122: invokestatic  #89                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     125: astore        8
     127: aload_2
     128: aload         8
     130: iconst_1
     131: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     134: invokeinterface #112,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     139: pop
     140: goto          36
     143: aload_2
     144: invokeinterface #116,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     149: invokeinterface #119,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     154: astore        4
     156: aload         4
     158: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     163: ifeq          239
     166: aload         4
     168: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     173: checkcast     #121                // class java/util/Map$Entry
     176: astore        5
     178: aload         5
     180: invokeinterface #124,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     185: checkcast     #40                 // class java/lang/Number
     188: invokevirtual #44                 // Method java/lang/Number.doubleValue:()D
     191: dstore        6
     193: aload         5
     195: invokeinterface #127,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     200: checkcast     #40                 // class java/lang/Number
     203: invokevirtual #103                // Method java/lang/Number.intValue:()I
     206: istore        8
     208: new           #129                // class kotlin/Pair
     211: dup
     212: dload         6
     214: invokestatic  #89                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     217: iload         8
     219: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     222: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     225: astore        9
     227: aload_3
     228: aload         9
     230: invokeinterface #135,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     235: pop
     236: goto          156
     239: aload_3
     240: astore        4
     242: iconst_0
     243: istore        5
     245: aload         4
     247: invokeinterface #48,  1           // InterfaceMethod java/util/List.size:()I
     252: iconst_1
     253: if_icmple     271
     256: aload         4
     258: new           #137                // class descriptive/Descriptive$mode$$inlined$sortBy$1
     261: dup
     262: invokespecial #138                // Method descriptive/Descriptive$mode$$inlined$sortBy$1."<init>":()V
     265: checkcast     #140                // class java/util/Comparator
     268: invokestatic  #144                // Method kotlin/collections/CollectionsKt.sortWith:(Ljava/util/List;Ljava/util/Comparator;)V
     271: nop
     272: aload_3
     273: invokestatic  #148                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     276: checkcast     #129                // class kotlin/Pair
     279: invokevirtual #151                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     282: checkcast     #40                 // class java/lang/Number
     285: invokevirtual #44                 // Method java/lang/Number.doubleValue:()D
     288: dreturn

  public final double varians(java.util.List<java.lang.Double>);
    Code:
       0: aload_1
       1: ldc           #16                 // String a
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokevirtual #161                // Method mean:(Ljava/util/List;)D
      11: dstore_2
      12: dconst_0
      13: dstore        4
      15: aload_1
      16: invokeinterface #28,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      21: astore        6
      23: aload         6
      25: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          67
      33: aload         6
      35: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      40: checkcast     #40                 // class java/lang/Number
      43: invokevirtual #44                 // Method java/lang/Number.doubleValue:()D
      46: dstore        7
      48: dload         7
      50: dload_2
      51: dsub
      52: dstore        9
      54: dload         4
      56: dload         9
      58: dload         9
      60: dmul
      61: dadd
      62: dstore        4
      64: goto          23
      67: dload         4
      69: aload_1
      70: invokeinterface #48,  1           // InterfaceMethod java/util/List.size:()I
      75: i2d
      76: ddiv
      77: dstore        6
      79: dload         6
      81: dreturn

  public final double standardDeviaton(java.util.List<java.lang.Double>);
    Code:
       0: aload_1
       1: ldc           #16                 // String a
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokevirtual #166                // Method varians:(Ljava/util/List;)D
      11: invokestatic  #169                // Method java/lang/Math.sqrt:(D)D
      14: dreturn

  static {};
    Code:
       0: new           #2                  // class descriptive/Descriptive
       3: dup
       4: invokespecial #171                // Method "<init>":()V
       7: putstatic     #174                // Field INSTANCE:Ldescriptive/Descriptive;
      10: return
}

Compiled from "Comparisons.kt"
public final class descriptive.Descriptive$mode$$inlined$sortBy$1<T> implements java.util.Comparator {
  public descriptive.Descriptive$mode$$inlined$sortBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class kotlin/Pair
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      12: checkcast     #29                 // class java/lang/Integer
      15: checkcast     #31                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class kotlin/Pair
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      32: checkcast     #29                 // class java/lang/Integer
      35: aload         5
      37: swap
      38: checkcast     #31                 // class java/lang/Comparable
      41: invokestatic  #37                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}


package exercise.easy.id121

class Solution121 {
    fun maxProfit(prices: IntArray): Int {
        if (prices.size < 2) return 0
        var profit = 0
        var min = Int.MAX_VALUE
        var max = 0

        for (i in 0..<prices.size) {
            if (prices[i] < min) {
                min = prices[i]
                max = 0
            }
            if (prices[i] > max) max = prices[i]
            if (max - min > profit) profit = max - min
        }
        return profit
    }

    /*

    fun maxProfit(prices: IntArray): Int {
        if (prices.size < 2) return 0
        var profit = 0
        var min = Int.MAX_VALUE
        var max = 0

        val minn = prices.slice(1..<prices.size).minBy { it }
        val m = prices.slice(1..<prices.size).maxBy { it }
        val mIndex = prices.lastIndexOf(m)

        for (i in 0..mIndex) {
            if (prices[i] < min) {
                min = prices[i]
                max = m
            }
            if (prices[i] > max) max = prices[i]
            if (max - min > profit) profit = max - min
        }
        return profit
    }

    fun maxProfit(prices: IntArray): Int {
        if (prices.size < 2) return 0
        var profit = 0
        for (i in prices.indices) {
            for (j in i + 1..<prices.size) {
                if (prices[j] - prices[i] > profit) {
                    profit = prices[j] - prices[i]
                }
            }
        }
        return profit
    }

    fun maxProfit(prices: IntArray): Int {
        if (prices.size < 2) return 0
        var profit = 0

        val min = prices.slice(0..prices.size - 1).indices.minBy { prices[it] }
        val minIndex = prices.lastIndexOf(prices[min])
        val p = prices.slice(minIndex..prices.size - 1)

        val max = p.indices.maxBy { p[it] }
        val maxIndex = p.lastIndexOf(p[max])

        val result = p[maxIndex] - prices[minIndex]
        if (result > profit) profit = result
        return profit
    }

    fun maxProfit(prices: IntArray): Int {
        var profit = 0
        for ((index, value) in prices.withIndex()) {
            val i1 = index + 1
            if (i1 < prices.size) {
                if (prices[i1] > value) {
                    val max = prices.slice(i1..prices.size - 1).max()
                    if (profit < max - value) {
                        profit = max - value
                    }
                }
            }
        }
        return profit
    }

    fun maxProfit(prices: IntArray): Int {
        var profit = 0

        val minIndex = prices.indices.minBy { prices[it] } ?: 0
        val slice = prices.slice(minIndex..prices.size - 1)
        val maxIndex = slice.indices.maxBy { slice[it] } ?: 0
        val result = slice[maxIndex] - prices[minIndex]

        if (result > profit) profit = result

        return profit
    }

    fun maxProfit(prices: IntArray): Int {
        if (prices.size < 2) return 0
        var profit = 0
        val maxSlice = prices.slice(1..prices.size - 1)
        val maxIndex = maxSlice.indices.maxBy { maxSlice[it] } ?: 0
        val minSlice = prices.slice(0..maxSlice.lastIndexOf(maxSlice[maxIndex]))
        val minIndex = minSlice.indices.minBy { minSlice[it] } ?: 0
        val result = maxSlice[maxIndex] - minSlice[minIndex]
        if (result > profit) profit = result
        return profit
    }

*/
}

Compiled from "Solution121.kt"
public final class exercise.easy.id121.Solution121 {
  public exercise.easy.id121.Solution121();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int maxProfit(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String prices
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: arraylength
       8: iconst_2
       9: if_icmpge     14
      12: iconst_0
      13: ireturn
      14: iconst_0
      15: istore_2
      16: ldc           #22                 // int 2147483647
      18: istore_3
      19: iconst_0
      20: istore        4
      22: iconst_0
      23: istore        5
      25: aload_1
      26: arraylength
      27: istore        6
      29: iload         5
      31: iload         6
      33: if_icmpge     86
      36: aload_1
      37: iload         5
      39: iaload
      40: iload_3
      41: if_icmpge     52
      44: aload_1
      45: iload         5
      47: iaload
      48: istore_3
      49: iconst_0
      50: istore        4
      52: aload_1
      53: iload         5
      55: iaload
      56: iload         4
      58: if_icmple     67
      61: aload_1
      62: iload         5
      64: iaload
      65: istore        4
      67: iload         4
      69: iload_3
      70: isub
      71: iload_2
      72: if_icmple     80
      75: iload         4
      77: iload_3
      78: isub
      79: istore_2
      80: iinc          5, 1
      83: goto          29
      86: iload_2
      87: ireturn
}


package exercise.medium.id57

import kotlin.math.max
import kotlin.math.min

class Solution57 {
    fun insert(intervals: Array<IntArray>, newInterval: IntArray): Array<IntArray> {

        if (intervals.isEmpty()) return arrayOf(newInterval)
        if (newInterval.isEmpty()) return intervals

        println("[${newInterval[0]}, ${newInterval[1]}]")

        var start = newInterval[0]
        var end = newInterval[1]
        val left = 0
        val right = 1

        val merged = mutableListOf<IntArray>()
        var index = 0
        while (index < intervals.size && intervals[index][right] < start) {
            merged.add(intervals[index])
            index++
        }

        while (index < intervals.size && intervals[index][left] <= end) {
            start = min(start, intervals[index][left])
            end = max(end, intervals[index][right])
            index++
        }

        merged.add(intArrayOf(start, end))

        while (index < intervals.size) {
            merged.add(intervals[index])
            index++
        }

        return merged.toTypedArray()
    }
    /*

    fun insert(intervals: Array<IntArray>, newInterval: IntArray): Array<IntArray> {

        if (intervals.isEmpty()) return arrayOf(newInterval)

        println("[${newInterval[0]}, ${newInterval[1]}]")

        val start = newInterval[0]
        val end = newInterval[1]
        val left = 0
        val right = 1

        val merged1 = mutableListOf<IntArray>()
        var index1 = 0
        while (index1 < intervals.size && intervals[index1][right] < start) {
            merged1.add(intervals[index1])
            index1++
        }

        if (intervals.size == 1) index1--

        val merged2 = mutableListOf<IntArray>()
        var index2 = intervals.size - 1
        while (index2 >= 0 && intervals[index2][left] > end) {
            merged2.add(intervals[index2])
            index2--
        }

        if (intervals.size > 1) {
            val min = min(start, intervals[index1][left])
            val max = max(end, intervals[index2][right])
            merged1.add(intArrayOf(min, max))
        }
        merged2.forEach { merged1.add(it) }

        return merged1.toTypedArray()
    }

    var index2 = index
    while (index2 < intervals.size) {
        if (intervals[index2][left] > end) {
            array.add(intervals[index2])
            index2++
        }
    }

    for ((index, arr) in intervals.withIndex()) {
        if (arr[right] < start) {
            array.add(arr)
        }
    }

    while (index < intervals.size ) {
        val value = intervals[index][right]
        if (value < start) {
            array.add(intervals[index])
        } else if (value < intervals[index][leftIndex]) {
            intervals[index][right] = end
            array.add(intervals[index])
            sliceStart = index
            break
        }
    }

    for (index in intervals.indices) {
        val value = intervals[index][rightIndex]
        if (value < start) {
            array.add(intervals[index])
        } else if (value < intervals[index][leftIndex]) {
            intervals[index][rightIndex] = end
            array.add(intervals[index])
            sliceStart = index
            break
        }
    }

    fun insert(intervals: Array<IntArray>, newInterval: IntArray): Array<IntArray> {

        println("[${newInterval[0]}, ${newInterval[1]}]")

        val arrayFlatten = mutableListOf<Int>()
        for (index in intervals.indices) {
            arrayFlatten.add(intervals[index][0])
            arrayFlatten.add(intervals[index][1])
        }

        val arrayNonOverlapping = mutableListOf<Int>()
        for (index in 0..<arrayFlatten.size) {
            if (arrayFlatten[index] !in newInterval[0]..newInterval[1]) {
                println("==> ${arrayFlatten[index]}")
                arrayNonOverlapping.add(arrayFlatten[index])

            }
        }
        val arr = mutableListOf<IntArray>()
        for (index in 0..arrayNonOverlapping.size - 1 step 2) {
            arr.add(intArrayOf(arrayNonOverlapping[index], arrayNonOverlapping[index + 1]))
        }

        return arr.toTypedArray()
    }

    fun insert(intervals: Array<IntArray>, newInterval: IntArray): Array<IntArray> {
        println("[${newInterval[0]}, ${newInterval[1]}]")
        val list = intervals.flatMap { it.asIterable() }.toMutableList()
        val start = newInterval[0]
        val end = newInterval[1]
        if (start !in list) list.add(start)
        if (end !in list) list.add(end)
        list.sort()
        var shiftLeft = 1
        var shiftRight = 1
        if (list.size % 2 != 0) shiftLeft--
        val part1: List<Int> = list.slice(0..<list.indexOf(start) - shiftLeft)
        if (part1.size % 2 == 0) shiftRight++
        val part2: List<Int> = list.slice(list.indexOf(end) + shiftRight..<list.size)
        val part3: List<Int> = listOf(part1, part2).flatten()
        val arr2 = mutableListOf<IntArray>()
        for (index in 0..part3.size - 1 step 2) {
            arr2.add(intArrayOf(part3[index], part3[index + 1]))
        }
        return arr2.toTypedArray()
    }

    */
}

Compiled from "Solution57.kt"
public final class exercise.medium.id57.Solution57 {
  public exercise.medium.id57.Solution57();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int[][] insert(int[][], int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String intervals
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String newInterval
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: checkcast     #25                 // class "[Ljava/lang/Object;"
      16: arraylength
      17: ifne          24
      20: iconst_1
      21: goto          25
      24: iconst_0
      25: ifeq          39
      28: iconst_1
      29: anewarray     #27                 // class "[I"
      32: astore_3
      33: aload_3
      34: iconst_0
      35: aload_2
      36: aastore
      37: aload_3
      38: areturn
      39: aload_2
      40: arraylength
      41: ifne          48
      44: iconst_1
      45: goto          49
      48: iconst_0
      49: ifeq          54
      52: aload_1
      53: areturn
      54: new           #29                 // class java/lang/StringBuilder
      57: dup
      58: invokespecial #30                 // Method java/lang/StringBuilder."<init>":()V
      61: bipush        91
      63: invokevirtual #34                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      66: aload_2
      67: iconst_0
      68: iaload
      69: invokevirtual #37                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      72: ldc           #39                 // String ,
      74: invokevirtual #42                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      77: aload_2
      78: iconst_1
      79: iaload
      80: invokevirtual #37                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      83: bipush        93
      85: invokevirtual #34                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      88: invokevirtual #46                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      91: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      94: swap
      95: invokevirtual #58                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      98: aload_2
      99: iconst_0
     100: iaload
     101: istore_3
     102: aload_2
     103: iconst_1
     104: iaload
     105: istore        4
     107: iconst_0
     108: istore        5
     110: iconst_1
     111: istore        6
     113: new           #60                 // class java/util/ArrayList
     116: dup
     117: invokespecial #61                 // Method java/util/ArrayList."<init>":()V
     120: checkcast     #63                 // class java/util/List
     123: astore        7
     125: iconst_0
     126: istore        8
     128: iload         8
     130: aload_1
     131: checkcast     #25                 // class "[Ljava/lang/Object;"
     134: arraylength
     135: if_icmpge     167
     138: aload_1
     139: iload         8
     141: aaload
     142: iload         6
     144: iaload
     145: iload_3
     146: if_icmpge     167
     149: aload         7
     151: aload_1
     152: iload         8
     154: aaload
     155: invokeinterface #67,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     160: pop
     161: iinc          8, 1
     164: goto          128
     167: iload         8
     169: aload_1
     170: checkcast     #25                 // class "[Ljava/lang/Object;"
     173: arraylength
     174: if_icmpge     221
     177: aload_1
     178: iload         8
     180: aaload
     181: iload         5
     183: iaload
     184: iload         4
     186: if_icmpgt     221
     189: iload_3
     190: aload_1
     191: iload         8
     193: aaload
     194: iload         5
     196: iaload
     197: invokestatic  #73                 // Method java/lang/Math.min:(II)I
     200: istore_3
     201: iload         4
     203: aload_1
     204: iload         8
     206: aaload
     207: iload         6
     209: iaload
     210: invokestatic  #76                 // Method java/lang/Math.max:(II)I
     213: istore        4
     215: iinc          8, 1
     218: goto          167
     221: aload         7
     223: iconst_2
     224: newarray       int
     226: astore        9
     228: aload         9
     230: iconst_0
     231: iload_3
     232: iastore
     233: aload         9
     235: iconst_1
     236: iload         4
     238: iastore
     239: aload         9
     241: invokeinterface #67,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     246: pop
     247: iload         8
     249: aload_1
     250: checkcast     #25                 // class "[Ljava/lang/Object;"
     253: arraylength
     254: if_icmpge     275
     257: aload         7
     259: aload_1
     260: iload         8
     262: aaload
     263: invokeinterface #67,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     268: pop
     269: iinc          8, 1
     272: goto          247
     275: aload         7
     277: checkcast     #78                 // class java/util/Collection
     280: astore        9
     282: iconst_0
     283: istore        10
     285: aload         9
     287: astore        11
     289: aload         11
     291: iconst_0
     292: anewarray     #27                 // class "[I"
     295: invokeinterface #82,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     300: checkcast     #84                 // class "[[I"
     303: areturn
}