fun main() = unitTest()

fun radixSort(list: List<Int>): List<Int> {
  val count = maxDigits(list)
  var sorted = stringify(list)

  for(i in 1..count) {
    sorted = bucketize(sorted, count - i).flatten()
  }

  return sorted.map { it.toInt() }
}

fun bucketize(list: List<String>, position: Int): List<List<String>> {
  return (0..9).map {
    list.filter { str -> str[position].toString() == it.toString() }
  }
}

fun stringify(list: List<Int>): List<String> {
  val length = maxDigits(list)

  return list.map {
    val prefix = "0".repeat(length - it.toString().length)

    "$prefix$it"
  }
}

fun maxDigits(list: List<Int>) = list.maxOrNull()?.toString()?.length ?: 0

fun unitTest() {
  val testCases = listOf(
    listOf(
      listOf(170, 45, 75, 90, 2, 802, 2, 66),
      listOf(2, 2, 45, 66, 75, 90, 170, 802)
    ),
    listOf(
      listOf(8902, 67832, 12, 1000, 4002),
      listOf(12, 1000, 4002, 8902, 67832)
    )
  )

  testCases.forEach {
    val originalArray = it[0]
    val expectedResult = it[1]

    val result = radixSort(originalArray)

    if (result == expectedResult) {
      println("Worked well for")
    } else {
      println("Failed on")
    }

    println(originalArray)
    println(result)
    println("--------")
  }
}

Compiled from "radix_sort.kt"
public final class Radix_sortKt {
  public static final void main();
    Code:
       0: invokestatic  #9                  // Method unitTest:()V
       3: return

