package day03

fun solveProblem01(input: List<String>): Int {
    val commonTypes = mutableListOf<Char>()
    input.forEach {
        val first = it.substring(0 until it.length/2)
        val second = it.substring((it.length / 2) until it.length)
        val commonType = commonType(first, second)
        commonTypes.add(commonType)
    }
    return commonTypes.sumOf { toScore(it) }
}

fun toScore(it: Char): Int {
    return if (it.isLowerCase())
        it.minus('a') + 1
    else
        it.minus('A') + 27
}

fun commonType(first: String, second: String): Char {
    val occurrencesFirst = HashSet<Char>()
    first.forEach {
        occurrencesFirst.add(it)
    }

    val occurrencesSecond = HashSet<Char>()
    second.forEach {
        occurrencesSecond.add(it)
    }

    val common = first.asIterable().toSet() intersect second.asIterable().toSet()
    return common.first()

}

fun solveProblem02(input: List<String>): Int {
    val windowed = input.windowed(3, 3)
    return windowed.map {
        findCommonTypes(it)
    }.sumOf {
        toScore(it)
    }
}

fun findCommonTypes(it: List<String>): Char {
    val (first, second, third) = it

    val occurrencesFirst = HashSet<Char>()
    first.forEach {
        occurrencesFirst.add(it)
    }

    val occurrencesSecond = HashSet<Char>()
    second.forEach {
        occurrencesSecond.add(it)
    }

    val occurrencesThird = HashSet<Char>()
    third.forEach {
        occurrencesThird.add(it)
    }

    val common = first.toSet() intersect second.toSet() intersect third.toSet()

    return common.first()
}

Compiled from "Problem.kt"
public final class day03.ProblemKt {
  public static final int solveProblem01(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/util/ArrayList
       9: dup
      10: invokespecial #22                 // Method java/util/ArrayList."<init>":()V
      13: checkcast     #24                 // class java/util/List
      16: astore_1
      17: aload_0
      18: checkcast     #26                 // class java/lang/Iterable
      21: astore_2
      22: iconst_0
      23: istore_3
      24: aload_2
      25: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      30: astore        4
      32: aload         4
      34: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          127
      42: aload         4
      44: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        5
      51: aload         5
      53: checkcast     #42                 // class java/lang/String
      56: astore        6
      58: iconst_0
      59: istore        7
      61: aload         6
      63: iconst_0
      64: aload         6
      66: invokevirtual #46                 // Method java/lang/String.length:()I
      69: iconst_2
      70: idiv
      71: invokestatic  #52                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      74: invokestatic  #58                 // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
      77: astore        8
      79: aload         6
      81: aload         6
      83: invokevirtual #46                 // Method java/lang/String.length:()I
      86: iconst_2
      87: idiv
      88: aload         6
      90: invokevirtual #46                 // Method java/lang/String.length:()I
      93: invokestatic  #52                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      96: invokestatic  #58                 // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
      99: astore        9
     101: aload         8
     103: aload         9
     105: invokestatic  #62                 // Method commonType:(Ljava/lang/String;Ljava/lang/String;)C
     108: istore        10
     110: aload_1
     111: iload         10
     113: invokestatic  #68                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     116: invokeinterface #72,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     121: pop
     122: nop
     123: nop
     124: goto          32
     127: nop
     128: aload_1
     129: checkcast     #26                 // class java/lang/Iterable
     132: astore_2
     133: iconst_0
     134: istore_3
     135: aload_2
     136: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     141: astore        4
     143: aload         4
     145: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     150: ifeq          194
     153: aload         4
     155: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     160: astore        5
     162: iload_3
     163: aload         5
     165: checkcast     #64                 // class java/lang/Character
     168: invokevirtual #76                 // Method java/lang/Character.charValue:()C
     171: istore        6
     173: istore        11
     175: iconst_0
     176: istore        7
     178: iload         6
     180: invokestatic  #80                 // Method toScore:(C)I
     183: istore        12
     185: iload         11
     187: iload         12
     189: iadd
     190: istore_3
     191: goto          143
     194: iload_3
     195: ireturn

  public static final int toScore(char);
    Code:
       0: iload_0
       1: invokestatic  #99                 // Method java/lang/Character.isLowerCase:(C)Z
       4: ifeq          16
       7: iload_0
       8: bipush        97
      10: isub
      11: iconst_1
      12: iadd
      13: goto          23
      16: iload_0
      17: bipush        65
      19: isub
      20: bipush        27
      22: iadd
      23: ireturn

  public static final char commonType(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #100                // String first
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #101                // String second
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #103                // class java/util/HashSet
      15: dup
      16: invokespecial #104                // Method java/util/HashSet."<init>":()V
      19: astore_2
      20: aload_0
      21: checkcast     #106                // class java/lang/CharSequence
      24: astore_3
      25: iconst_0
      26: istore        4
      28: iconst_0
      29: istore        5
      31: iload         5
      33: aload_3
      34: invokeinterface #107,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      39: if_icmpge     77
      42: aload_3
      43: iload         5
      45: invokeinterface #111,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      50: istore        6
      52: iload         6
      54: istore        7
      56: iconst_0
      57: istore        8
      59: aload_2
      60: iload         7
      62: invokestatic  #68                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      65: invokevirtual #112                // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
      68: pop
      69: nop
      70: nop
      71: iinc          5, 1
      74: goto          31
      77: nop
      78: new           #103                // class java/util/HashSet
      81: dup
      82: invokespecial #104                // Method java/util/HashSet."<init>":()V
      85: astore_3
      86: aload_1
      87: checkcast     #106                // class java/lang/CharSequence
      90: astore        4
      92: iconst_0
      93: istore        5
      95: iconst_0
      96: istore        6
      98: iload         6
     100: aload         4
     102: invokeinterface #107,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     107: if_icmpge     146
     110: aload         4
     112: iload         6
     114: invokeinterface #111,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     119: istore        7
     121: iload         7
     123: istore        8
     125: iconst_0
     126: istore        9
     128: aload_3
     129: iload         8
     131: invokestatic  #68                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     134: invokevirtual #112                // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
     137: pop
     138: nop
     139: nop
     140: iinc          6, 1
     143: goto          98
     146: nop
     147: aload_0
     148: checkcast     #106                // class java/lang/CharSequence
     151: invokestatic  #116                // Method kotlin/text/StringsKt.asIterable:(Ljava/lang/CharSequence;)Ljava/lang/Iterable;
     154: invokestatic  #122                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     157: checkcast     #26                 // class java/lang/Iterable
     160: aload_1
     161: checkcast     #106                // class java/lang/CharSequence
     164: invokestatic  #116                // Method kotlin/text/StringsKt.asIterable:(Ljava/lang/CharSequence;)Ljava/lang/Iterable;
     167: invokestatic  #122                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     170: checkcast     #26                 // class java/lang/Iterable
     173: invokestatic  #126                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     176: astore        4
     178: aload         4
     180: checkcast     #26                 // class java/lang/Iterable
     183: invokestatic  #129                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
     186: checkcast     #64                 // class java/lang/Character
     189: invokevirtual #76                 // Method java/lang/Character.charValue:()C
     192: ireturn

  public static final int solveProblem02(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #26                 // class java/lang/Iterable
      10: iconst_3
      11: iconst_3
      12: iconst_0
      13: iconst_4
      14: aconst_null
      15: invokestatic  #142                // Method kotlin/collections/CollectionsKt.windowed$default:(Ljava/lang/Iterable;IIZILjava/lang/Object;)Ljava/util/List;
      18: astore_1
      19: aload_1
      20: checkcast     #26                 // class java/lang/Iterable
      23: astore_2
      24: iconst_0
      25: istore_3
      26: aload_2
      27: astore        4
      29: new           #18                 // class java/util/ArrayList
      32: dup
      33: aload_2
      34: bipush        10
      36: invokestatic  #146                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      39: invokespecial #149                // Method java/util/ArrayList."<init>":(I)V
      42: checkcast     #151                // class java/util/Collection
      45: astore        5
      47: iconst_0
      48: istore        6
      50: aload         4
      52: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      57: astore        7
      59: aload         7
      61: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      66: ifeq          112
      69: aload         7
      71: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      76: astore        8
      78: aload         5
      80: aload         8
      82: checkcast     #24                 // class java/util/List
      85: astore        9
      87: astore        11
      89: iconst_0
      90: istore        10
      92: aload         9
      94: invokestatic  #155                // Method findCommonTypes:(Ljava/util/List;)C
      97: invokestatic  #68                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     100: aload         11
     102: swap
     103: invokeinterface #156,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     108: pop
     109: goto          59
     112: aload         5
     114: checkcast     #24                 // class java/util/List
     117: nop
     118: checkcast     #26                 // class java/lang/Iterable
     121: astore_2
     122: iconst_0
     123: istore_3
     124: aload_2
     125: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     130: astore        4
     132: aload         4
     134: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     139: ifeq          183
     142: aload         4
     144: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     149: astore        5
     151: iload_3
     152: aload         5
     154: checkcast     #64                 // class java/lang/Character
     157: invokevirtual #76                 // Method java/lang/Character.charValue:()C
     160: istore        6
     162: istore        11
     164: iconst_0
     165: istore        7
     167: iload         6
     169: invokestatic  #80                 // Method toScore:(C)I
     172: istore        12
     174: iload         11
     176: iload         12
     178: iadd
     179: istore_3
     180: goto          132
     183: iload_3
     184: ireturn

  public static final char findCommonTypes(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #168                // String it
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iconst_0
       8: invokeinterface #172,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #42                 // class java/lang/String
      16: astore_1
      17: aload_0
      18: iconst_1
      19: invokeinterface #172,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      24: checkcast     #42                 // class java/lang/String
      27: astore_2
      28: aload_0
      29: iconst_2
      30: invokeinterface #172,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: checkcast     #42                 // class java/lang/String
      38: astore_3
      39: new           #103                // class java/util/HashSet
      42: dup
      43: invokespecial #104                // Method java/util/HashSet."<init>":()V
      46: astore        4
      48: aload_1
      49: checkcast     #106                // class java/lang/CharSequence
      52: astore        5
      54: iconst_0
      55: istore        6
      57: iconst_0
      58: istore        7
      60: iload         7
      62: aload         5
      64: invokeinterface #107,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      69: if_icmpge     109
      72: aload         5
      74: iload         7
      76: invokeinterface #111,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      81: istore        8
      83: iload         8
      85: istore        9
      87: iconst_0
      88: istore        10
      90: aload         4
      92: iload         9
      94: invokestatic  #68                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      97: invokevirtual #112                // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
     100: pop
     101: nop
     102: nop
     103: iinc          7, 1
     106: goto          60
     109: nop
     110: new           #103                // class java/util/HashSet
     113: dup
     114: invokespecial #104                // Method java/util/HashSet."<init>":()V
     117: astore        5
     119: aload_2
     120: checkcast     #106                // class java/lang/CharSequence
     123: astore        6
     125: iconst_0
     126: istore        7
     128: iconst_0
     129: istore        8
     131: iload         8
     133: aload         6
     135: invokeinterface #107,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     140: if_icmpge     180
     143: aload         6
     145: iload         8
     147: invokeinterface #111,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     152: istore        9
     154: iload         9
     156: istore        10
     158: iconst_0
     159: istore        11
     161: aload         5
     163: iload         10
     165: invokestatic  #68                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     168: invokevirtual #112                // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
     171: pop
     172: nop
     173: nop
     174: iinc          8, 1
     177: goto          131
     180: nop
     181: new           #103                // class java/util/HashSet
     184: dup
     185: invokespecial #104                // Method java/util/HashSet."<init>":()V
     188: astore        6
     190: aload_3
     191: checkcast     #106                // class java/lang/CharSequence
     194: astore        7
     196: iconst_0
     197: istore        8
     199: iconst_0
     200: istore        9
     202: iload         9
     204: aload         7
     206: invokeinterface #107,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     211: if_icmpge     251
     214: aload         7
     216: iload         9
     218: invokeinterface #111,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     223: istore        10
     225: iload         10
     227: istore        11
     229: iconst_0
     230: istore        12
     232: aload         6
     234: iload         11
     236: invokestatic  #68                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     239: invokevirtual #112                // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
     242: pop
     243: nop
     244: nop
     245: iinc          9, 1
     248: goto          202
     251: nop
     252: aload_1
     253: checkcast     #106                // class java/lang/CharSequence
     256: invokestatic  #175                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
     259: checkcast     #26                 // class java/lang/Iterable
     262: aload_2
     263: checkcast     #106                // class java/lang/CharSequence
     266: invokestatic  #175                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
     269: checkcast     #26                 // class java/lang/Iterable
     272: invokestatic  #126                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     275: checkcast     #26                 // class java/lang/Iterable
     278: aload_3
     279: checkcast     #106                // class java/lang/CharSequence
     282: invokestatic  #175                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
     285: checkcast     #26                 // class java/lang/Iterable
     288: invokestatic  #126                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     291: astore        7
     293: aload         7
     295: checkcast     #26                 // class java/lang/Iterable
     298: invokestatic  #129                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
     301: checkcast     #64                 // class java/lang/Character
     304: invokevirtual #76                 // Method java/lang/Character.charValue:()C
     307: ireturn
}


package day02

fun solveProblem01(input: List<Pair<String, String>>): Int {
    var score = 0
    input.forEach {
        score += round01(it)
    }
    return score
}

// A for Rock, B for Paper, and C for Scissors
// X for Rock, Y for Paper, and Z for Scissors
// score: (1 for Rock, 2 for Paper, and 3 for Scissors) + (0 if you lost, 3 if the round was a draw, and 6 if you won)
private fun round01(pair: Pair<String, String>): Int {
    var figureScore = 0
    when (pair.second) {
        "X" -> figureScore = 1
        "Y" -> figureScore = 2
        "Z" -> figureScore = 3

    }

    var winningScore = 0
    when (pair) {
        Pair("A", "X") -> winningScore = 3
        Pair("A", "Y") -> winningScore = 6
        Pair("A", "Z") -> winningScore = 0

        Pair("B", "X") -> winningScore = 0
        Pair("B", "Y") -> winningScore = 3
        Pair("B", "Z") -> winningScore = 6

        Pair("C", "X") -> winningScore = 6
        Pair("C", "Y") -> winningScore = 0
        Pair("C", "Z") -> winningScore = 3
    }

    return figureScore + winningScore
}

fun solveProblem02(input: List<Pair<String, String>>): Int {
    var score = 0
    input.forEach {
        score += round02(it)
    }
    return score
}

// A for Rock, B for Paper, and C for Scissors
// X for lose, Y for draw, and Z for win
// score: (1 for Rock, 2 for Paper, and 3 for Scissors) + (0 if you lost, 3 if the round was a draw, and 6 if you won)
private fun round02(pair: Pair<String, String>): Int {
    var winningScore = 0
    when (pair.second) {
        "X" -> winningScore = 0
        "Y" -> winningScore = 3
        "Z" -> winningScore = 6

    }

    var figureScore = 0
    when (pair) {
        // rock
        Pair("A", "X") -> figureScore = 3 // lose with scissors
        Pair("A", "Y") -> figureScore = 1 // draw with rock
        Pair("A", "Z") -> figureScore = 2 // win with paper

        // paper
        Pair("B", "X") -> figureScore = 1 // lose with rock
        Pair("B", "Y") -> figureScore = 2 // draw with paper
        Pair("B", "Z") -> figureScore = 3 // win with scissors

        // scissors
        Pair("C", "X") -> figureScore = 2 // lose with paper
        Pair("C", "Y") -> figureScore = 3 // draw with scissors
        Pair("C", "Z") -> figureScore = 1 // win with rock
    }

    return figureScore + winningScore
}

Compiled from "Problem.kt"
public final class day02.ProblemKt {
  public static final int solveProblem01(java.util.List<kotlin.Pair<java.lang.String, java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: checkcast     #18                 // class java/lang/Iterable
      12: astore_2
      13: iconst_0
      14: istore_3
      15: aload_2
      16: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      21: astore        4
      23: aload         4
      25: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          65
      33: aload         4
      35: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      40: astore        5
      42: aload         5
      44: checkcast     #34                 // class kotlin/Pair
      47: astore        6
      49: iconst_0
      50: istore        7
      52: iload_1
      53: aload         6
      55: invokestatic  #38                 // Method round01:(Lkotlin/Pair;)I
      58: iadd
      59: istore_1
      60: nop
      61: nop
      62: goto          23
      65: nop
      66: iload_1
      67: ireturn

  private static final int round01(kotlin.Pair<java.lang.String, java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: invokevirtual #55                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
       6: checkcast     #57                 // class java/lang/String
       9: astore_2
      10: aload_2
      11: invokevirtual #61                 // Method java/lang/String.hashCode:()I
      14: tableswitch   { // 88 to 90
                    88: 40
                    89: 52
                    90: 64
               default: 88
          }
      40: aload_2
      41: ldc           #63                 // String X
      43: invokevirtual #67                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      46: ifne          76
      49: goto          88
      52: aload_2
      53: ldc           #69                 // String Y
      55: invokevirtual #67                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      58: ifne          81
      61: goto          88
      64: aload_2
      65: ldc           #71                 // String Z
      67: invokevirtual #67                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      70: ifne          86
      73: goto          88
      76: iconst_1
      77: istore_1
      78: goto          88
      81: iconst_2
      82: istore_1
      83: goto          88
      86: iconst_3
      87: istore_1
      88: iconst_0
      89: istore_2
      90: aload_0
      91: astore_3
      92: aload_3
      93: new           #34                 // class kotlin/Pair
      96: dup
      97: ldc           #73                 // String A
      99: ldc           #63                 // String X
     101: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     104: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     107: ifeq          115
     110: iconst_3
     111: istore_2
     112: goto          299
     115: aload_3
     116: new           #34                 // class kotlin/Pair
     119: dup
     120: ldc           #73                 // String A
     122: ldc           #69                 // String Y
     124: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     127: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     130: ifeq          139
     133: bipush        6
     135: istore_2
     136: goto          299
     139: aload_3
     140: new           #34                 // class kotlin/Pair
     143: dup
     144: ldc           #73                 // String A
     146: ldc           #71                 // String Z
     148: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     151: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     154: ifeq          162
     157: iconst_0
     158: istore_2
     159: goto          299
     162: aload_3
     163: new           #34                 // class kotlin/Pair
     166: dup
     167: ldc           #83                 // String B
     169: ldc           #63                 // String X
     171: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     174: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     177: ifeq          185
     180: iconst_0
     181: istore_2
     182: goto          299
     185: aload_3
     186: new           #34                 // class kotlin/Pair
     189: dup
     190: ldc           #83                 // String B
     192: ldc           #69                 // String Y
     194: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     197: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     200: ifeq          208
     203: iconst_3
     204: istore_2
     205: goto          299
     208: aload_3
     209: new           #34                 // class kotlin/Pair
     212: dup
     213: ldc           #83                 // String B
     215: ldc           #71                 // String Z
     217: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     220: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     223: ifeq          232
     226: bipush        6
     228: istore_2
     229: goto          299
     232: aload_3
     233: new           #34                 // class kotlin/Pair
     236: dup
     237: ldc           #85                 // String C
     239: ldc           #63                 // String X
     241: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     244: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     247: ifeq          256
     250: bipush        6
     252: istore_2
     253: goto          299
     256: aload_3
     257: new           #34                 // class kotlin/Pair
     260: dup
     261: ldc           #85                 // String C
     263: ldc           #69                 // String Y
     265: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     268: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     271: ifeq          279
     274: iconst_0
     275: istore_2
     276: goto          299
     279: aload_3
     280: new           #34                 // class kotlin/Pair
     283: dup
     284: ldc           #85                 // String C
     286: ldc           #71                 // String Z
     288: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     291: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     294: ifeq          299
     297: iconst_3
     298: istore_2
     299: iload_1
     300: iload_2
     301: iadd
     302: ireturn

  public static final int solveProblem02(java.util.List<kotlin.Pair<java.lang.String, java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: checkcast     #18                 // class java/lang/Iterable
      12: astore_2
      13: iconst_0
      14: istore_3
      15: aload_2
      16: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      21: astore        4
      23: aload         4
      25: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          65
      33: aload         4
      35: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      40: astore        5
      42: aload         5
      44: checkcast     #34                 // class kotlin/Pair
      47: astore        6
      49: iconst_0
      50: istore        7
      52: iload_1
      53: aload         6
      55: invokestatic  #92                 // Method round02:(Lkotlin/Pair;)I
      58: iadd
      59: istore_1
      60: nop
      61: nop
      62: goto          23
      65: nop
      66: iload_1
      67: ireturn

  private static final int round02(kotlin.Pair<java.lang.String, java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: invokevirtual #55                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
       6: checkcast     #57                 // class java/lang/String
       9: astore_2
      10: aload_2
      11: invokevirtual #61                 // Method java/lang/String.hashCode:()I
      14: tableswitch   { // 88 to 90
                    88: 40
                    89: 52
                    90: 64
               default: 89
          }
      40: aload_2
      41: ldc           #63                 // String X
      43: invokevirtual #67                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      46: ifne          76
      49: goto          89
      52: aload_2
      53: ldc           #69                 // String Y
      55: invokevirtual #67                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      58: ifne          81
      61: goto          89
      64: aload_2
      65: ldc           #71                 // String Z
      67: invokevirtual #67                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      70: ifne          86
      73: goto          89
      76: iconst_0
      77: istore_1
      78: goto          89
      81: iconst_3
      82: istore_1
      83: goto          89
      86: bipush        6
      88: istore_1
      89: iconst_0
      90: istore_2
      91: aload_0
      92: astore_3
      93: aload_3
      94: new           #34                 // class kotlin/Pair
      97: dup
      98: ldc           #73                 // String A
     100: ldc           #63                 // String X
     102: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     105: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     108: ifeq          116
     111: iconst_3
     112: istore_2
     113: goto          297
     116: aload_3
     117: new           #34                 // class kotlin/Pair
     120: dup
     121: ldc           #73                 // String A
     123: ldc           #69                 // String Y
     125: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     128: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     131: ifeq          139
     134: iconst_1
     135: istore_2
     136: goto          297
     139: aload_3
     140: new           #34                 // class kotlin/Pair
     143: dup
     144: ldc           #73                 // String A
     146: ldc           #71                 // String Z
     148: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     151: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     154: ifeq          162
     157: iconst_2
     158: istore_2
     159: goto          297
     162: aload_3
     163: new           #34                 // class kotlin/Pair
     166: dup
     167: ldc           #83                 // String B
     169: ldc           #63                 // String X
     171: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     174: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     177: ifeq          185
     180: iconst_1
     181: istore_2
     182: goto          297
     185: aload_3
     186: new           #34                 // class kotlin/Pair
     189: dup
     190: ldc           #83                 // String B
     192: ldc           #69                 // String Y
     194: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     197: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     200: ifeq          208
     203: iconst_2
     204: istore_2
     205: goto          297
     208: aload_3
     209: new           #34                 // class kotlin/Pair
     212: dup
     213: ldc           #83                 // String B
     215: ldc           #71                 // String Z
     217: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     220: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     223: ifeq          231
     226: iconst_3
     227: istore_2
     228: goto          297
     231: aload_3
     232: new           #34                 // class kotlin/Pair
     235: dup
     236: ldc           #85                 // String C
     238: ldc           #63                 // String X
     240: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     243: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     246: ifeq          254
     249: iconst_2
     250: istore_2
     251: goto          297
     254: aload_3
     255: new           #34                 // class kotlin/Pair
     258: dup
     259: ldc           #85                 // String C
     261: ldc           #69                 // String Y
     263: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     266: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     269: ifeq          277
     272: iconst_3
     273: istore_2
     274: goto          297
     277: aload_3
     278: new           #34                 // class kotlin/Pair
     281: dup
     282: ldc           #85                 // String C
     284: ldc           #71                 // String Z
     286: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     289: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     292: ifeq          297
     295: iconst_1
     296: istore_2
     297: iload_2
     298: iload_1
     299: iadd
     300: ireturn
}


package day05

import java.util.*

fun solveProblem01(input: List<String>): String {
    val stackInput = Stack<String>()
    val movements = mutableListOf<String>()
    var stackHalf = true
    for (value in input) {
        if (value.isEmpty()) {
            stackHalf = false
            continue
        }
        if (stackHalf) {
            stackInput.push(value)
        } else {
            movements.add(value)
        }
    }

    val stacks = buildInitialStack(stackInput)
    for (movement in movements) {
        val (num, from, to) = parseMovement(movement)
        repeat(num) {
            val value = stacks[from]?.pop()
            stacks[to]?.push(value)
        }
    }
    return (1..stacks.size)
        .mapNotNull { stacks[it]?.pop() }
        .joinToString("")
}

fun parseMovement(movement: String): List<Int> {
    val regex = """move (\d+) from (\d+) to (\d+)""".toRegex()
    val matchResult = regex.find(movement)
    val destructured = matchResult!!.destructured
    return destructured.toList().map { it.toInt() }
}

fun buildInitialStack(stackInput: Stack<String>): MutableMap<Int, Stack<String>> {
    val result = mutableMapOf<Int, Stack<String>>()
    val keys = stackInput
        .pop()
        .trim().split("\\s+".toRegex())
        .map {
            it.toInt()
        }
    keys
        .forEach {
            result[it] = Stack<String>()
        }
    val rowLength = keys.count()*4 - 1
    for (value in stackInput.reversed()) {
        val row = value.padEnd(rowLength)
        row.asSequence()
            .windowed(3, 4)
            .forEachIndexed { index, letters ->
                val letter = letters.filter { it.isLetter() }.joinToString("")
                if (letter.isNotBlank()) {
                    result[index+1]?.push(letter)
                }
            }
    }

    return result
}

fun solveProblem02(input: List<String>): String {
    val stackInput = Stack<String>()
    val movements = mutableListOf<String>()
    var stackHalf = true
    for (value in input) {
        if (value.isEmpty()) {
            stackHalf = false
            continue
        }
        if (stackHalf) {
            stackInput.push(value)
        } else {
            movements.add(value)
        }
    }

    val stacks = buildInitialStack(stackInput)
    for (movement in movements) {
        val (num, from, to) = parseMovement(movement)
        val temp = Stack<String>()
        repeat(num) {
            val value = stacks[from]?.pop()
            temp.push(value)
        }
        repeat(num) {
            val value = temp.pop()
            stacks[to]?.push(value)
        }
    }
    return (1..stacks.size)
        .mapNotNull { stacks[it]?.pop() }
        .joinToString("")
}

Compiled from "Problem.kt"
public final class day05.ProblemKt {
  public static final java.lang.String solveProblem01(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/util/Stack
       9: dup
      10: invokespecial #22                 // Method java/util/Stack."<init>":()V
      13: astore_1
      14: new           #24                 // class java/util/ArrayList
      17: dup
      18: invokespecial #25                 // Method java/util/ArrayList."<init>":()V
      21: checkcast     #27                 // class java/util/List
      24: astore_2
      25: iconst_1
      26: istore_3
      27: aload_0
      28: invokeinterface #31,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      33: astore        4
      35: aload         4
      37: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          111
      45: aload         4
      47: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: checkcast     #43                 // class java/lang/String
      55: astore        5
      57: aload         5
      59: checkcast     #45                 // class java/lang/CharSequence
      62: invokeinterface #49,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      67: ifne          74
      70: iconst_1
      71: goto          75
      74: iconst_0
      75: ifeq          83
      78: iconst_0
      79: istore_3
      80: goto          35
      83: iload_3
      84: ifeq          96
      87: aload_1
      88: aload         5
      90: invokevirtual #53                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
      93: goto          107
      96: aload_2
      97: aload         5
      99: invokeinterface #57,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     104: invokestatic  #63                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     107: pop
     108: goto          35
     111: aload_1
     112: invokestatic  #67                 // Method buildInitialStack:(Ljava/util/Stack;)Ljava/util/Map;
     115: astore        4
     117: aload_2
     118: invokeinterface #31,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     123: astore        5
     125: aload         5
     127: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     132: ifeq          290
     135: aload         5
     137: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     142: checkcast     #43                 // class java/lang/String
     145: astore        6
     147: aload         6
     149: invokestatic  #71                 // Method parseMovement:(Ljava/lang/String;)Ljava/util/List;
     152: astore        7
     154: aload         7
     156: iconst_0
     157: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     162: checkcast     #77                 // class java/lang/Number
     165: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     168: istore        8
     170: aload         7
     172: iconst_1
     173: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     178: checkcast     #77                 // class java/lang/Number
     181: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     184: istore        9
     186: aload         7
     188: iconst_2
     189: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     194: checkcast     #77                 // class java/lang/Number
     197: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     200: istore        10
     202: iconst_0
     203: istore        11
     205: iload         11
     207: iload         8
     209: if_icmpge     125
     212: iload         11
     214: istore        12
     216: iconst_0
     217: istore        13
     219: aload         4
     221: iload         9
     223: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     226: invokeinterface #89,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     231: checkcast     #18                 // class java/util/Stack
     234: dup
     235: ifnull        247
     238: invokevirtual #92                 // Method java/util/Stack.pop:()Ljava/lang/Object;
     241: checkcast     #43                 // class java/lang/String
     244: goto          249
     247: pop
     248: aconst_null
     249: astore        14
     251: aload         4
     253: iload         10
     255: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     258: invokeinterface #89,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     263: checkcast     #18                 // class java/util/Stack
     266: dup
     267: ifnull        282
     270: aload         14
     272: invokevirtual #53                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     275: checkcast     #43                 // class java/lang/String
     278: pop
     279: goto          283
     282: pop
     283: nop
     284: iinc          11, 1
     287: goto          205
     290: new           #94                 // class kotlin/ranges/IntRange
     293: dup
     294: iconst_1
     295: aload         4
     297: invokeinterface #97,  1           // InterfaceMethod java/util/Map.size:()I
     302: invokespecial #100                // Method kotlin/ranges/IntRange."<init>":(II)V
     305: checkcast     #102                // class java/lang/Iterable
     308: astore        5
     310: nop
     311: iconst_0
     312: istore        6
     314: aload         5
     316: astore        7
     318: new           #24                 // class java/util/ArrayList
     321: dup
     322: invokespecial #25                 // Method java/util/ArrayList."<init>":()V
     325: checkcast     #104                // class java/util/Collection
     328: astore        8
     330: iconst_0
     331: istore        9
     333: aload         7
     335: astore        10
     337: iconst_0
     338: istore        11
     340: aload         10
     342: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     347: astore        12
     349: aload         12
     351: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     356: ifeq          440
     359: aload         12
     361: checkcast     #107                // class kotlin/collections/IntIterator
     364: invokevirtual #110                // Method kotlin/collections/IntIterator.nextInt:()I
     367: istore        13
     369: iload         13
     371: istore        14
     373: iconst_0
     374: istore        15
     376: iload         14
     378: istore        16
     380: iconst_0
     381: istore        17
     383: aload         4
     385: iload         16
     387: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     390: invokeinterface #89,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     395: checkcast     #18                 // class java/util/Stack
     398: dup
     399: ifnull        411
     402: invokevirtual #92                 // Method java/util/Stack.pop:()Ljava/lang/Object;
     405: checkcast     #43                 // class java/lang/String
     408: goto          413
     411: pop
     412: aconst_null
     413: dup
     414: ifnull        435
     417: astore        18
     419: iconst_0
     420: istore        19
     422: aload         8
     424: aload         18
     426: invokeinterface #111,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     431: pop
     432: goto          436
     435: pop
     436: nop
     437: goto          349
     440: nop
     441: aload         8
     443: checkcast     #27                 // class java/util/List
     446: nop
     447: checkcast     #102                // class java/lang/Iterable
     450: ldc           #113                // String
     452: checkcast     #45                 // class java/lang/CharSequence
     455: aconst_null
     456: aconst_null
     457: iconst_0
     458: aconst_null
     459: aconst_null
     460: bipush        62
     462: aconst_null
     463: invokestatic  #119                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     466: areturn

  public static final java.util.List<java.lang.Integer> parseMovement(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #154                // String movement
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #156                // class kotlin/text/Regex
       9: dup
      10: ldc           #158                // String move (\\d+) from (\\d+) to (\\d+)
      12: invokespecial #161                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: astore_1
      16: aload_1
      17: aload_0
      18: checkcast     #45                 // class java/lang/CharSequence
      21: iconst_0
      22: iconst_2
      23: aconst_null
      24: invokestatic  #165                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      27: astore_2
      28: aload_2
      29: dup
      30: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      33: invokeinterface #175,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      38: astore_3
      39: aload_3
      40: invokevirtual #181                // Method kotlin/text/MatchResult$Destructured.toList:()Ljava/util/List;
      43: checkcast     #102                // class java/lang/Iterable
      46: astore        4
      48: iconst_0
      49: istore        5
      51: aload         4
      53: astore        6
      55: new           #24                 // class java/util/ArrayList
      58: dup
      59: aload         4
      61: bipush        10
      63: invokestatic  #185                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      66: invokespecial #188                // Method java/util/ArrayList."<init>":(I)V
      69: checkcast     #104                // class java/util/Collection
      72: astore        7
      74: iconst_0
      75: istore        8
      77: aload         6
      79: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      84: astore        9
      86: aload         9
      88: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      93: ifeq          140
      96: aload         9
      98: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     103: astore        10
     105: aload         7
     107: aload         10
     109: checkcast     #43                 // class java/lang/String
     112: astore        11
     114: astore        13
     116: iconst_0
     117: istore        12
     119: aload         11
     121: invokestatic  #192                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     124: nop
     125: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     128: aload         13
     130: swap
     131: invokeinterface #111,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     136: pop
     137: goto          86
     140: aload         7
     142: checkcast     #27                 // class java/util/List
     145: nop
     146: areturn

  public static final java.util.Map<java.lang.Integer, java.util.Stack<java.lang.String>> buildInitialStack(java.util.Stack<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #206                // String stackInput
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #208                // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #209                // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #87                 // class java/util/Map
      16: astore_1
      17: aload_0
      18: invokevirtual #92                 // Method java/util/Stack.pop:()Ljava/lang/Object;
      21: dup
      22: ldc           #211                // String pop(...)
      24: invokestatic  #214                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      27: checkcast     #43                 // class java/lang/String
      30: checkcast     #45                 // class java/lang/CharSequence
      33: invokestatic  #220                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      36: invokevirtual #224                // Method java/lang/Object.toString:()Ljava/lang/String;
      39: checkcast     #45                 // class java/lang/CharSequence
      42: astore_3
      43: new           #156                // class kotlin/text/Regex
      46: dup
      47: ldc           #226                // String \\s+
      49: invokespecial #161                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      52: astore        4
      54: iconst_0
      55: istore        5
      57: aload         4
      59: aload_3
      60: iload         5
      62: invokevirtual #230                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      65: checkcast     #102                // class java/lang/Iterable
      68: astore_3
      69: nop
      70: iconst_0
      71: istore        4
      73: aload_3
      74: astore        5
      76: new           #24                 // class java/util/ArrayList
      79: dup
      80: aload_3
      81: bipush        10
      83: invokestatic  #185                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      86: invokespecial #188                // Method java/util/ArrayList."<init>":(I)V
      89: checkcast     #104                // class java/util/Collection
      92: astore        6
      94: iconst_0
      95: istore        7
      97: aload         5
      99: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     104: astore        8
     106: aload         8
     108: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     113: ifeq          160
     116: aload         8
     118: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     123: astore        9
     125: aload         6
     127: aload         9
     129: checkcast     #43                 // class java/lang/String
     132: astore        10
     134: astore        26
     136: iconst_0
     137: istore        11
     139: aload         10
     141: invokestatic  #192                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     144: nop
     145: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     148: aload         26
     150: swap
     151: invokeinterface #111,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     156: pop
     157: goto          106
     160: aload         6
     162: checkcast     #27                 // class java/util/List
     165: nop
     166: astore_2
     167: aload_2
     168: checkcast     #102                // class java/lang/Iterable
     171: astore_3
     172: nop
     173: iconst_0
     174: istore        4
     176: aload_3
     177: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     182: astore        5
     184: aload         5
     186: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     191: ifeq          244
     194: aload         5
     196: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     201: astore        6
     203: aload         6
     205: checkcast     #77                 // class java/lang/Number
     208: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     211: istore        7
     213: iconst_0
     214: istore        8
     216: iload         7
     218: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     221: astore        9
     223: aload_1
     224: aload         9
     226: new           #18                 // class java/util/Stack
     229: dup
     230: invokespecial #22                 // Method java/util/Stack."<init>":()V
     233: invokeinterface #234,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     238: pop
     239: nop
     240: nop
     241: goto          184
     244: nop
     245: aload_2
     246: checkcast     #104                // class java/util/Collection
     249: invokeinterface #235,  1          // InterfaceMethod java/util/Collection.size:()I
     254: iconst_4
     255: imul
     256: iconst_1
     257: isub
     258: istore_3
     259: aload_0
     260: checkcast     #102                // class java/lang/Iterable
     263: invokestatic  #239                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     266: invokeinterface #31,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     271: astore        4
     273: aload         4
     275: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     280: ifeq          573
     283: aload         4
     285: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     290: checkcast     #43                 // class java/lang/String
     293: astore        5
     295: aload         5
     297: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     300: aload         5
     302: iload_3
     303: iconst_0
     304: iconst_2
     305: aconst_null
     306: invokestatic  #243                // Method kotlin/text/StringsKt.padEnd$default:(Ljava/lang/String;ICILjava/lang/Object;)Ljava/lang/String;
     309: astore        6
     311: aload         6
     313: checkcast     #45                 // class java/lang/CharSequence
     316: invokestatic  #247                // Method kotlin/text/StringsKt.asSequence:(Ljava/lang/CharSequence;)Lkotlin/sequences/Sequence;
     319: iconst_3
     320: iconst_4
     321: iconst_0
     322: iconst_4
     323: aconst_null
     324: invokestatic  #253                // Method kotlin/sequences/SequencesKt.windowed$default:(Lkotlin/sequences/Sequence;IIZILjava/lang/Object;)Lkotlin/sequences/Sequence;
     327: astore        7
     329: nop
     330: iconst_0
     331: istore        8
     333: iconst_0
     334: istore        9
     336: aload         7
     338: invokeinterface #256,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     343: astore        10
     345: aload         10
     347: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     352: ifeq          569
     355: aload         10
     357: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     362: astore        11
     364: iload         9
     366: iinc          9, 1
     369: istore        12
     371: iload         12
     373: ifge          379
     376: invokestatic  #259                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     379: iload         12
     381: aload         11
     383: checkcast     #27                 // class java/util/List
     386: astore        13
     388: istore        14
     390: iconst_0
     391: istore        15
     393: aload         13
     395: checkcast     #102                // class java/lang/Iterable
     398: astore        16
     400: iconst_0
     401: istore        17
     403: aload         16
     405: astore        18
     407: new           #24                 // class java/util/ArrayList
     410: dup
     411: invokespecial #25                 // Method java/util/ArrayList."<init>":()V
     414: checkcast     #104                // class java/util/Collection
     417: astore        19
     419: iconst_0
     420: istore        20
     422: aload         18
     424: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     429: astore        21
     431: aload         21
     433: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     438: ifeq          485
     441: aload         21
     443: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     448: astore        22
     450: aload         22
     452: checkcast     #261                // class java/lang/Character
     455: invokevirtual #265                // Method java/lang/Character.charValue:()C
     458: istore        23
     460: iconst_0
     461: istore        24
     463: iload         23
     465: invokestatic  #269                // Method java/lang/Character.isLetter:(C)Z
     468: nop
     469: ifeq          431
     472: aload         19
     474: aload         22
     476: invokeinterface #111,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     481: pop
     482: goto          431
     485: aload         19
     487: checkcast     #27                 // class java/util/List
     490: nop
     491: checkcast     #102                // class java/lang/Iterable
     494: ldc           #113                // String
     496: checkcast     #45                 // class java/lang/CharSequence
     499: aconst_null
     500: aconst_null
     501: iconst_0
     502: aconst_null
     503: aconst_null
     504: bipush        62
     506: aconst_null
     507: invokestatic  #119                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     510: astore        25
     512: aload         25
     514: checkcast     #45                 // class java/lang/CharSequence
     517: invokestatic  #273                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
     520: ifne          527
     523: iconst_1
     524: goto          528
     527: iconst_0
     528: ifeq          564
     531: aload_1
     532: iload         14
     534: iconst_1
     535: iadd
     536: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     539: invokeinterface #89,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     544: checkcast     #18                 // class java/util/Stack
     547: dup
     548: ifnull        563
     551: aload         25
     553: invokevirtual #53                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     556: checkcast     #43                 // class java/lang/String
     559: pop
     560: goto          564
     563: pop
     564: nop
     565: nop
     566: goto          345
     569: nop
     570: goto          273
     573: aload_1
     574: areturn

  public static final java.lang.String solveProblem02(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/util/Stack
       9: dup
      10: invokespecial #22                 // Method java/util/Stack."<init>":()V
      13: astore_1
      14: new           #24                 // class java/util/ArrayList
      17: dup
      18: invokespecial #25                 // Method java/util/ArrayList."<init>":()V
      21: checkcast     #27                 // class java/util/List
      24: astore_2
      25: iconst_1
      26: istore_3
      27: aload_0
      28: invokeinterface #31,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      33: astore        4
      35: aload         4
      37: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          111
      45: aload         4
      47: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: checkcast     #43                 // class java/lang/String
      55: astore        5
      57: aload         5
      59: checkcast     #45                 // class java/lang/CharSequence
      62: invokeinterface #49,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      67: ifne          74
      70: iconst_1
      71: goto          75
      74: iconst_0
      75: ifeq          83
      78: iconst_0
      79: istore_3
      80: goto          35
      83: iload_3
      84: ifeq          96
      87: aload_1
      88: aload         5
      90: invokevirtual #53                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
      93: goto          107
      96: aload_2
      97: aload         5
      99: invokeinterface #57,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     104: invokestatic  #63                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     107: pop
     108: goto          35
     111: aload_1
     112: invokestatic  #67                 // Method buildInitialStack:(Ljava/util/Stack;)Ljava/util/Map;
     115: astore        4
     117: aload_2
     118: invokeinterface #31,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     123: astore        5
     125: aload         5
     127: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     132: ifeq          341
     135: aload         5
     137: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     142: checkcast     #43                 // class java/lang/String
     145: astore        6
     147: aload         6
     149: invokestatic  #71                 // Method parseMovement:(Ljava/lang/String;)Ljava/util/List;
     152: astore        7
     154: aload         7
     156: iconst_0
     157: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     162: checkcast     #77                 // class java/lang/Number
     165: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     168: istore        8
     170: aload         7
     172: iconst_1
     173: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     178: checkcast     #77                 // class java/lang/Number
     181: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     184: istore        9
     186: aload         7
     188: iconst_2
     189: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     194: checkcast     #77                 // class java/lang/Number
     197: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     200: istore        10
     202: new           #18                 // class java/util/Stack
     205: dup
     206: invokespecial #22                 // Method java/util/Stack."<init>":()V
     209: astore        11
     211: iconst_0
     212: istore        12
     214: iload         12
     216: iload         8
     218: if_icmpge     275
     221: iload         12
     223: istore        13
     225: iconst_0
     226: istore        14
     228: aload         4
     230: iload         9
     232: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     235: invokeinterface #89,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     240: checkcast     #18                 // class java/util/Stack
     243: dup
     244: ifnull        256
     247: invokevirtual #92                 // Method java/util/Stack.pop:()Ljava/lang/Object;
     250: checkcast     #43                 // class java/lang/String
     253: goto          258
     256: pop
     257: aconst_null
     258: astore        15
     260: aload         11
     262: aload         15
     264: invokevirtual #53                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     267: pop
     268: nop
     269: iinc          12, 1
     272: goto          214
     275: iconst_0
     276: istore        12
     278: iload         12
     280: iload         8
     282: if_icmpge     125
     285: iload         12
     287: istore        13
     289: iconst_0
     290: istore        14
     292: aload         11
     294: invokevirtual #92                 // Method java/util/Stack.pop:()Ljava/lang/Object;
     297: checkcast     #43                 // class java/lang/String
     300: astore        15
     302: aload         4
     304: iload         10
     306: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     309: invokeinterface #89,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     314: checkcast     #18                 // class java/util/Stack
     317: dup
     318: ifnull        333
     321: aload         15
     323: invokevirtual #53                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     326: checkcast     #43                 // class java/lang/String
     329: pop
     330: goto          334
     333: pop
     334: nop
     335: iinc          12, 1
     338: goto          278
     341: new           #94                 // class kotlin/ranges/IntRange
     344: dup
     345: iconst_1
     346: aload         4
     348: invokeinterface #97,  1           // InterfaceMethod java/util/Map.size:()I
     353: invokespecial #100                // Method kotlin/ranges/IntRange."<init>":(II)V
     356: checkcast     #102                // class java/lang/Iterable
     359: astore        5
     361: nop
     362: iconst_0
     363: istore        6
     365: aload         5
     367: astore        7
     369: new           #24                 // class java/util/ArrayList
     372: dup
     373: invokespecial #25                 // Method java/util/ArrayList."<init>":()V
     376: checkcast     #104                // class java/util/Collection
     379: astore        8
     381: iconst_0
     382: istore        9
     384: aload         7
     386: astore        10
     388: iconst_0
     389: istore        11
     391: aload         10
     393: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     398: astore        12
     400: aload         12
     402: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     407: ifeq          491
     410: aload         12
     412: checkcast     #107                // class kotlin/collections/IntIterator
     415: invokevirtual #110                // Method kotlin/collections/IntIterator.nextInt:()I
     418: istore        13
     420: iload         13
     422: istore        14
     424: iconst_0
     425: istore        15
     427: iload         14
     429: istore        16
     431: iconst_0
     432: istore        17
     434: aload         4
     436: iload         16
     438: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     441: invokeinterface #89,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     446: checkcast     #18                 // class java/util/Stack
     449: dup
     450: ifnull        462
     453: invokevirtual #92                 // Method java/util/Stack.pop:()Ljava/lang/Object;
     456: checkcast     #43                 // class java/lang/String
     459: goto          464
     462: pop
     463: aconst_null
     464: dup
     465: ifnull        486
     468: astore        18
     470: iconst_0
     471: istore        19
     473: aload         8
     475: aload         18
     477: invokeinterface #111,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     482: pop
     483: goto          487
     486: pop
     487: nop
     488: goto          400
     491: nop
     492: aload         8
     494: checkcast     #27                 // class java/util/List
     497: nop
     498: checkcast     #102                // class java/lang/Iterable
     501: ldc           #113                // String
     503: checkcast     #45                 // class java/lang/CharSequence
     506: aconst_null
     507: aconst_null
     508: iconst_0
     509: aconst_null
     510: aconst_null
     511: bipush        62
     513: aconst_null
     514: invokestatic  #119                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     517: areturn
}


package lesson8

import java.util.*

/*
* Find leaders in 2 array slices by checking if leader exists
* and using prefix occurrences sums after, on  all array slices
* */

class EquiLeader {

    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            val result = solution(intArrayOf(4, 3, 4, 4, 4, 2))
            println("result :  $result")

        }

        fun solution(A: IntArray): Int {
            if (A.size < 2)
                return 0
            val stack = Stack<Int>()
            for (i in A.indices) {
                stack.push(A[i])
            }

            for (i in A.indices) {
                when {
                    stack.isEmpty() -> stack.push(A[i])
                    stack.peek() != A[i] -> stack.pop()
                    else -> stack.push(A[i])
                }
            }

            if (stack.size == 0)
                return 0
            val candidate = stack.pop()
            var candidateOccurrences = 0
            val sumOccurrences = IntArray(A.size) {0}
            var equis = 0

            for (i in A.indices) {
                if (A[i] == candidate) {
                    candidateOccurrences++
                    if (i > 0)
                        sumOccurrences[i] = sumOccurrences[i - 1] + 1
                    else
                        sumOccurrences[i] = 1
                } else {
                    if (i > 0)
                        sumOccurrences[i] = sumOccurrences[i - 1]
                    else
                        sumOccurrences[i] = 0
                }

            }

            if (candidateOccurrences > (A.size / 2)) {
                println("we have a leader $candidate")
                for (i in A.indices) {
                    println("in index $i : ")
                    println("sum occ from start: ${sumOccurrences[i]}, occur from end: ${sumOccurrences[A.size-1] - sumOccurrences[i]}")
                    println("compared to ${i+1/2} and compared to ${(A.size -1 - i)/2 }")

                    if(sumOccurrences[i] > (i+1).toDouble() /2 && ((sumOccurrences[A.size-1] - sumOccurrences[i]) > (A.size -1 - i).toDouble()  /2 )) {
                        equis++
                        println("bingo")
                    }
                }
                return equis
            }

            return 0
        }
    }
}

Compiled from "EquiLeader.kt"
public final class lesson8.EquiLeader$Companion {
  private lesson8.EquiLeader$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void main(java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #16                 // String args
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: bipush        6
       9: newarray       int
      11: astore_3
      12: aload_3
      13: iconst_0
      14: iconst_4
      15: iastore
      16: aload_3
      17: iconst_1
      18: iconst_3
      19: iastore
      20: aload_3
      21: iconst_2
      22: iconst_4
      23: iastore
      24: aload_3
      25: iconst_3
      26: iconst_4
      27: iastore
      28: aload_3
      29: iconst_4
      30: iconst_4
      31: iastore
      32: aload_3
      33: iconst_5
      34: iconst_2
      35: iastore
      36: aload_3
      37: invokevirtual #26                 // Method solution:([I)I
      40: istore_2
      41: new           #28                 // class java/lang/StringBuilder
      44: dup
      45: invokespecial #29                 // Method java/lang/StringBuilder."<init>":()V
      48: ldc           #31                 // String result :
      50: invokevirtual #35                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      53: iload_2
      54: invokevirtual #38                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      57: invokevirtual #42                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      60: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
      63: swap
      64: invokevirtual #54                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      67: return

  public final int solution(int[]);
    Code:
       0: aload_1
       1: ldc           #59                 // String A
       3: invokestatic  #22                 // 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: new           #61                 // class java/util/Stack
      17: dup
      18: invokespecial #62                 // Method java/util/Stack."<init>":()V
      21: astore_2
      22: iconst_0
      23: istore_3
      24: aload_1
      25: arraylength
      26: istore        4
      28: iload_3
      29: iload         4
      31: if_icmpge     51
      34: aload_2
      35: aload_1
      36: iload_3
      37: iaload
      38: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokevirtual #72                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
      44: pop
      45: iinc          3, 1
      48: goto          28
      51: iconst_0
      52: istore_3
      53: aload_1
      54: arraylength
      55: istore        4
      57: iload_3
      58: iload         4
      60: if_icmpge     145
      63: nop
      64: aload_2
      65: invokevirtual #76                 // Method java/util/Stack.isEmpty:()Z
      68: ifeq          87
      71: aload_2
      72: aload_1
      73: iload_3
      74: iaload
      75: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: invokevirtual #72                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
      81: checkcast     #64                 // class java/lang/Integer
      84: goto          138
      87: aload_2
      88: invokevirtual #80                 // Method java/util/Stack.peek:()Ljava/lang/Object;
      91: checkcast     #64                 // class java/lang/Integer
      94: aload_1
      95: iload_3
      96: iaload
      97: istore        5
      99: dup
     100: ifnonnull     107
     103: pop
     104: goto          115
     107: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
     110: iload         5
     112: if_icmpeq     125
     115: aload_2
     116: invokevirtual #87                 // Method java/util/Stack.pop:()Ljava/lang/Object;
     119: checkcast     #64                 // class java/lang/Integer
     122: goto          138
     125: aload_2
     126: aload_1
     127: iload_3
     128: iaload
     129: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     132: invokevirtual #72                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     135: checkcast     #64                 // class java/lang/Integer
     138: pop
     139: iinc          3, 1
     142: goto          57
     145: aload_2
     146: invokevirtual #90                 // Method java/util/Stack.size:()I
     149: ifne          154
     152: iconst_0
     153: ireturn
     154: aload_2
     155: invokevirtual #87                 // Method java/util/Stack.pop:()Ljava/lang/Object;
     158: checkcast     #64                 // class java/lang/Integer
     161: astore_3
     162: iconst_0
     163: istore        4
     165: iconst_0
     166: istore        6
     168: aload_1
     169: arraylength
     170: istore        7
     172: iload         7
     174: newarray       int
     176: astore        8
     178: iload         6
     180: iload         7
     182: if_icmpge     201
     185: iload         6
     187: istore        9
     189: aload         8
     191: iload         9
     193: iconst_0
     194: iastore
     195: iinc          6, 1
     198: goto          178
     201: aload         8
     203: astore        5
     205: iconst_0
     206: istore        6
     208: iconst_0
     209: istore        7
     211: aload_1
     212: arraylength
     213: istore        8
     215: iload         7
     217: iload         8
     219: if_icmpge     308
     222: aload_1
     223: iload         7
     225: iaload
     226: aload_3
     227: dup
     228: ifnonnull     236
     231: pop
     232: pop
     233: goto          276
     236: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
     239: if_icmpne     276
     242: iinc          4, 1
     245: iload         7
     247: ifle          267
     250: aload         5
     252: iload         7
     254: aload         5
     256: iload         7
     258: iconst_1
     259: isub
     260: iaload
     261: iconst_1
     262: iadd
     263: iastore
     264: goto          302
     267: aload         5
     269: iload         7
     271: iconst_1
     272: iastore
     273: goto          302
     276: iload         7
     278: ifle          296
     281: aload         5
     283: iload         7
     285: aload         5
     287: iload         7
     289: iconst_1
     290: isub
     291: iaload
     292: iastore
     293: goto          302
     296: aload         5
     298: iload         7
     300: iconst_0
     301: iastore
     302: iinc          7, 1
     305: goto          215
     308: iload         4
     310: aload_1
     311: arraylength
     312: iconst_2
     313: idiv
     314: if_icmple     554
     317: new           #28                 // class java/lang/StringBuilder
     320: dup
     321: invokespecial #29                 // Method java/lang/StringBuilder."<init>":()V
     324: ldc           #92                 // String we have a leader
     326: invokevirtual #35                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     329: aload_3
     330: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     333: invokevirtual #42                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     336: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
     339: swap
     340: invokevirtual #54                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     343: iconst_0
     344: istore        7
     346: aload_1
     347: arraylength
     348: istore        8
     350: iload         7
     352: iload         8
     354: if_icmpge     551
     357: new           #28                 // class java/lang/StringBuilder
     360: dup
     361: invokespecial #29                 // Method java/lang/StringBuilder."<init>":()V
     364: ldc           #97                 // String in index
     366: invokevirtual #35                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     369: iload         7
     371: invokevirtual #38                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     374: ldc           #99                 // String  :
     376: invokevirtual #35                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     379: invokevirtual #42                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     382: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
     385: swap
     386: invokevirtual #54                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     389: new           #28                 // class java/lang/StringBuilder
     392: dup
     393: invokespecial #29                 // Method java/lang/StringBuilder."<init>":()V
     396: ldc           #101                // String sum occ from start:
     398: invokevirtual #35                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     401: aload         5
     403: iload         7
     405: iaload
     406: invokevirtual #38                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     409: ldc           #103                // String , occur from end:
     411: invokevirtual #35                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     414: aload         5
     416: aload_1
     417: arraylength
     418: iconst_1
     419: isub
     420: iaload
     421: aload         5
     423: iload         7
     425: iaload
     426: isub
     427: invokevirtual #38                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     430: invokevirtual #42                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     433: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
     436: swap
     437: invokevirtual #54                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     440: new           #28                 // class java/lang/StringBuilder
     443: dup
     444: invokespecial #29                 // Method java/lang/StringBuilder."<init>":()V
     447: ldc           #105                // String compared to
     449: invokevirtual #35                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     452: iload         7
     454: iconst_0
     455: iadd
     456: invokevirtual #38                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     459: ldc           #107                // String  and compared to
     461: invokevirtual #35                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     464: aload_1
     465: arraylength
     466: iconst_1
     467: isub
     468: iload         7
     470: isub
     471: iconst_2
     472: idiv
     473: invokevirtual #38                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     476: invokevirtual #42                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     479: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
     482: swap
     483: invokevirtual #54                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     486: aload         5
     488: iload         7
     490: iaload
     491: i2d
     492: iload         7
     494: iconst_1
     495: iadd
     496: i2d
     497: iconst_2
     498: i2d
     499: ddiv
     500: dcmpl
     501: ifle          545
     504: aload         5
     506: aload_1
     507: arraylength
     508: iconst_1
     509: isub
     510: iaload
     511: aload         5
     513: iload         7
     515: iaload
     516: isub
     517: i2d
     518: aload_1
     519: arraylength
     520: iconst_1
     521: isub
     522: iload         7
     524: isub
     525: i2d
     526: iconst_2
     527: i2d
     528: ddiv
     529: dcmpl
     530: ifle          545
     533: iinc          6, 1
     536: ldc           #109                // String bingo
     538: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
     541: swap
     542: invokevirtual #54                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     545: iinc          7, 1
     548: goto          350
     551: iload         6
     553: ireturn
     554: iconst_0
     555: ireturn

  public lesson8.EquiLeader$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #121                // Method "<init>":()V
       4: return
}

Compiled from "EquiLeader.kt"
public final class lesson8.EquiLeader {
  public static final lesson8.EquiLeader$Companion Companion;

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

  public static final void main(java.lang.String[]);
    Code:
       0: getstatic     #18                 // Field Companion:Llesson8/EquiLeader$Companion;
       3: aload_0
       4: invokevirtual #22                 // Method lesson8/EquiLeader$Companion.main:([Ljava/lang/String;)V
       7: return

  static {};
    Code:
       0: new           #20                 // class lesson8/EquiLeader$Companion
       3: dup
       4: aconst_null
       5: invokespecial #28                 // Method lesson8/EquiLeader$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #18                 // Field Companion:Llesson8/EquiLeader$Companion;
      11: return
}