  public static final java.util.List<java.lang.Integer> radixSort(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #15                 // String list
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #25                 // Method maxDigits:(Ljava/util/List;)I
      10: istore_1
      11: aload_0
      12: invokestatic  #28                 // Method stringify:(Ljava/util/List;)Ljava/util/List;
      15: astore_2
      16: iconst_1
      17: istore_3
      18: iload_3
      19: iload_1
      20: if_icmpgt     48
      23: aload_2
      24: iload_1
      25: iload_3
      26: isub
      27: invokestatic  #32                 // Method bucketize:(Ljava/util/List;I)Ljava/util/List;
      30: checkcast     #34                 // class java/lang/Iterable
      33: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
      36: astore_2
      37: iload_3
      38: iload_1
      39: if_icmpeq     48
      42: iinc          3, 1
      45: goto          23
      48: aload_2
      49: checkcast     #34                 // class java/lang/Iterable
      52: astore_3
      53: iconst_0
      54: istore        4
      56: aload_3
      57: astore        5
      59: new           #42                 // class java/util/ArrayList
      62: dup
      63: aload_3
      64: bipush        10
      66: invokestatic  #46                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      69: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
      72: checkcast     #52                 // class java/util/Collection
      75: astore        6
      77: iconst_0
      78: istore        7
      80: aload         5
      82: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      87: astore        8
      89: aload         8
      91: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      96: ifeq          143
      99: aload         8
     101: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     106: astore        9
     108: aload         6
     110: aload         9
     112: checkcast     #68                 // class java/lang/String
     115: astore        10
     117: astore        12
     119: iconst_0
     120: istore        11
     122: aload         10
     124: invokestatic  #74                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     127: nop
     128: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     131: aload         12
     133: swap
     134: invokeinterface #82,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     139: pop
     140: goto          89
     143: aload         6
     145: checkcast     #84                 // class java/util/List
     148: nop
     149: areturn

  public static final java.util.List<java.util.List<java.lang.String>> bucketize(java.util.List<java.lang.String>, int);
    Code:
       0: aload_0
       1: ldc           #15                 // String list
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #104                // class kotlin/ranges/IntRange
       9: dup
      10: iconst_0
      11: bipush        9
      13: invokespecial #107                // Method kotlin/ranges/IntRange."<init>":(II)V
      16: checkcast     #34                 // class java/lang/Iterable
      19: astore_2
      20: iconst_0
      21: istore_3
      22: aload_2
      23: astore        4
      25: new           #42                 // class java/util/ArrayList
      28: dup
      29: aload_2
      30: bipush        10
      32: invokestatic  #46                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      35: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
      38: checkcast     #52                 // class java/util/Collection
      41: astore        5
      43: iconst_0
      44: istore        6
      46: aload         4
      48: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        7
      55: aload         7
      57: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          204
      65: aload         7
      67: checkcast     #109                // class kotlin/collections/IntIterator
      70: invokevirtual #113                // Method kotlin/collections/IntIterator.nextInt:()I
      73: istore        8
      75: aload         5
      77: iload         8
      79: istore        9
      81: astore        20
      83: iconst_0
      84: istore        10
      86: aload_0
      87: checkcast     #34                 // class java/lang/Iterable
      90: astore        11
      92: iconst_0
      93: istore        12
      95: aload         11
      97: astore        13
      99: new           #42                 // class java/util/ArrayList
     102: dup
     103: invokespecial #115                // Method java/util/ArrayList."<init>":()V
     106: checkcast     #52                 // class java/util/Collection
     109: astore        14
     111: iconst_0
     112: istore        15
     114: aload         13
     116: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     121: astore        16
     123: aload         16
     125: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     130: ifeq          185
     133: aload         16
     135: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     140: astore        17
     142: aload         17
     144: checkcast     #68                 // class java/lang/String
     147: astore        18
     149: iconst_0
     150: istore        19
     152: aload         18
     154: iload_1
     155: invokevirtual #119                // Method java/lang/String.charAt:(I)C
     158: invokestatic  #122                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     161: iload         9
     163: invokestatic  #125                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
     166: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     169: ifeq          123
     172: aload         14
     174: aload         17
     176: invokeinterface #82,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     181: pop
     182: goto          123
     185: aload         14
     187: checkcast     #84                 // class java/util/List
     190: nop
     191: nop
     192: aload         20
     194: swap
     195: invokeinterface #82,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     200: pop
     201: goto          55
     204: aload         5
     206: checkcast     #84                 // class java/util/List
     209: nop
     210: areturn

  public static final java.util.List<java.lang.String> stringify(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #15                 // String list
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #25                 // Method maxDigits:(Ljava/util/List;)I
      10: istore_1
      11: aload_0
      12: checkcast     #34                 // class java/lang/Iterable
      15: astore_2
      16: iconst_0
      17: istore_3
      18: aload_2
      19: astore        4
      21: new           #42                 // class java/util/ArrayList
      24: dup
      25: aload_2
      26: bipush        10
      28: invokestatic  #46                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      31: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
      34: checkcast     #52                 // class java/util/Collection
      37: astore        5
      39: iconst_0
      40: istore        6
      42: aload         4
      44: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      49: astore        7
      51: aload         7
      53: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifeq          139
      61: aload         7
      63: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      68: astore        8
      70: aload         5
      72: aload         8
      74: checkcast     #141                // class java/lang/Number
      77: invokevirtual #144                // Method java/lang/Number.intValue:()I
      80: istore        9
      82: astore        12
      84: iconst_0
      85: istore        10
      87: ldc           #146                // String 0
      89: checkcast     #148                // class java/lang/CharSequence
      92: iload_1
      93: iload         9
      95: invokestatic  #125                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      98: invokevirtual #151                // Method java/lang/String.length:()I
     101: isub
     102: invokestatic  #157                // Method kotlin/text/StringsKt.repeat:(Ljava/lang/CharSequence;I)Ljava/lang/String;
     105: astore        11
     107: new           #159                // class java/lang/StringBuilder
     110: dup
     111: invokespecial #160                // Method java/lang/StringBuilder."<init>":()V
     114: aload         11
     116: invokevirtual #164                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     119: iload         9
     121: invokevirtual #167                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     124: invokevirtual #171                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     127: aload         12
     129: swap
     130: invokeinterface #82,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     135: pop
     136: goto          51
     139: aload         5
     141: checkcast     #84                 // class java/util/List
     144: nop
     145: areturn

  public static final int maxDigits(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #15                 // String list
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #34                 // class java/lang/Iterable
      10: invokestatic  #178                // Method kotlin/collections/CollectionsKt.maxOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
      13: checkcast     #70                 // class java/lang/Integer
      16: dup
      17: ifnull        33
      20: invokevirtual #179                // Method java/lang/Integer.toString:()Ljava/lang/String;
      23: dup
      24: ifnull        33
      27: invokevirtual #151                // Method java/lang/String.length:()I
      30: goto          35
      33: pop
      34: iconst_0
      35: ireturn

  public static final void unitTest();
    Code:
       0: iconst_2
       1: anewarray     #84                 // class java/util/List
       4: astore_1
       5: aload_1
       6: iconst_0
       7: iconst_2
       8: anewarray     #84                 // class java/util/List
      11: astore_2
      12: aload_2
      13: iconst_0
      14: bipush        8
      16: anewarray     #70                 // class java/lang/Integer
      19: astore_3
      20: aload_3
      21: iconst_0
      22: sipush        170
      25: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: aastore
      29: aload_3
      30: iconst_1
      31: bipush        45
      33: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      36: aastore
      37: aload_3
      38: iconst_2
      39: bipush        75
      41: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      44: aastore
      45: aload_3
      46: iconst_3
      47: bipush        90
      49: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      52: aastore
      53: aload_3
      54: iconst_4
      55: iconst_2
      56: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: aastore
      60: aload_3
      61: iconst_5
      62: sipush        802
      65: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      68: aastore
      69: aload_3
      70: bipush        6
      72: iconst_2
      73: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      76: aastore
      77: aload_3
      78: bipush        7
      80: bipush        66
      82: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      85: aastore
      86: aload_3
      87: invokestatic  #183                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      90: aastore
      91: aload_2
      92: iconst_1
      93: bipush        8
      95: anewarray     #70                 // class java/lang/Integer
      98: astore_3
      99: aload_3
     100: iconst_0
     101: iconst_2
     102: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: aastore
     106: aload_3
     107: iconst_1
     108: iconst_2
     109: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: aastore
     113: aload_3
     114: iconst_2
     115: bipush        45
     117: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     120: aastore
     121: aload_3
     122: iconst_3
     123: bipush        66
     125: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     128: aastore
     129: aload_3
     130: iconst_4
     131: bipush        75
     133: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     136: aastore
     137: aload_3
     138: iconst_5
     139: bipush        90
     141: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     144: aastore
     145: aload_3
     146: bipush        6
     148: sipush        170
     151: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: aastore
     155: aload_3
     156: bipush        7
     158: sipush        802
     161: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     164: aastore
     165: aload_3
     166: invokestatic  #183                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     169: aastore
     170: aload_2
     171: invokestatic  #183                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     174: aastore
     175: aload_1
     176: iconst_1
     177: iconst_2
     178: anewarray     #84                 // class java/util/List
     181: astore_2
     182: aload_2
     183: iconst_0
     184: iconst_5
     185: anewarray     #70                 // class java/lang/Integer
     188: astore_3
     189: aload_3
     190: iconst_0
     191: sipush        8902
     194: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     197: aastore
     198: aload_3
     199: iconst_1
     200: ldc           #184                // int 67832
     202: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     205: aastore
     206: aload_3
     207: iconst_2
     208: bipush        12
     210: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     213: aastore
     214: aload_3
     215: iconst_3
     216: sipush        1000
     219: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     222: aastore
     223: aload_3
     224: iconst_4
     225: sipush        4002
     228: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     231: aastore
     232: aload_3
     233: invokestatic  #183                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     236: aastore
     237: aload_2
     238: iconst_1
     239: iconst_5
     240: anewarray     #70                 // class java/lang/Integer
     243: astore_3
     244: aload_3
     245: iconst_0
     246: bipush        12
     248: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     251: aastore
     252: aload_3
     253: iconst_1
     254: sipush        1000
     257: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     260: aastore
     261: aload_3
     262: iconst_2
     263: sipush        4002
     266: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     269: aastore
     270: aload_3
     271: iconst_3
     272: sipush        8902
     275: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     278: aastore
     279: aload_3
     280: iconst_4
     281: ldc           #184                // int 67832
     283: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     286: aastore
     287: aload_3
     288: invokestatic  #183                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     291: aastore
     292: aload_2
     293: invokestatic  #183                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     296: aastore
     297: aload_1
     298: invokestatic  #183                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     301: astore_0
     302: aload_0
     303: checkcast     #34                 // class java/lang/Iterable
     306: astore_1
     307: iconst_0
     308: istore_2
     309: aload_1
     310: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     315: astore_3
     316: aload_3
     317: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     322: ifeq          437
     325: aload_3
     326: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     331: astore        4
     333: aload         4
     335: checkcast     #84                 // class java/util/List
     338: astore        5
     340: iconst_0
     341: istore        6
     343: aload         5
     345: iconst_0
     346: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     351: checkcast     #84                 // class java/util/List
     354: astore        7
     356: aload         5
     358: iconst_1
     359: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     364: checkcast     #84                 // class java/util/List
     367: astore        8
     369: aload         7
     371: invokestatic  #190                // Method radixSort:(Ljava/util/List;)Ljava/util/List;
     374: astore        9
     376: aload         9
     378: aload         8
     380: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     383: ifeq          398
     386: ldc           #192                // String Worked well for
     388: getstatic     #198                // Field java/lang/System.out:Ljava/io/PrintStream;
     391: swap
     392: invokevirtual #204                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     395: goto          407
     398: ldc           #206                // String Failed on
     400: getstatic     #198                // Field java/lang/System.out:Ljava/io/PrintStream;
     403: swap
     404: invokevirtual #204                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     407: getstatic     #198                // Field java/lang/System.out:Ljava/io/PrintStream;
     410: aload         7
     412: invokevirtual #204                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     415: getstatic     #198                // Field java/lang/System.out:Ljava/io/PrintStream;
     418: aload         9
     420: invokevirtual #204                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     423: ldc           #208                // String --------
     425: getstatic     #198                // Field java/lang/System.out:Ljava/io/PrintStream;
     428: swap
     429: invokevirtual #204                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     432: nop
     433: nop
     434: goto          316
     437: nop
     438: return

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


import kotlin.math.abs
import kotlin.math.ceil
import kotlin.math.sqrt

fun findNearestSquareRoot(num: Int): Int {

    val nearestRoot = ceil(sqrt(num.toDouble())).toInt()

    return if (nearestRoot % 2 == 0) {
        nearestRoot + 1
    } else {
        nearestRoot
    }

}

fun main(args: Array<String>) {

    val input = 325489

    val nearestRoot = findNearestSquareRoot(input)
    val rightBottom = nearestRoot * nearestRoot
    val leftBottom = rightBottom - nearestRoot + 1
    val leftTop = leftBottom - nearestRoot + 1
    val rightTop = leftTop - nearestRoot + 1
    val rightLowest = rightTop - nearestRoot + 2

    val horizontalPos = when (input) {
        in leftTop..leftBottom -> leftTop
        in rightLowest..rightTop -> rightBottom
        else -> input
    }

    val horizontal = if (horizontalPos >= leftBottom) {

        val midVal = leftBottom + (nearestRoot / 2.0).toInt()
        abs(horizontalPos - midVal)

    } else {

        val midVal = rightTop + (nearestRoot / 2.0).toInt()
        abs(horizontalPos - midVal)

    }

    val verticalPosition = when (input) {
        in leftBottom..rightBottom -> leftBottom
        in leftTop..rightTop -> leftTop
        else -> input
    }

    val vertical = if (verticalPosition < leftTop) {

        val midVal = rightTop - (nearestRoot / 2.0).toInt()
        abs(verticalPosition - midVal)

    } else {

        val midVal = leftTop + (nearestRoot / 2.0).toInt()
        abs(verticalPosition - midVal)

    }

    println(horizontal + vertical)

}

Compiled from "spiral_memory.kt"
public final class Spiral_memoryKt {
  public static final int findNearestSquareRoot(int);
    Code:
       0: iload_0
       1: i2d
       2: invokestatic  #12                 // Method java/lang/Math.sqrt:(D)D
       5: invokestatic  #15                 // Method java/lang/Math.ceil:(D)D
       8: d2i
       9: istore_1
      10: iload_1
      11: iconst_2
      12: irem
      13: ifne          22
      16: iload_1
      17: iconst_1
      18: iadd
      19: goto          23
      22: iload_1
      23: ireturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #23                 // String args
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #30                 // int 325489
       8: istore_1
       9: iload_1
      10: invokestatic  #32                 // Method findNearestSquareRoot:(I)I
      13: istore_2
      14: iload_2
      15: iload_2
      16: imul
      17: istore_3
      18: iload_3
      19: iload_2
      20: isub
      21: iconst_1
      22: iadd
      23: istore        4
      25: iload         4
      27: iload_2
      28: isub
      29: iconst_1
      30: iadd
      31: istore        5
      33: iload         5
      35: iload_2
      36: isub
      37: iconst_1
      38: iadd
      39: istore        6
      41: iload         6
      43: iload_2
      44: isub
      45: iconst_2
      46: iadd
      47: istore        7
      49: iload_1
      50: istore        9
      52: iload         5
      54: iload         9
      56: if_icmpgt     74
      59: iload         9
      61: iload         4
      63: if_icmpgt     70
      66: iconst_1
      67: goto          75
      70: iconst_0
      71: goto          75
      74: iconst_0
      75: ifeq          83
      78: iload         5
      80: goto          114
      83: iload         7
      85: iload         9
      87: if_icmpgt     105
      90: iload         9
      92: iload         6
      94: if_icmpgt     101
      97: iconst_1
      98: goto          106
     101: iconst_0
     102: goto          106
     105: iconst_0
     106: ifeq          113
     109: iload_3
     110: goto          114
     113: iload_1
     114: istore        8
     116: iload         8
     118: iload         4
     120: if_icmplt     146
     123: iload         4
     125: iload_2
     126: i2d
     127: ldc2_w        #33                 // double 2.0d
     130: ddiv
     131: d2i
     132: iadd
     133: istore        10
     135: iload         8
     137: iload         10
     139: isub
     140: invokestatic  #37                 // Method java/lang/Math.abs:(I)I
     143: goto          166
     146: iload         6
     148: iload_2
     149: i2d
     150: ldc2_w        #33                 // double 2.0d
     153: ddiv
     154: d2i
     155: iadd
     156: istore        10
     158: iload         8
     160: iload         10
     162: isub
     163: invokestatic  #37                 // Method java/lang/Math.abs:(I)I
     166: istore        9
     168: iload_1
     169: istore        11
     171: iload         4
     173: iload         11
     175: if_icmpgt     192
     178: iload         11
     180: iload_3
     181: if_icmpgt     188
     184: iconst_1
     185: goto          193
     188: iconst_0
     189: goto          193
     192: iconst_0
     193: ifeq          201
     196: iload         4
     198: goto          233
     201: iload         5
     203: iload         11
     205: if_icmpgt     223
     208: iload         11
     210: iload         6
     212: if_icmpgt     219
     215: iconst_1
     216: goto          224
     219: iconst_0
     220: goto          224
     223: iconst_0
     224: ifeq          232
     227: iload         5
     229: goto          233
     232: iload_1
     233: istore        10
     235: iload         10
     237: iload         5
     239: if_icmpge     265
     242: iload         6
     244: iload_2
     245: i2d
     246: ldc2_w        #33                 // double 2.0d
     249: ddiv
     250: d2i
     251: isub
     252: istore        12
     254: iload         10
     256: iload         12
     258: isub
     259: invokestatic  #37                 // Method java/lang/Math.abs:(I)I
     262: goto          285
     265: iload         5
     267: iload_2
     268: i2d
     269: ldc2_w        #33                 // double 2.0d
     272: ddiv
     273: d2i
     274: iadd
     275: istore        12
     277: iload         10
     279: iload         12
     281: isub
     282: invokestatic  #37                 // Method java/lang/Math.abs:(I)I
     285: istore        11
     287: iload         9
     289: iload         11
     291: iadd
     292: istore        12
     294: getstatic     #43                 // Field java/lang/System.out:Ljava/io/PrintStream;
     297: iload         12
     299: invokevirtual #49                 // Method java/io/PrintStream.println:(I)V
     302: return
}


// Solves both first and second problem

fun redistribute(banks: MutableList<Int>) {

    val max = banks.max()!!
    var index = banks.indexOf(max)
    var blocksToAlloc = max

    banks[index] = 0

    while (blocksToAlloc > 0) {

        ++index

        if (index >= banks.size) {
            index = 0
        }

        ++banks[index]
        --blocksToAlloc

    }

}

fun main(args: Array<String>) {

    val input = "5 1 10 0 1 7 13 14 3 12 8 10 7 12 0 6"

    val banks = input.split(" ").map { it.toInt() }.toMutableList()

    val occuredCombinations = mutableListOf<String>()
    var combination: String

    while (true) {
        redistribute(banks)
        combination = banks.fold("") { acc: String, i: Int -> "$acc$i " }

        if (occuredCombinations.find {it == combination} != null) {
            break
        }

        occuredCombinations.add(combination)

    }

    val loopSize = (occuredCombinations.size) - occuredCombinations.indexOf(combination)

    println("Number of combinations: ${occuredCombinations.size + 1}")
    println("Loop size: $loopSize")

}

Compiled from "memory_banks.kt"
public final class Memory_banksKt {
  public static final void redistribute(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #10                 // String banks
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.maxOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
      13: dup
      14: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      17: checkcast     #30                 // class java/lang/Number
      20: invokevirtual #34                 // Method java/lang/Number.intValue:()I
      23: istore_1
      24: aload_0
      25: iload_1
      26: invokestatic  #40                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: invokeinterface #46,  2           // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
      34: istore_2
      35: iload_1
      36: istore_3
      37: aload_0
      38: iload_2
      39: iconst_0
      40: invokestatic  #40                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      43: invokeinterface #50,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      48: pop
      49: iload_3
      50: ifle          114
      53: iinc          2, 1
      56: iload_2
      57: aload_0
      58: invokeinterface #53,  1           // InterfaceMethod java/util/List.size:()I
      63: if_icmplt     68
      66: iconst_0
      67: istore_2
      68: iload_2
      69: istore        4
      71: aload_0
      72: iload         4
      74: aload_0
      75: iload         4
      77: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      82: checkcast     #30                 // class java/lang/Number
      85: invokevirtual #34                 // Method java/lang/Number.intValue:()I
      88: iconst_1
      89: iadd
      90: invokestatic  #40                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      93: invokeinterface #50,  3           // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      98: pop
      99: aload_0
     100: iload         4
     102: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     107: pop
     108: iinc          3, -1
     111: goto          49
     114: return

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #66                 // String args
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #68                 // String 5 1 10 0 1 7 13 14 3 12 8 10 7 12 0 6
       8: astore_1
       9: aload_1
      10: checkcast     #70                 // class java/lang/CharSequence
      13: iconst_1
      14: anewarray     #72                 // class java/lang/String
      17: astore_3
      18: aload_3
      19: iconst_0
      20: ldc           #74                 // String
      22: aastore
      23: aload_3
      24: iconst_0
      25: iconst_0
      26: bipush        6
      28: aconst_null
      29: invokestatic  #80                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      32: checkcast     #18                 // class java/lang/Iterable
      35: astore_3
      36: iconst_0
      37: istore        4
      39: aload_3
      40: astore        5
      42: new           #82                 // class java/util/ArrayList
      45: dup
      46: aload_3
      47: bipush        10
      49: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      52: invokespecial #90                 // Method java/util/ArrayList."<init>":(I)V
      55: checkcast     #92                 // class java/util/Collection
      58: astore        6
      60: iconst_0
      61: istore        7
      63: aload         5
      65: invokeinterface #96,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      70: astore        8
      72: aload         8
      74: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      79: ifeq          126
      82: aload         8
      84: invokeinterface #106,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      89: astore        9
      91: aload         6
      93: aload         9
      95: checkcast     #72                 // class java/lang/String
      98: astore        10
     100: astore        14
     102: iconst_0
     103: istore        11
     105: aload         10
     107: invokestatic  #110                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     110: nop
     111: invokestatic  #40                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: aload         14
     116: swap
     117: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     122: pop
     123: goto          72
     126: aload         6
     128: checkcast     #42                 // class java/util/List
     131: nop
     132: checkcast     #92                 // class java/util/Collection
     135: invokestatic  #118                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     138: astore_2
     139: new           #82                 // class java/util/ArrayList
     142: dup
     143: invokespecial #121                // Method java/util/ArrayList."<init>":()V
     146: checkcast     #42                 // class java/util/List
     149: astore_3
     150: aconst_null
     151: astore        4
     153: nop
     154: aload_2
     155: invokestatic  #123                // Method redistribute:(Ljava/util/List;)V
     158: aload_2
     159: checkcast     #18                 // class java/lang/Iterable
     162: astore        5
     164: ldc           #125                // String
     166: astore        6
     168: iconst_0
     169: istore        7
     171: aload         6
     173: astore        8
     175: aload         5
     177: invokeinterface #96,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     182: astore        9
     184: aload         9
     186: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     191: ifeq          250
     194: aload         9
     196: invokeinterface #106,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     201: astore        10
     203: aload         8
     205: aload         10
     207: checkcast     #30                 // class java/lang/Number
     210: invokevirtual #34                 // Method java/lang/Number.intValue:()I
     213: istore        11
     215: astore        12
     217: iconst_0
     218: istore        13
     220: new           #127                // class java/lang/StringBuilder
     223: dup
     224: invokespecial #128                // Method java/lang/StringBuilder."<init>":()V
     227: aload         12
     229: invokevirtual #132                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     232: iload         11
     234: invokevirtual #135                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     237: bipush        32
     239: invokevirtual #138                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     242: invokevirtual #142                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     245: astore        8
     247: goto          184
     250: aload         8
     252: astore        4
     254: aload_3
     255: checkcast     #18                 // class java/lang/Iterable
     258: astore        6
     260: aload         6
     262: invokeinterface #96,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     267: astore        7
     269: aload         7
     271: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     276: ifeq          313
     279: aload         7
     281: invokeinterface #106,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     286: astore        8
     288: aload         8
     290: checkcast     #72                 // class java/lang/String
     293: astore        9
     295: iconst_0
     296: istore        10
     298: aload         9
     300: aload         4
     302: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     305: ifeq          269
     308: aload         8
     310: goto          314
     313: aconst_null
     314: ifnull        320
     317: goto          332
     320: aload_3
     321: aload         4
     323: invokeinterface #147,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     328: pop
     329: goto          153
     332: aload_3
     333: invokeinterface #53,  1           // InterfaceMethod java/util/List.size:()I
     338: aload_3
     339: aload         4
     341: invokeinterface #46,  2           // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     346: isub
     347: istore        5
     349: new           #127                // class java/lang/StringBuilder
     352: dup
     353: invokespecial #128                // Method java/lang/StringBuilder."<init>":()V
     356: ldc           #149                // String Number of combinations:
     358: invokevirtual #132                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     361: aload_3
     362: invokeinterface #53,  1           // InterfaceMethod java/util/List.size:()I
     367: iconst_1
     368: iadd
     369: invokevirtual #135                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     372: invokevirtual #142                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     375: getstatic     #155                // Field java/lang/System.out:Ljava/io/PrintStream;
     378: swap
     379: invokevirtual #160                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     382: new           #127                // class java/lang/StringBuilder
     385: dup
     386: invokespecial #128                // Method java/lang/StringBuilder."<init>":()V
     389: ldc           #162                // String Loop size:
     391: invokevirtual #132                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     394: iload         5
     396: invokevirtual #135                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     399: invokevirtual #142                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     402: getstatic     #155                // Field java/lang/System.out:Ljava/io/PrintStream;
     405: swap
     406: invokevirtual #160                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     409: return
}


fun parseGrammar(grammar: List<Pair<String, String>>) = getFirsts(grammar)

fun getFirsts(grammar: List<Pair<String, String>>): Map<String, List<String>> =
        grammar.groupBy { it.first }
                .mapValues { it.value.map { it.second } }
                .mapValues {
                    it.value.map {
                        getFirsts(grammar.groupBy { it.first }.mapValues { it.value.map { it.second } }, it)
                    }.flatten()
                }

fun getFollows(grammar: List<Pair<String, String>>, firsts: Map<String, List<String>>) {

}

private fun getFirsts(mapByRules: Map<String, List<String>>, it: String): Collection<String> {
    return when {
        !mapByRules.containsKey(it.substringBefore(" ")) -> setOf(it.substringBefore(" "))
        else -> mapByRules
                .filterKeys { key -> key == it }
                .values
                .flatten()
                .map {
                    when {
                        !mapByRules.containsKey(it.substringBefore(" ")) -> listOf(it)
                        else -> getFirsts(mapByRules, it)
                    }
                }.flatten()
    }
}

Compiled from "Parser.kt"
public final class ParserKt {
  public static final java.util.Map<java.lang.String, java.util.List<java.lang.String>> parseGrammar(java.util.List<kotlin.Pair<java.lang.String, java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #10                 // String grammar
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #19                 // Method getFirsts:(Ljava/util/List;)Ljava/util/Map;
      10: areturn

  public static final java.util.Map<java.lang.String, java.util.List<java.lang.String>> getFirsts(java.util.List<kotlin.Pair<java.lang.String, java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #10                 // String grammar
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #22                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #24                 // class java/util/LinkedHashMap
      18: dup
      19: invokespecial #28                 // Method java/util/LinkedHashMap."<init>":()V
      22: checkcast     #30                 // class java/util/Map
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          153
      48: aload         6
      50: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         7
      59: checkcast     #46                 // class kotlin/Pair
      62: astore        8
      64: iconst_0
      65: istore        9
      67: aload         8
      69: invokevirtual #49                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      72: checkcast     #51                 // class java/lang/String
      75: astore        10
      77: aload         4
      79: astore        11
      81: iconst_0
      82: istore        12
      84: aload         11
      86: aload         10
      88: invokeinterface #55,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      93: astore        13
      95: aload         13
      97: ifnonnull     132
     100: iconst_0
     101: istore        14
     103: new           #57                 // class java/util/ArrayList
     106: dup
     107: invokespecial #58                 // Method java/util/ArrayList."<init>":()V
     110: checkcast     #60                 // class java/util/List
     113: astore        14
     115: aload         11
     117: aload         10
     119: aload         14
     121: invokeinterface #64,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     126: pop
     127: aload         14
     129: goto          134
     132: aload         13
     134: nop
     135: checkcast     #60                 // class java/util/List
     138: astore        8
     140: aload         8
     142: aload         7
     144: invokeinterface #68,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     149: pop
     150: goto          38
     153: aload         4
     155: nop
     156: astore_1
     157: nop
     158: iconst_0
     159: istore_2
     160: aload_1
     161: astore_3
     162: new           #24                 // class java/util/LinkedHashMap
     165: dup
     166: aload_1
     167: invokeinterface #72,  1           // InterfaceMethod java/util/Map.size:()I
     172: invokestatic  #78                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     175: invokespecial #81                 // Method java/util/LinkedHashMap."<init>":(I)V
     178: checkcast     #30                 // class java/util/Map
     181: astore        4
     183: iconst_0
     184: istore        5
     186: aload_3
     187: invokeinterface #85,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     192: checkcast     #22                 // class java/lang/Iterable
     195: astore        6
     197: iconst_0
     198: istore        7
     200: aload         6
     202: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     207: astore        8
     209: aload         8
     211: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     216: ifeq          393
     219: aload         8
     221: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     226: astore        9
     228: aload         4
     230: aload         9
     232: checkcast     #87                 // class java/util/Map$Entry
     235: astore        10
     237: astore        11
     239: iconst_0
     240: istore        12
     242: aload         10
     244: invokeinterface #90,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     249: aload         11
     251: swap
     252: aload         9
     254: checkcast     #87                 // class java/util/Map$Entry
     257: astore        13
     259: astore        53
     261: astore        52
     263: iconst_0
     264: istore        14
     266: aload         13
     268: invokeinterface #93,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     273: checkcast     #22                 // class java/lang/Iterable
     276: astore        15
     278: iconst_0
     279: istore        16
     281: aload         15
     283: astore        17
     285: new           #57                 // class java/util/ArrayList
     288: dup
     289: aload         15
     291: bipush        10
     293: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     296: invokespecial #100                // Method java/util/ArrayList."<init>":(I)V
     299: checkcast     #102                // class java/util/Collection
     302: astore        18
     304: iconst_0
     305: istore        19
     307: aload         17
     309: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     314: astore        20
     316: aload         20
     318: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     323: ifeq          369
     326: aload         20
     328: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     333: astore        21
     335: aload         18
     337: aload         21
     339: checkcast     #46                 // class kotlin/Pair
     342: astore        22
     344: astore        23
     346: iconst_0
     347: istore        24
     349: aload         22
     351: invokevirtual #105                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     354: checkcast     #51                 // class java/lang/String
     357: aload         23
     359: swap
     360: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     365: pop
     366: goto          316
     369: aload         18
     371: checkcast     #60                 // class java/util/List
     374: nop
     375: nop
     376: astore        54
     378: aload         52
     380: aload         53
     382: aload         54
     384: invokeinterface #64,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     389: pop
     390: goto          209
     393: aload         4
     395: nop
     396: nop
     397: astore_1
     398: nop
     399: iconst_0
     400: istore_2
     401: aload_1
     402: astore_3
     403: new           #24                 // class java/util/LinkedHashMap
     406: dup
     407: aload_1
     408: invokeinterface #72,  1           // InterfaceMethod java/util/Map.size:()I
     413: invokestatic  #78                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     416: invokespecial #81                 // Method java/util/LinkedHashMap."<init>":(I)V
     419: checkcast     #30                 // class java/util/Map
     422: astore        4
     424: iconst_0
     425: istore        5
     427: aload_3
     428: invokeinterface #85,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     433: checkcast     #22                 // class java/lang/Iterable
     436: astore        6
     438: iconst_0
     439: istore        7
     441: aload         6
     443: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     448: astore        8
     450: aload         8
     452: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     457: ifeq          1038
     460: aload         8
     462: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     467: astore        9
     469: aload         4
     471: aload         9
     473: checkcast     #87                 // class java/util/Map$Entry
     476: astore        10
     478: astore        11
     480: iconst_0
     481: istore        12
     483: aload         10
     485: invokeinterface #90,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     490: aload         11
     492: swap
     493: aload         9
     495: checkcast     #87                 // class java/util/Map$Entry
     498: astore        13
     500: astore        53
     502: astore        52
     504: iconst_0
     505: istore        14
     507: aload         13
     509: invokeinterface #93,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     514: checkcast     #22                 // class java/lang/Iterable
     517: astore        15
     519: iconst_0
     520: istore        16
     522: aload         15
     524: astore        17
     526: new           #57                 // class java/util/ArrayList
     529: dup
     530: aload         15
     532: bipush        10
     534: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     537: invokespecial #100                // Method java/util/ArrayList."<init>":(I)V
     540: checkcast     #102                // class java/util/Collection
     543: astore        18
     545: iconst_0
     546: istore        19
     548: aload         17
     550: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     555: astore        20
     557: aload         20
     559: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     564: ifeq          1009
     567: aload         20
     569: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     574: astore        21
     576: aload         18
     578: aload         21
     580: checkcast     #51                 // class java/lang/String
     583: astore        22
     585: astore        23
     587: iconst_0
     588: istore        24
     590: aload_0
     591: checkcast     #22                 // class java/lang/Iterable
     594: astore        25
     596: iconst_0
     597: istore        26
     599: aload         25
     601: astore        27
     603: new           #24                 // class java/util/LinkedHashMap
     606: dup
     607: invokespecial #28                 // Method java/util/LinkedHashMap."<init>":()V
     610: checkcast     #30                 // class java/util/Map
     613: astore        28
     615: iconst_0
     616: istore        29
     618: aload         27
     620: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     625: astore        30
     627: aload         30
     629: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     634: ifeq          742
     637: aload         30
     639: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     644: astore        31
     646: aload         31
     648: checkcast     #46                 // class kotlin/Pair
     651: astore        32
     653: iconst_0
     654: istore        33
     656: aload         32
     658: invokevirtual #49                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     661: checkcast     #51                 // class java/lang/String
     664: astore        34
     666: aload         28
     668: astore        35
     670: iconst_0
     671: istore        36
     673: aload         35
     675: aload         34
     677: invokeinterface #55,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     682: astore        37
     684: aload         37
     686: ifnonnull     721
     689: iconst_0
     690: istore        38
     692: new           #57                 // class java/util/ArrayList
     695: dup
     696: invokespecial #58                 // Method java/util/ArrayList."<init>":()V
     699: checkcast     #60                 // class java/util/List
     702: astore        38
     704: aload         35
     706: aload         34
     708: aload         38
     710: invokeinterface #64,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     715: pop
     716: aload         38
     718: goto          723
     721: aload         37
     723: nop
     724: checkcast     #60                 // class java/util/List
     727: astore        32
     729: aload         32
     731: aload         31
     733: invokeinterface #68,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     738: pop
     739: goto          627
     742: aload         28
     744: nop
     745: astore        25
     747: nop
     748: iconst_0
     749: istore        26
     751: aload         25
     753: astore        27
     755: new           #24                 // class java/util/LinkedHashMap
     758: dup
     759: aload         25
     761: invokeinterface #72,  1           // InterfaceMethod java/util/Map.size:()I
     766: invokestatic  #78                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     769: invokespecial #81                 // Method java/util/LinkedHashMap."<init>":(I)V
     772: checkcast     #30                 // class java/util/Map
     775: astore        28
     777: iconst_0
     778: istore        29
     780: aload         27
     782: invokeinterface #85,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     787: checkcast     #22                 // class java/lang/Iterable
     790: astore        30
     792: iconst_0
     793: istore        31
     795: aload         30
     797: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     802: astore        32
     804: aload         32
     806: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     811: ifeq          988
     814: aload         32
     816: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     821: astore        33
     823: aload         28
     825: aload         33
     827: checkcast     #87                 // class java/util/Map$Entry
     830: astore        34
     832: astore        35
     834: iconst_0
     835: istore        36
     837: aload         34
     839: invokeinterface #90,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     844: aload         35
     846: swap
     847: aload         33
     849: checkcast     #87                 // class java/util/Map$Entry
     852: astore        37
     854: astore        39
     856: astore        40
     858: iconst_0
     859: istore        38
     861: aload         37
     863: invokeinterface #93,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     868: checkcast     #22                 // class java/lang/Iterable
     871: astore        41
     873: iconst_0
     874: istore        42
     876: aload         41
     878: astore        43
     880: new           #57                 // class java/util/ArrayList
     883: dup
     884: aload         41
     886: bipush        10
     888: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     891: invokespecial #100                // Method java/util/ArrayList."<init>":(I)V
     894: checkcast     #102                // class java/util/Collection
     897: astore        44
     899: iconst_0
     900: istore        45
     902: aload         43
     904: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     909: astore        46
     911: aload         46
     913: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     918: ifeq          964
     921: aload         46
     923: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     928: astore        47
     930: aload         44
     932: aload         47
     934: checkcast     #46                 // class kotlin/Pair
     937: astore        48
     939: astore        49
     941: iconst_0
     942: istore        50
     944: aload         48
     946: invokevirtual #105                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     949: checkcast     #51                 // class java/lang/String
     952: aload         49
     954: swap
     955: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     960: pop
     961: goto          911
     964: aload         44
     966: checkcast     #60                 // class java/util/List
     969: nop
     970: nop
     971: astore        51
     973: aload         40
     975: aload         39
     977: aload         51
     979: invokeinterface #64,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     984: pop
     985: goto          804
     988: aload         28
     990: nop
     991: nop
     992: aload         22
     994: invokestatic  #109                // Method getFirsts:(Ljava/util/Map;Ljava/lang/String;)Ljava/util/Collection;
     997: aload         23
     999: swap
    1000: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
    1005: pop
    1006: goto          557
    1009: aload         18
    1011: checkcast     #60                 // class java/util/List
    1014: nop
    1015: checkcast     #22                 // class java/lang/Iterable
    1018: invokestatic  #113                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
    1021: astore        54
    1023: aload         52
    1025: aload         53
    1027: aload         54
    1029: invokeinterface #64,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    1034: pop
    1035: goto          450
    1038: aload         4
    1040: nop
    1041: nop
    1042: areturn

  public static final void getFollows(java.util.List<kotlin.Pair<java.lang.String, java.lang.String>>, java.util.Map<java.lang.String, ? extends java.util.List<java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #10                 // String grammar
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #162                // String firsts
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: return

  private static final java.util.Collection<java.lang.String> getFirsts(java.util.Map<java.lang.String, ? extends java.util.List<java.lang.String>>, java.lang.String);
    Code:
       0: nop
       1: aload_0
       2: aload_1
       3: ldc           #165                // String
       5: aconst_null
       6: iconst_2
       7: aconst_null
       8: invokestatic  #171                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      11: invokeinterface #174,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      16: ifne          37
      19: aload_1
      20: ldc           #165                // String
      22: aconst_null
      23: iconst_2
      24: aconst_null
      25: invokestatic  #171                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      28: invokestatic  #180                // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      31: checkcast     #102                // class java/util/Collection
      34: goto          287
      37: aload_0
      38: astore_2
      39: nop
      40: iconst_0
      41: istore_3
      42: new           #24                 // class java/util/LinkedHashMap
      45: dup
      46: invokespecial #28                 // Method java/util/LinkedHashMap."<init>":()V
      49: astore        4
      51: aload_2
      52: invokeinterface #85,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      57: invokeinterface #183,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      62: astore        5
      64: aload         5
      66: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      71: ifeq          133
      74: aload         5
      76: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      81: checkcast     #87                 // class java/util/Map$Entry
      84: astore        6
      86: aload         6
      88: invokeinterface #90,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      93: checkcast     #51                 // class java/lang/String
      96: astore        7
      98: iconst_0
      99: istore        8
     101: aload         7
     103: aload_1
     104: invokestatic  #187                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     107: ifeq          64
     110: aload         4
     112: aload         6
     114: invokeinterface #90,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     119: aload         6
     121: invokeinterface #93,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     126: invokevirtual #188                // Method java/util/LinkedHashMap.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     129: pop
     130: goto          64
     133: aload         4
     135: checkcast     #30                 // class java/util/Map
     138: invokeinterface #192,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     143: checkcast     #22                 // class java/lang/Iterable
     146: invokestatic  #113                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     149: checkcast     #22                 // class java/lang/Iterable
     152: astore_2
     153: nop
     154: iconst_0
     155: istore_3
     156: aload_2
     157: astore        4
     159: new           #57                 // class java/util/ArrayList
     162: dup
     163: aload_2
     164: bipush        10
     166: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     169: invokespecial #100                // Method java/util/ArrayList."<init>":(I)V
     172: checkcast     #102                // class java/util/Collection
     175: astore        5
     177: iconst_0
     178: istore        6
     180: aload         4
     182: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     187: astore        7
     189: aload         7
     191: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     196: ifeq          272
     199: aload         7
     201: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     206: astore        8
     208: aload         5
     210: aload         8
     212: checkcast     #51                 // class java/lang/String
     215: astore        9
     217: astore        11
     219: iconst_0
     220: istore        10
     222: nop
     223: aload_0
     224: aload         9
     226: ldc           #165                // String
     228: aconst_null
     229: iconst_2
     230: aconst_null
     231: invokestatic  #171                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     234: invokeinterface #174,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     239: ifne          253
     242: aload         9
     244: invokestatic  #196                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     247: checkcast     #102                // class java/util/Collection
     250: goto          259
     253: aload_0
     254: aload         9
     256: invokestatic  #109                // Method getFirsts:(Ljava/util/Map;Ljava/lang/String;)Ljava/util/Collection;
     259: nop
     260: aload         11
     262: swap
     263: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     268: pop
     269: goto          189
     272: aload         5
     274: checkcast     #60                 // class java/util/List
     277: nop
     278: checkcast     #22                 // class java/lang/Iterable
     281: invokestatic  #113                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     284: checkcast     #102                // class java/util/Collection
     287: areturn
}


import java.lang.Math.random

/**
 * Implementation of a basic genetic algorithm, that is capable to generate solutions for optimization and search
 * problems relying on bio-inspired operations such as crossover, mutation and selection.
 *
 * @param T the type of an individual.
 * @property population a collection of individuals to start optimization.
 * @property score a function which scores the fitness of an individual. Higher fitness is better.
 * @property cross a function which implements the crossover of two individuals resulting in a child.
 * @property mutate a function which mutates a given individual.
 * @property select a function which implements a selection strategy of an individual from the population.
 */
class GeneticAlgorithm<T>(
        var population: Collection<T>,
        val score: (individual: T) -> Double,
        val cross: (parents: Pair<T, T>) -> T,
        val mutate: (individual: T) -> T,
        val select: (scoredPopulation: Collection<Pair<Double, T>>) -> T) {

    /**
     * Returns the best individual after the given number of optimization epochs.
     *
     * @param epochs number of optimization epochs.
     * @property mutationProbability a value between 0 and 1, which defines the mutation probability of each child.
     */
    fun run(epochs: Int = 1000, mutationProbability: Double = 0.1): T {
        var scoredPopulation = population.map { Pair(score(it), it) }.sortedByDescending { it.first }

        for (i in 0..epochs)
            scoredPopulation = scoredPopulation
                    .map { Pair(select(scoredPopulation), select(scoredPopulation)) }
                    .map { cross(it) }
                    .map { if (random() <= mutationProbability) mutate(it) else it }
                    .map { Pair(score(it), it) }
                    .sortedByDescending { it.first }

        return scoredPopulation.first().second
    }
}

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

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

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

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

Compiled from "GeneticAlgorithm.kt"
public final class GeneticAlgorithm<T> {
  private java.util.Collection<? extends T> population;

  private final kotlin.jvm.functions.Function1<T, java.lang.Double> score;

  private final kotlin.jvm.functions.Function1<kotlin.Pair<? extends T, ? extends T>, T> cross;

  private final kotlin.jvm.functions.Function1<T, T> mutate;

  private final kotlin.jvm.functions.Function1<java.util.Collection<? extends kotlin.Pair<java.lang.Double, ? extends T>>, T> select;

  public GeneticAlgorithm(java.util.Collection<? extends T>, kotlin.jvm.functions.Function1<? super T, java.lang.Double>, kotlin.jvm.functions.Function1<? super kotlin.Pair<? extends T, ? extends T>, ? extends T>, kotlin.jvm.functions.Function1<? super T, ? extends T>, kotlin.jvm.functions.Function1<? super java.util.Collection<? extends kotlin.Pair<java.lang.Double, ? extends T>>, ? extends T>);
    Code:
       0: aload_1
       1: ldc           #11                 // String population
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #19                 // String score
       9: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #21                 // String cross
      15: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload         4
      20: ldc           #23                 // String mutate
      22: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      25: aload         5
      27: ldc           #25                 // String select
      29: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      32: aload_0
      33: invokespecial #28                 // Method java/lang/Object."<init>":()V
      36: aload_0
      37: aload_1
      38: putfield      #31                 // Field population:Ljava/util/Collection;
      41: aload_0
      42: aload_2
      43: putfield      #34                 // Field score:Lkotlin/jvm/functions/Function1;
      46: aload_0
      47: aload_3
      48: putfield      #36                 // Field cross:Lkotlin/jvm/functions/Function1;
      51: aload_0
      52: aload         4
      54: putfield      #38                 // Field mutate:Lkotlin/jvm/functions/Function1;
      57: aload_0
      58: aload         5
      60: putfield      #40                 // Field select:Lkotlin/jvm/functions/Function1;
      63: return

  public final java.util.Collection<T> getPopulation();
    Code:
       0: aload_0
       1: getfield      #31                 // Field population:Ljava/util/Collection;
       4: areturn

  public final void setPopulation(java.util.Collection<? extends T>);
    Code:
       0: aload_1
       1: ldc           #50                 // String <set-?>
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: putfield      #31                 // Field population:Ljava/util/Collection;
      11: return

  public final kotlin.jvm.functions.Function1<T, java.lang.Double> getScore();
    Code:
       0: aload_0
       1: getfield      #34                 // Field score:Lkotlin/jvm/functions/Function1;
       4: areturn

  public final kotlin.jvm.functions.Function1<kotlin.Pair<? extends T, ? extends T>, T> getCross();
    Code:
       0: aload_0
       1: getfield      #36                 // Field cross:Lkotlin/jvm/functions/Function1;
       4: areturn

  public final kotlin.jvm.functions.Function1<T, T> getMutate();
    Code:
       0: aload_0
       1: getfield      #38                 // Field mutate:Lkotlin/jvm/functions/Function1;
       4: areturn

  public final kotlin.jvm.functions.Function1<java.util.Collection<? extends kotlin.Pair<java.lang.Double, ? extends T>>, T> getSelect();
    Code:
       0: aload_0
       1: getfield      #40                 // Field select:Lkotlin/jvm/functions/Function1;
       4: areturn

  public final T run(int, double);
    Code:
       0: aconst_null
       1: astore        4
       3: aload_0
       4: getfield      #31                 // Field population:Ljava/util/Collection;
       7: checkcast     #64                 // class java/lang/Iterable
      10: astore        5
      12: iconst_0
      13: istore        6
      15: aload         5
      17: astore        7
      19: new           #66                 // class java/util/ArrayList
      22: dup
      23: aload         5
      25: bipush        10
      27: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      30: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
      33: checkcast     #77                 // class java/util/Collection
      36: astore        8
      38: iconst_0
      39: istore        9
      41: aload         7
      43: invokeinterface #81,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        10
      50: aload         10
      52: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          112
      60: aload         10
      62: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        11
      69: aload         8
      71: aload         11
      73: astore        12
      75: astore        15
      77: iconst_0
      78: istore        13
      80: new           #93                 // class kotlin/Pair
      83: dup
      84: aload_0
      85: getfield      #34                 // Field score:Lkotlin/jvm/functions/Function1;
      88: aload         12
      90: invokeinterface #99,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      95: aload         12
      97: invokespecial #102                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     100: aload         15
     102: swap
     103: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     108: pop
     109: goto          50
     112: aload         8
     114: checkcast     #108                // class java/util/List
     117: nop
     118: checkcast     #64                 // class java/lang/Iterable
     121: astore        5
     123: nop
     124: iconst_0
     125: istore        6
     127: aload         5
     129: new           #110                // class GeneticAlgorithm$run$$inlined$sortedByDescending$1
     132: dup
     133: invokespecial #111                // Method GeneticAlgorithm$run$$inlined$sortedByDescending$1."<init>":()V
     136: checkcast     #113                // class java/util/Comparator
     139: invokestatic  #117                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     142: astore        4
     144: iconst_0
     145: istore        5
     147: iload         5
     149: iload_1
     150: if_icmpgt     651
     153: aload         4
     155: checkcast     #64                 // class java/lang/Iterable
     158: astore        6
     160: nop
     161: iconst_0
     162: istore        7
     164: aload         6
     166: astore        8
     168: new           #66                 // class java/util/ArrayList
     171: dup
     172: aload         6
     174: bipush        10
     176: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     179: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
     182: checkcast     #77                 // class java/util/Collection
     185: astore        9
     187: iconst_0
     188: istore        10
     190: aload         8
     192: invokeinterface #81,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     197: astore        11
     199: aload         11
     201: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     206: ifeq          273
     209: aload         11
     211: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     216: astore        12
     218: aload         9
     220: aload         12
     222: checkcast     #93                 // class kotlin/Pair
     225: astore        13
     227: astore        15
     229: iconst_0
     230: istore        14
     232: new           #93                 // class kotlin/Pair
     235: dup
     236: aload_0
     237: getfield      #40                 // Field select:Lkotlin/jvm/functions/Function1;
     240: aload         4
     242: invokeinterface #99,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     247: aload_0
     248: getfield      #40                 // Field select:Lkotlin/jvm/functions/Function1;
     251: aload         4
     253: invokeinterface #99,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     258: invokespecial #102                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     261: aload         15
     263: swap
     264: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     269: pop
     270: goto          199
     273: aload         9
     275: checkcast     #108                // class java/util/List
     278: nop
     279: checkcast     #64                 // class java/lang/Iterable
     282: astore        6
     284: nop
     285: iconst_0
     286: istore        7
     288: aload         6
     290: astore        8
     292: new           #66                 // class java/util/ArrayList
     295: dup
     296: aload         6
     298: bipush        10
     300: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     303: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
     306: checkcast     #77                 // class java/util/Collection
     309: astore        9
     311: iconst_0
     312: istore        10
     314: aload         8
     316: invokeinterface #81,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     321: astore        11
     323: aload         11
     325: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     330: ifeq          379
     333: aload         11
     335: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     340: astore        12
     342: aload         9
     344: aload         12
     346: checkcast     #93                 // class kotlin/Pair
     349: astore        13
     351: astore        15
     353: iconst_0
     354: istore        14
     356: aload_0
     357: getfield      #36                 // Field cross:Lkotlin/jvm/functions/Function1;
     360: aload         13
     362: invokeinterface #99,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     367: aload         15
     369: swap
     370: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     375: pop
     376: goto          323
     379: aload         9
     381: checkcast     #108                // class java/util/List
     384: nop
     385: checkcast     #64                 // class java/lang/Iterable
     388: astore        6
     390: nop
     391: iconst_0
     392: istore        7
     394: aload         6
     396: astore        8
     398: new           #66                 // class java/util/ArrayList
     401: dup
     402: aload         6
     404: bipush        10
     406: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     409: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
     412: checkcast     #77                 // class java/util/Collection
     415: astore        9
     417: iconst_0
     418: istore        10
     420: aload         8
     422: invokeinterface #81,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     427: astore        11
     429: aload         11
     431: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     436: ifeq          495
     439: aload         11
     441: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     446: astore        12
     448: aload         9
     450: aload         12
     452: astore        13
     454: astore        15
     456: iconst_0
     457: istore        14
     459: invokestatic  #123                // Method java/lang/Math.random:()D
     462: dload_2
     463: dcmpg
     464: ifgt          481
     467: aload_0
     468: getfield      #38                 // Field mutate:Lkotlin/jvm/functions/Function1;
     471: aload         13
     473: invokeinterface #99,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     478: goto          483
     481: aload         13
     483: aload         15
     485: swap
     486: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     491: pop
     492: goto          429
     495: aload         9
     497: checkcast     #108                // class java/util/List
     500: nop
     501: checkcast     #64                 // class java/lang/Iterable
     504: astore        6
     506: nop
     507: iconst_0
     508: istore        7
     510: aload         6
     512: astore        8
     514: new           #66                 // class java/util/ArrayList
     517: dup
     518: aload         6
     520: bipush        10
     522: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     525: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
     528: checkcast     #77                 // class java/util/Collection
     531: astore        9
     533: iconst_0
     534: istore        10
     536: aload         8
     538: invokeinterface #81,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     543: astore        11
     545: aload         11
     547: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     552: ifeq          607
     555: aload         11
     557: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     562: astore        12
     564: aload         9
     566: aload         12
     568: astore        13
     570: astore        15
     572: iconst_0
     573: istore        14
     575: new           #93                 // class kotlin/Pair
     578: dup
     579: aload_0
     580: getfield      #34                 // Field score:Lkotlin/jvm/functions/Function1;
     583: aload         13
     585: invokeinterface #99,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     590: aload         13
     592: invokespecial #102                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     595: aload         15
     597: swap
     598: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     603: pop
     604: goto          545
     607: aload         9
     609: checkcast     #108                // class java/util/List
     612: nop
     613: checkcast     #64                 // class java/lang/Iterable
     616: astore        6
     618: nop
     619: iconst_0
     620: istore        7
     622: aload         6
     624: new           #125                // class GeneticAlgorithm$run$$inlined$sortedByDescending$2
     627: dup
     628: invokespecial #126                // Method GeneticAlgorithm$run$$inlined$sortedByDescending$2."<init>":()V
     631: checkcast     #113                // class java/util/Comparator
     634: invokestatic  #117                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     637: astore        4
     639: iload         5
     641: iload_1
     642: if_icmpeq     651
     645: iinc          5, 1
     648: goto          153
     651: aload         4
     653: invokestatic  #130                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     656: checkcast     #93                 // class kotlin/Pair
     659: invokevirtual #133                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     662: areturn

  public static java.lang.Object run$default(GeneticAlgorithm, int, double, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          11
       7: sipush        1000
      10: istore_1
      11: iload         4
      13: iconst_2
      14: iand
      15: ifeq          22
      18: ldc2_w        #159                // double 0.1d
      21: dstore_2
      22: aload_0
      23: iload_1
      24: dload_2
      25: invokevirtual #162                // Method run:(ID)Ljava/lang/Object;
      28: areturn
}