package de.fabmax.kool.math

import kotlin.math.*

fun <T> MutableList<T>.partition(k: Int, cmp: (T, T) -> Int) = partition(indices, k, cmp)

fun <T> MutableList<T>.partition(rng: IntRange, k: Int, cmp: (T, T) -> Int) {
    partition(this, rng.first, rng.last, k, { get(it) }, cmp, { a, b -> this[a] = this[b].also { this[b] = this[a] } })
}

fun <T> Array<T>.partition(k: Int, cmp: (T, T) -> Int) = partition(indices, k, cmp)

fun <T> Array<T>.partition(rng: IntRange, k: Int, cmp: (T, T) -> Int) {
    partition(this, rng.first, rng.last, k, { get(it) }, cmp, { a, b -> this[a] = this[b].also { this[b] = this[a] } })
}

/**
 * Partitions items with the given comparator. After partitioning, all elements left of k are smaller
 * than all elements right of k with respect to the given comparator function.
 *
 * This method implements the Floyd-Rivest selection algorithm:
 * https://en.wikipedia.org/wiki/Floyd%E2%80%93Rivest_algorithm
 */
fun <L,T> partition(elems: L, lt: Int, rt: Int, k: Int, get: L.(Int) -> T, cmp: (T, T) -> Int, swap: L.(Int, Int) -> Unit) {
    var left = lt
    var right = rt
    while (right > left) {
        if (right - left > 600) {
            val n = right - left + 1
            val i = k - left + 1
            val z = ln(n.toDouble())
            val s = 0.5 * exp(2.0 * z / 3.0)
            val sd = 0.5 * sqrt(z * s * (n - s) / n) * sign(i - n / 2.0)
            val newLeft = max(left, (k - i * s / n + sd).toInt())
            val newRight = min(right, (k + (n - i) * s / n + sd).toInt())
            partition(elems, newLeft, newRight, k, get, cmp, swap)
        }
        val t = elems.get(k)
        var i = left
        var j = right
        elems.swap(left, k)
        if (cmp(elems.get(right), t) > 0) {
            elems.swap(right, left)
        }
        while (i < j) {
            elems.swap(i, j)
            i++
            j--
            while (cmp(elems.get(i), t) < 0) {
                i++
            }
            while (j >= 0 && cmp(elems.get(j), t) > 0) {
                j--
            }
        }
        if (cmp(elems.get(left), t) == 0) {
            elems.swap(left, j)
        } else {
            j++
            elems.swap(j, right)
        }
        if (j <= k) {
            left = j + 1
        }
        if (k <= j) {
            right = j - 1
        }
    }
}

Compiled from "Partition.kt"
public final class de.fabmax.kool.math.PartitionKt {
  public static final <T> void partition(java.util.List<T>, int, kotlin.jvm.functions.Function2<? super T, ? super T, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String cmp
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_0
      14: checkcast     #20                 // class java/util/Collection
      17: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
      20: iload_1
      21: aload_2
      22: invokestatic  #29                 // Method partition:(Ljava/util/List;Lkotlin/ranges/IntRange;ILkotlin/jvm/functions/Function2;)V
      25: return

  public static final <T> void partition(java.util.List<T>, kotlin.ranges.IntRange, int, kotlin.jvm.functions.Function2<? super T, ? super T, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #37                 // String rng
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #18                 // String cmp
      15: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload_0
      19: aload_1
      20: invokevirtual #43                 // Method kotlin/ranges/IntRange.getFirst:()I
      23: aload_1
      24: invokevirtual #46                 // Method kotlin/ranges/IntRange.getLast:()I
      27: iload_2
      28: invokedynamic #66,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
      33: aload_3
      34: invokedynamic #78,  0             // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function3;
      39: invokestatic  #81                 // Method partition:(Ljava/lang/Object;IIILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)V
      42: return

  public static final <T> void partition(T[], int, kotlin.jvm.functions.Function2<? super T, ? super T, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String cmp
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_0
      14: invokestatic  #89                 // Method kotlin/collections/ArraysKt.getIndices:([Ljava/lang/Object;)Lkotlin/ranges/IntRange;
      17: iload_1
      18: aload_2
      19: invokestatic  #92                 // Method partition:([Ljava/lang/Object;Lkotlin/ranges/IntRange;ILkotlin/jvm/functions/Function2;)V
      22: return

  public static final <T> void partition(T[], kotlin.ranges.IntRange, int, kotlin.jvm.functions.Function2<? super T, ? super T, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #37                 // String rng
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #18                 // String cmp
      15: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload_0
      19: aload_1
      20: invokevirtual #43                 // Method kotlin/ranges/IntRange.getFirst:()I
      23: aload_1
      24: invokevirtual #46                 // Method kotlin/ranges/IntRange.getLast:()I
      27: iload_2
      28: invokedynamic #102,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function2;
      33: aload_3
      34: invokedynamic #110,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function3;
      39: invokestatic  #81                 // Method partition:(Ljava/lang/Object;IIILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)V
      42: return

  public static final <L, T> void partition(L, int, int, int, kotlin.jvm.functions.Function2<? super L, ? super java.lang.Integer, ? extends T>, kotlin.jvm.functions.Function2<? super T, ? super T, java.lang.Integer>, kotlin.jvm.functions.Function3<? super L, ? super java.lang.Integer, ? super java.lang.Integer, kotlin.Unit>);
    Code:
       0: aload         4
       2: ldc           #113                // String get
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload         5
       9: ldc           #18                 // String cmp
      11: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload         6
      16: ldc           #115                // String swap
      18: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      21: iload_1
      22: istore        7
      24: iload_2
      25: istore        8
      27: iload         8
      29: iload         7
      31: if_icmple     498
      34: iload         8
      36: iload         7
      38: isub
      39: sipush        600
      42: if_icmple     195
      45: iload         8
      47: iload         7
      49: isub
      50: iconst_1
      51: iadd
      52: istore        9
      54: iload_3
      55: iload         7
      57: isub
      58: iconst_1
      59: iadd
      60: istore        10
      62: iload         9
      64: i2d
      65: invokestatic  #121                // Method java/lang/Math.log:(D)D
      68: dstore        11
      70: ldc2_w        #122                // double 0.5d
      73: ldc2_w        #124                // double 2.0d
      76: dload         11
      78: dmul
      79: ldc2_w        #126                // double 3.0d
      82: ddiv
      83: invokestatic  #130                // Method java/lang/Math.exp:(D)D
      86: dmul
      87: dstore        13
      89: ldc2_w        #122                // double 0.5d
      92: dload         11
      94: dload         13
      96: dmul
      97: iload         9
      99: i2d
     100: dload         13
     102: dsub
     103: dmul
     104: iload         9
     106: i2d
     107: ddiv
     108: invokestatic  #133                // Method java/lang/Math.sqrt:(D)D
     111: dmul
     112: iload         10
     114: i2d
     115: iload         9
     117: i2d
     118: ldc2_w        #124                // double 2.0d
     121: ddiv
     122: dsub
     123: invokestatic  #136                // Method java/lang/Math.signum:(D)D
     126: dmul
     127: dstore        15
     129: iload         7
     131: iload_3
     132: i2d
     133: iload         10
     135: i2d
     136: dload         13
     138: dmul
     139: iload         9
     141: i2d
     142: ddiv
     143: dsub
     144: dload         15
     146: dadd
     147: d2i
     148: invokestatic  #140                // Method java/lang/Math.max:(II)I
     151: istore        17
     153: iload         8
     155: iload_3
     156: i2d
     157: iload         9
     159: iload         10
     161: isub
     162: i2d
     163: dload         13
     165: dmul
     166: iload         9
     168: i2d
     169: ddiv
     170: dadd
     171: dload         15
     173: dadd
     174: d2i
     175: invokestatic  #143                // Method java/lang/Math.min:(II)I
     178: istore        18
     180: aload_0
     181: iload         17
     183: iload         18
     185: iload_3
     186: aload         4
     188: aload         5
     190: aload         6
     192: invokestatic  #81                 // Method partition:(Ljava/lang/Object;IIILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)V
     195: aload         4
     197: aload_0
     198: iload_3
     199: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     202: invokeinterface #153,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     207: astore        9
     209: iload         7
     211: istore        10
     213: iload         8
     215: istore        11
     217: aload         6
     219: aload_0
     220: iload         7
     222: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     225: iload_3
     226: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     229: invokeinterface #157,  4          // InterfaceMethod kotlin/jvm/functions/Function3.invoke:(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     234: pop
     235: aload         5
     237: aload         4
     239: aload_0
     240: iload         8
     242: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     245: invokeinterface #153,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     250: aload         9
     252: invokeinterface #153,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     257: checkcast     #159                // class java/lang/Number
     260: invokevirtual #162                // Method java/lang/Number.intValue:()I
     263: ifle          285
     266: aload         6
     268: aload_0
     269: iload         8
     271: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     274: iload         7
     276: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     279: invokeinterface #157,  4          // InterfaceMethod kotlin/jvm/functions/Function3.invoke:(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     284: pop
     285: iload         10
     287: iload         11
     289: if_icmpge     396
     292: aload         6
     294: aload_0
     295: iload         10
     297: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     300: iload         11
     302: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     305: invokeinterface #157,  4          // InterfaceMethod kotlin/jvm/functions/Function3.invoke:(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     310: pop
     311: iinc          10, 1
     314: iinc          11, -1
     317: aload         5
     319: aload         4
     321: aload_0
     322: iload         10
     324: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     327: invokeinterface #153,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     332: aload         9
     334: invokeinterface #153,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     339: checkcast     #159                // class java/lang/Number
     342: invokevirtual #162                // Method java/lang/Number.intValue:()I
     345: ifge          354
     348: iinc          10, 1
     351: goto          317
     354: iload         11
     356: iflt          285
     359: aload         5
     361: aload         4
     363: aload_0
     364: iload         11
     366: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     369: invokeinterface #153,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     374: aload         9
     376: invokeinterface #153,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     381: checkcast     #159                // class java/lang/Number
     384: invokevirtual #162                // Method java/lang/Number.intValue:()I
     387: ifle          285
     390: iinc          11, -1
     393: goto          354
     396: aload         5
     398: aload         4
     400: aload_0
     401: iload         7
     403: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     406: invokeinterface #153,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     411: aload         9
     413: invokeinterface #153,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     418: checkcast     #159                // class java/lang/Number
     421: invokevirtual #162                // Method java/lang/Number.intValue:()I
     424: ifne          449
     427: aload         6
     429: aload_0
     430: iload         7
     432: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     435: iload         11
     437: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     440: invokeinterface #157,  4          // InterfaceMethod kotlin/jvm/functions/Function3.invoke:(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     445: pop
     446: goto          471
     449: iinc          11, 1
     452: aload         6
     454: aload_0
     455: iload         11
     457: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     460: iload         8
     462: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     465: invokeinterface #157,  4          // InterfaceMethod kotlin/jvm/functions/Function3.invoke:(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     470: pop
     471: iload         11
     473: iload_3
     474: if_icmpgt     483
     477: iload         11
     479: iconst_1
     480: iadd
     481: istore        7
     483: iload_3
     484: iload         11
     486: if_icmpgt     27
     489: iload         11
     491: iconst_1
     492: isub
     493: istore        8
     495: goto          27
     498: return

  private static final java.lang.Object partition$lambda$0(java.util.List, int);
    Code:
       0: aload_0
       1: ldc           #180                // String $this$partition
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: invokeinterface #185,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: areturn

  private static final kotlin.Unit partition$lambda$2(java.util.List, int, int);
    Code:
       0: aload_0
       1: ldc           #180                // String $this$partition
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: aload_0
       9: iload_2
      10: invokeinterface #185,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      15: astore_3
      16: aload_3
      17: astore        4
      19: istore        7
      21: astore        6
      23: iconst_0
      24: istore        5
      26: aload_0
      27: iload_2
      28: aload_0
      29: iload_1
      30: invokeinterface #185,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: invokeinterface #190,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      40: pop
      41: getstatic     #196                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      44: astore        8
      46: aload         6
      48: iload         7
      50: aload_3
      51: invokeinterface #190,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      56: pop
      57: getstatic     #196                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      60: areturn

  private static final java.lang.Object partition$lambda$3(java.lang.Object[], int);
    Code:
       0: aload_0
       1: ldc           #180                // String $this$partition
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: aaload
       9: areturn

  private static final kotlin.Unit partition$lambda$5(java.lang.Object[], int, int);
    Code:
       0: aload_0
       1: ldc           #180                // String $this$partition
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: aload_0
       9: iload_2
      10: aaload
      11: astore_3
      12: aload_3
      13: astore        4
      15: istore        7
      17: astore        6
      19: iconst_0
      20: istore        5
      22: aload_0
      23: iload_2
      24: aload_0
      25: iload_1
      26: aaload
      27: aastore
      28: getstatic     #196                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      31: astore        8
      33: aload         6
      35: iload         7
      37: aload_3
      38: aastore
      39: getstatic     #196                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      42: areturn
}


package sort_algorithm

/**
 * 快速排序
 * 时间复杂度：
 *   最优时间复杂度：Ο(n*log(n))
 *   平均时间复杂度：Ο(n*log(n))
 *   最坏时间复杂度：Ο(n²)
 * 空间复杂度：Ο(1)
 *
 * Quick Sort
 * Time Complexity:
 *   Optimal Time Complexity: Ο(n*log(n))
 *   Average Time Complexity: Ο(n*log(n))
 *   Worst Time Complexity: Ο(n²)
 * Space Complexity: Ο(1)
 */
fun quickSort(array: IntArray) {

    fun partition(left: Int, right: Int): Int {
        // 以最左边的值作为交换值
        var pivotPreIndex = left
        for (index in left..right) {
            if (array[index] <= array[right]) {
                array[pivotPreIndex] = array[index].also { array[index] = array[pivotPreIndex] }
                pivotPreIndex += 1
            }
        }
        return pivotPreIndex - 1
    }

    fun inner(left: Int, right: Int) {
        if (left < right) {
            val p = partition(left, right)
            inner(left, p - 1)
            inner(p + 1, right)
        }
    }

    inner(0, array.size - 1)
}

Compiled from "quickSort.kt"
public final class sort_algorithm.QuickSortKt {
  public static final void quickSort(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String array
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iconst_0
       8: aload_0
       9: arraylength
      10: iconst_1
      11: isub
      12: invokestatic  #19                 // Method quickSort$inner:([III)V
      15: return

  private static final int quickSort$partition(int[], int, int);
    Code:
       0: iconst_0
       1: istore_3
       2: iload_1
       3: istore_3
       4: iload_1
       5: istore        4
       7: iload         4
       9: iload_2
      10: if_icmpgt     77
      13: aload_0
      14: iload         4
      16: iaload
      17: aload_0
      18: iload_2
      19: iaload
      20: if_icmpgt     65
      23: aload_0
      24: iload_3
      25: aload_0
      26: iload         4
      28: iaload
      29: istore        5
      31: iload         5
      33: istore        6
      35: istore        9
      37: astore        8
      39: iconst_0
      40: istore        7
      42: aload_0
      43: iload         4
      45: aload_0
      46: iload_3
      47: iaload
      48: iastore
      49: getstatic     #28                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      52: astore        10
      54: aload         8
      56: iload         9
      58: iload         5
      60: iastore
      61: iload_3
      62: iconst_1
      63: iadd
      64: istore_3
      65: iload         4
      67: iload_2
      68: if_icmpeq     77
      71: iinc          4, 1
      74: goto          13
      77: iload_3
      78: iconst_1
      79: isub
      80: ireturn

  private static final void quickSort$inner(int[], int, int);
    Code:
       0: iload_1
       1: iload_2
       2: if_icmpge     28
       5: aload_0
       6: iload_1
       7: iload_2
       8: invokestatic  #38                 // Method quickSort$partition:([III)I
      11: istore_3
      12: aload_0
      13: iload_1
      14: iload_3
      15: iconst_1
      16: isub
      17: invokestatic  #19                 // Method quickSort$inner:([III)V
      20: aload_0
      21: iload_3
      22: iconst_1
      23: iadd
      24: iload_2
      25: invokestatic  #19                 // Method quickSort$inner:([III)V
      28: return
}


package day4

import java.io.File
import java.util.regex.Pattern

fun main(args: Array<String>) {
    val lines = loadFile("input.txt")
    val numbersDrawn = lines[0]
    val boards = lines.drop(1)
        .chunked(5)
        .map { board ->
            board.map { line -> line.map { it to false }.toMutableList() }.toMutableList()
        }

    traverseBoards(numbersDrawn, boards)
}

private fun traverseBoards(
    numbersDrawn: MutableList<Int>,
    boards: List<MutableList<MutableList<Pair<Int, Boolean>>>>
) {
    var lastWinningBoard = boards[0]
    var lastWinningNumber = -1
    var mutableBoards = boards
    numbersDrawn.forEach { numberDrawn ->
        mutableBoards = mutableBoards.filter { board ->
            updateBoard(numberDrawn, board)
            val didWin = checkBoard(board)
            if (didWin) {
                lastWinningBoard = board
                lastWinningNumber = numberDrawn
            }
            !didWin
        }
    }

    println("Last board won at $lastWinningNumber")
    lastWinningBoard.forEach { line ->
        println(line)
    }
    val sum = sumOfUnmarked(lastWinningBoard)
    println("Result: $sum x $lastWinningNumber = ${sum * lastWinningNumber}")
}

fun sumOfUnmarked(board: MutableList<MutableList<Pair<Int, Boolean>>>): Int {
    return board.flatten().fold(0 to false) { acc, pair ->
        if (!pair.second) {
            acc.copy(acc.first + pair.first)
        } else acc
    }.first
}

fun checkBoard(board: MutableList<MutableList<Pair<Int, Boolean>>>): Boolean {
    board.forEach { line ->
        val win = line.reduce { acc, next ->
            acc.copy(second = acc.second && next.second)
        }.second
        if (win) return true
    }

    for (column in board[0].indices) {
        val win = board.indices
            .map { line -> board[line][column].second }
            .reduce { acc, marked -> acc && marked }
        if (win) return true
    }

    return false
}

fun updateBoard(numberDrawn: Int, board: MutableList<MutableList<Pair<Int, Boolean>>>) {
    for (line in board.indices) {
        for (column in board[line].indices) {
            if (board[line][column].first == numberDrawn) {
                board[line][column] = numberDrawn to true
            }
        }
    }
}

fun loadFile(input: String): MutableList<MutableList<Int>> {
    val regex = Pattern.compile(" +|,")
    return File(input)
        .useLines { sequence ->
            sequence.filter { line -> line.isNotBlank() }
                .map { line ->
                    line.split(regex)
                        .map { entry -> entry.trim() }
                        .filter { it.isNotBlank() }
                        .map { it.toInt() }
                        .toMutableList()
                }
                .toMutableList()
        }
}

Compiled from "Main.kt"
public final class day4.MainKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #17                 // String input.txt
       8: invokestatic  #21                 // Method loadFile:(Ljava/lang/String;)Ljava/util/List;
      11: astore_1
      12: aload_1
      13: iconst_0
      14: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      19: checkcast     #23                 // class java/util/List
      22: astore_2
      23: aload_1
      24: checkcast     #29                 // class java/lang/Iterable
      27: iconst_1
      28: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      31: checkcast     #29                 // class java/lang/Iterable
      34: iconst_5
      35: invokestatic  #38                 // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
      38: checkcast     #29                 // class java/lang/Iterable
      41: astore        4
      43: nop
      44: iconst_0
      45: istore        5
      47: aload         4
      49: astore        6
      51: new           #40                 // class java/util/ArrayList
      54: dup
      55: aload         4
      57: bipush        10
      59: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      62: invokespecial #48                 // Method java/util/ArrayList."<init>":(I)V
      65: checkcast     #50                 // class java/util/Collection
      68: astore        7
      70: iconst_0
      71: istore        8
      73: aload         6
      75: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      80: astore        9
      82: aload         9
      84: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      89: ifeq          346
      92: aload         9
      94: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      99: astore        10
     101: aload         7
     103: aload         10
     105: checkcast     #23                 // class java/util/List
     108: astore        11
     110: astore        33
     112: iconst_0
     113: istore        12
     115: aload         11
     117: checkcast     #29                 // class java/lang/Iterable
     120: astore        13
     122: iconst_0
     123: istore        14
     125: aload         13
     127: astore        15
     129: new           #40                 // class java/util/ArrayList
     132: dup
     133: aload         13
     135: bipush        10
     137: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     140: invokespecial #48                 // Method java/util/ArrayList."<init>":(I)V
     143: checkcast     #50                 // class java/util/Collection
     146: astore        16
     148: iconst_0
     149: istore        17
     151: aload         15
     153: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     158: astore        18
     160: aload         18
     162: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     167: ifeq          322
     170: aload         18
     172: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     177: astore        19
     179: aload         16
     181: aload         19
     183: checkcast     #23                 // class java/util/List
     186: astore        20
     188: astore        21
     190: iconst_0
     191: istore        22
     193: aload         20
     195: checkcast     #29                 // class java/lang/Iterable
     198: astore        23
     200: iconst_0
     201: istore        24
     203: aload         23
     205: astore        25
     207: new           #40                 // class java/util/ArrayList
     210: dup
     211: aload         23
     213: bipush        10
     215: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     218: invokespecial #48                 // Method java/util/ArrayList."<init>":(I)V
     221: checkcast     #50                 // class java/util/Collection
     224: astore        26
     226: iconst_0
     227: istore        27
     229: aload         25
     231: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     236: astore        28
     238: aload         28
     240: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     245: ifeq          298
     248: aload         28
     250: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     255: astore        29
     257: aload         26
     259: aload         29
     261: checkcast     #66                 // class java/lang/Number
     264: invokevirtual #70                 // Method java/lang/Number.intValue:()I
     267: istore        30
     269: astore        31
     271: iconst_0
     272: istore        32
     274: iload         30
     276: invokestatic  #76                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     279: iconst_0
     280: invokestatic  #81                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     283: invokestatic  #87                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     286: aload         31
     288: swap
     289: invokeinterface #91,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     294: pop
     295: goto          238
     298: aload         26
     300: checkcast     #23                 // class java/util/List
     303: nop
     304: checkcast     #50                 // class java/util/Collection
     307: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     310: aload         21
     312: swap
     313: invokeinterface #91,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     318: pop
     319: goto          160
     322: aload         16
     324: checkcast     #23                 // class java/util/List
     327: nop
     328: checkcast     #50                 // class java/util/Collection
     331: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     334: aload         33
     336: swap
     337: invokeinterface #91,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     342: pop
     343: goto          82
     346: aload         7
     348: checkcast     #23                 // class java/util/List
     351: nop
     352: astore_3
     353: aload_2
     354: aload_3
     355: invokestatic  #99                 // Method traverseBoards:(Ljava/util/List;Ljava/util/List;)V
     358: return

  private static final void traverseBoards(java.util.List<java.lang.Integer>, java.util.List<? extends java.util.List<java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Boolean>>>>);
    Code:
       0: aconst_null
       1: astore_2
       2: aload_1
       3: iconst_0
       4: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       9: astore_2
      10: iconst_0
      11: istore_3
      12: iconst_m1
      13: istore_3
      14: new           #124                // class kotlin/jvm/internal/Ref$ObjectRef
      17: dup
      18: invokespecial #127                // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
      21: astore        4
      23: aload         4
      25: aload_1
      26: putfield      #130                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      29: aload_0
      30: checkcast     #29                 // class java/lang/Iterable
      33: astore        5
      35: iconst_0
      36: istore        6
      38: aload         5
      40: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        7
      47: aload         7
      49: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          221
      57: aload         7
      59: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        8
      66: aload         8
      68: checkcast     #66                 // class java/lang/Number
      71: invokevirtual #70                 // Method java/lang/Number.intValue:()I
      74: istore        9
      76: iconst_0
      77: istore        10
      79: aload         4
      81: aload         4
      83: getfield      #130                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      86: checkcast     #29                 // class java/lang/Iterable
      89: astore        11
      91: astore        12
      93: iconst_0
      94: istore        13
      96: aload         11
      98: astore        14
     100: new           #40                 // class java/util/ArrayList
     103: dup
     104: invokespecial #131                // Method java/util/ArrayList."<init>":()V
     107: checkcast     #50                 // class java/util/Collection
     110: astore        15
     112: iconst_0
     113: istore        16
     115: aload         14
     117: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     122: astore        17
     124: aload         17
     126: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     131: ifeq          204
     134: aload         17
     136: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     141: astore        18
     143: aload         18
     145: checkcast     #23                 // class java/util/List
     148: astore        19
     150: iconst_0
     151: istore        20
     153: iload         9
     155: aload         19
     157: invokestatic  #135                // Method updateBoard:(ILjava/util/List;)V
     160: aload         19
     162: invokestatic  #139                // Method checkBoard:(Ljava/util/List;)Z
     165: istore        21
     167: iload         21
     169: ifeq          178
     172: aload         19
     174: astore_2
     175: iload         9
     177: istore_3
     178: iload         21
     180: ifne          187
     183: iconst_1
     184: goto          188
     187: iconst_0
     188: ifeq          124
     191: aload         15
     193: aload         18
     195: invokeinterface #91,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     200: pop
     201: goto          124
     204: aload         15
     206: checkcast     #23                 // class java/util/List
     209: nop
     210: aload         12
     212: swap
     213: putfield      #130                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     216: nop
     217: nop
     218: goto          47
     221: nop
     222: new           #141                // class java/lang/StringBuilder
     225: dup
     226: invokespecial #142                // Method java/lang/StringBuilder."<init>":()V
     229: ldc           #144                // String Last board won at
     231: invokevirtual #148                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     234: iload_3
     235: invokevirtual #151                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     238: invokevirtual #155                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     241: getstatic     #161                // Field java/lang/System.out:Ljava/io/PrintStream;
     244: swap
     245: invokevirtual #167                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     248: aload_2
     249: checkcast     #29                 // class java/lang/Iterable
     252: astore        5
     254: iconst_0
     255: istore        6
     257: aload         5
     259: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     264: astore        7
     266: aload         7
     268: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     273: ifeq          308
     276: aload         7
     278: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     283: astore        8
     285: aload         8
     287: checkcast     #23                 // class java/util/List
     290: astore        9
     292: iconst_0
     293: istore        10
     295: getstatic     #161                // Field java/lang/System.out:Ljava/io/PrintStream;
     298: aload         9
     300: invokevirtual #167                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     303: nop
     304: nop
     305: goto          266
     308: nop
     309: aload_2
     310: checkcast     #23                 // class java/util/List
     313: invokestatic  #171                // Method sumOfUnmarked:(Ljava/util/List;)I
     316: istore        5
     318: new           #141                // class java/lang/StringBuilder
     321: dup
     322: invokespecial #142                // Method java/lang/StringBuilder."<init>":()V
     325: ldc           #173                // String Result:
     327: invokevirtual #148                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     330: iload         5
     332: invokevirtual #151                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     335: ldc           #175                // String  x
     337: invokevirtual #148                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     340: iload_3
     341: invokevirtual #151                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     344: ldc           #177                // String  =
     346: invokevirtual #148                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     349: iload         5
     351: iload_3
     352: imul
     353: invokevirtual #151                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     356: invokevirtual #155                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     359: getstatic     #161                // Field java/lang/System.out:Ljava/io/PrintStream;
     362: swap
     363: invokevirtual #167                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     366: return

  public static final int sumOfUnmarked(java.util.List<java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Boolean>>>);
    Code:
       0: aload_0
       1: ldc           #198                // String board
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #29                 // class java/lang/Iterable
      10: invokestatic  #202                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
      13: checkcast     #29                 // class java/lang/Iterable
      16: astore_1
      17: iconst_0
      18: invokestatic  #76                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      21: iconst_0
      22: invokestatic  #81                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      25: invokestatic  #87                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      28: astore_2
      29: iconst_0
      30: istore_3
      31: aload_2
      32: astore        4
      34: aload_1
      35: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        5
      42: aload         5
      44: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          133
      52: aload         5
      54: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        6
      61: aload         4
      63: aload         6
      65: checkcast     #204                // class kotlin/Pair
      68: astore        7
      70: astore        8
      72: iconst_0
      73: istore        9
      75: aload         7
      77: invokevirtual #207                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      80: checkcast     #78                 // class java/lang/Boolean
      83: invokevirtual #210                // Method java/lang/Boolean.booleanValue:()Z
      86: ifne          126
      89: aload         8
      91: aload         8
      93: invokevirtual #213                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      96: checkcast     #66                 // class java/lang/Number
      99: invokevirtual #70                 // Method java/lang/Number.intValue:()I
     102: aload         7
     104: invokevirtual #213                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     107: checkcast     #66                 // class java/lang/Number
     110: invokevirtual #70                 // Method java/lang/Number.intValue:()I
     113: iadd
     114: invokestatic  #76                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     117: aconst_null
     118: iconst_2
     119: aconst_null
     120: invokestatic  #217                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     123: goto          128
     126: aload         8
     128: astore        4
     130: goto          42
     133: aload         4
     135: invokevirtual #213                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     138: checkcast     #66                 // class java/lang/Number
     141: invokevirtual #70                 // Method java/lang/Number.intValue:()I
     144: ireturn

  public static final boolean checkBoard(java.util.List<java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Boolean>>>);
    Code:
       0: aload_0
       1: ldc           #198                // String board
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #29                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifeq          204
      29: aload_3
      30: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      35: astore        4
      37: aload         4
      39: checkcast     #23                 // class java/util/List
      42: astore        5
      44: iconst_0
      45: istore        6
      47: aload         5
      49: checkcast     #29                 // class java/lang/Iterable
      52: astore        7
      54: iconst_0
      55: istore        8
      57: aload         7
      59: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        9
      66: aload         9
      68: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifne          86
      76: new           #228                // class java/lang/UnsupportedOperationException
      79: dup
      80: ldc           #230                // String Empty collection can\'t be reduced.
      82: invokespecial #233                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
      85: athrow
      86: aload         9
      88: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      93: astore        10
      95: aload         9
      97: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     102: ifeq          176
     105: aload         10
     107: aload         9
     109: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     114: checkcast     #204                // class kotlin/Pair
     117: astore        11
     119: checkcast     #204                // class kotlin/Pair
     122: astore        12
     124: iconst_0
     125: istore        13
     127: aload         12
     129: aconst_null
     130: aload         12
     132: invokevirtual #207                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     135: checkcast     #78                 // class java/lang/Boolean
     138: invokevirtual #210                // Method java/lang/Boolean.booleanValue:()Z
     141: ifeq          162
     144: aload         11
     146: invokevirtual #207                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     149: checkcast     #78                 // class java/lang/Boolean
     152: invokevirtual #210                // Method java/lang/Boolean.booleanValue:()Z
     155: ifeq          162
     158: iconst_1
     159: goto          163
     162: iconst_0
     163: invokestatic  #81                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     166: iconst_1
     167: aconst_null
     168: invokestatic  #217                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     171: astore        10
     173: goto          95
     176: aload         10
     178: checkcast     #204                // class kotlin/Pair
     181: invokevirtual #207                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     184: checkcast     #78                 // class java/lang/Boolean
     187: invokevirtual #210                // Method java/lang/Boolean.booleanValue:()Z
     190: istore        14
     192: iload         14
     194: ifeq          199
     197: iconst_1
     198: ireturn
     199: nop
     200: nop
     201: goto          20
     204: nop
     205: iconst_0
     206: istore_1
     207: aload_0
     208: iconst_0
     209: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     214: checkcast     #50                 // class java/util/Collection
     217: invokeinterface #236,  1          // InterfaceMethod java/util/Collection.size:()I
     222: istore_2
     223: iload_1
     224: iload_2
     225: if_icmpge     489
     228: aload_0
     229: checkcast     #50                 // class java/util/Collection
     232: invokestatic  #240                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
     235: checkcast     #29                 // class java/lang/Iterable
     238: astore        4
     240: nop
     241: iconst_0
     242: istore        5
     244: aload         4
     246: astore        6
     248: new           #40                 // class java/util/ArrayList
     251: dup
     252: aload         4
     254: bipush        10
     256: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     259: invokespecial #48                 // Method java/util/ArrayList."<init>":(I)V
     262: checkcast     #50                 // class java/util/Collection
     265: astore        7
     267: iconst_0
     268: istore        8
     270: aload         6
     272: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     277: astore        9
     279: aload         9
     281: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     286: ifeq          354
     289: aload         9
     291: checkcast     #242                // class kotlin/collections/IntIterator
     294: invokevirtual #245                // Method kotlin/collections/IntIterator.nextInt:()I
     297: istore        10
     299: aload         7
     301: iload         10
     303: istore        11
     305: astore        15
     307: iconst_0
     308: istore        12
     310: aload_0
     311: iload         11
     313: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     318: checkcast     #23                 // class java/util/List
     321: iload_1
     322: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     327: checkcast     #204                // class kotlin/Pair
     330: invokevirtual #207                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     333: checkcast     #78                 // class java/lang/Boolean
     336: invokevirtual #210                // Method java/lang/Boolean.booleanValue:()Z
     339: invokestatic  #81                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     342: aload         15
     344: swap
     345: invokeinterface #91,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     350: pop
     351: goto          279
     354: aload         7
     356: checkcast     #23                 // class java/util/List
     359: nop
     360: checkcast     #29                 // class java/lang/Iterable
     363: astore        4
     365: nop
     366: iconst_0
     367: istore        5
     369: aload         4
     371: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     376: astore        6
     378: aload         6
     380: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     385: ifne          398
     388: new           #228                // class java/lang/UnsupportedOperationException
     391: dup
     392: ldc           #230                // String Empty collection can\'t be reduced.
     394: invokespecial #233                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     397: athrow
     398: aload         6
     400: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     405: astore        7
     407: aload         6
     409: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     414: ifeq          468
     417: aload         7
     419: aload         6
     421: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     426: checkcast     #78                 // class java/lang/Boolean
     429: invokevirtual #210                // Method java/lang/Boolean.booleanValue:()Z
     432: istore        8
     434: checkcast     #78                 // class java/lang/Boolean
     437: invokevirtual #210                // Method java/lang/Boolean.booleanValue:()Z
     440: istore        9
     442: iconst_0
     443: istore        10
     445: iload         9
     447: ifeq          459
     450: iload         8
     452: ifeq          459
     455: iconst_1
     456: goto          460
     459: iconst_0
     460: invokestatic  #81                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     463: astore        7
     465: goto          407
     468: aload         7
     470: checkcast     #78                 // class java/lang/Boolean
     473: invokevirtual #210                // Method java/lang/Boolean.booleanValue:()Z
     476: istore_3
     477: iload_3
     478: ifeq          483
     481: iconst_1
     482: ireturn
     483: iinc          1, 1
     486: goto          223
     489: iconst_0
     490: ireturn

  public static final void updateBoard(int, java.util.List<java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Boolean>>>);
    Code:
       0: aload_1
       1: ldc           #198                // String board
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_1
       9: checkcast     #50                 // class java/util/Collection
      12: invokeinterface #236,  1          // InterfaceMethod java/util/Collection.size:()I
      17: istore_3
      18: iload_2
      19: iload_3
      20: if_icmpge     124
      23: iconst_0
      24: istore        4
      26: aload_1
      27: iload_2
      28: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      33: checkcast     #50                 // class java/util/Collection
      36: invokeinterface #236,  1          // InterfaceMethod java/util/Collection.size:()I
      41: istore        5
      43: iload         4
      45: iload         5
      47: if_icmpge     118
      50: aload_1
      51: iload_2
      52: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      57: checkcast     #23                 // class java/util/List
      60: iload         4
      62: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #204                // class kotlin/Pair
      70: invokevirtual #213                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      73: checkcast     #66                 // class java/lang/Number
      76: invokevirtual #70                 // Method java/lang/Number.intValue:()I
      79: iload_0
      80: if_icmpne     112
      83: aload_1
      84: iload_2
      85: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      90: checkcast     #23                 // class java/util/List
      93: iload         4
      95: iload_0
      96: invokestatic  #76                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: iconst_1
     100: invokestatic  #81                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     103: invokestatic  #87                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     106: invokeinterface #261,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     111: pop
     112: iinc          4, 1
     115: goto          43
     118: iinc          2, 1
     121: goto          18
     124: return

  public static final java.util.List<java.util.List<java.lang.Integer>> loadFile(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #266                // String input
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: ldc_w         #268                // String  +|,
      10: invokestatic  #274                // Method java/util/regex/Pattern.compile:(Ljava/lang/String;)Ljava/util/regex/Pattern;
      13: astore_1
      14: new           #276                // class java/io/File
      17: dup
      18: aload_0
      19: invokespecial #277                // Method java/io/File."<init>":(Ljava/lang/String;)V
      22: astore_2
      23: nop
      24: getstatic     #283                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: astore        5
      34: sipush        8192
      37: istore        6
      39: aload         5
      41: astore        7
      43: new           #285                // class java/io/InputStreamReader
      46: dup
      47: new           #287                // class java/io/FileInputStream
      50: dup
      51: aload         7
      53: invokespecial #290                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      56: checkcast     #292                // class java/io/InputStream
      59: aload_3
      60: invokespecial #295                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      63: checkcast     #297                // class java/io/Reader
      66: astore        7
      68: aload         7
      70: instanceof    #299                // class java/io/BufferedReader
      73: ifeq          84
      76: aload         7
      78: checkcast     #299                // class java/io/BufferedReader
      81: goto          95
      84: new           #299                // class java/io/BufferedReader
      87: dup
      88: aload         7
      90: iload         6
      92: invokespecial #302                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      95: checkcast     #304                // class java/io/Closeable
      98: astore        5
     100: aconst_null
     101: astore        6
     103: nop
     104: aload         5
     106: checkcast     #299                // class java/io/BufferedReader
     109: astore        7
     111: iconst_0
     112: istore        8
     114: aload         7
     116: invokestatic  #310                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     119: astore        9
     121: iconst_0
     122: istore        10
     124: aload         9
     126: invokedynamic #330,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     131: invokestatic  #336                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     134: aload_1
     135: invokedynamic #345,  0            // InvokeDynamic #1:invoke:(Ljava/util/regex/Pattern;)Lkotlin/jvm/functions/Function1;
     140: invokestatic  #348                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     143: invokestatic  #351                // Method kotlin/sequences/SequencesKt.toMutableList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     146: astore        7
     148: aload         5
     150: aload         6
     152: invokestatic  #357                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     155: aload         7
     157: goto          181
     160: astore        8
     162: aload         8
     164: astore        6
     166: aload         8
     168: athrow
     169: astore        8
     171: aload         5
     173: aload         6
     175: invokestatic  #357                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     178: aload         8
     180: athrow
     181: nop
     182: areturn
    Exception table:
       from    to  target type
         103   148   160   Class java/lang/Throwable
         103   148   169   any
         160   169   169   any
         169   171   169   any

  private static final boolean loadFile$lambda$16$lambda$11(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #377                // String line
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #379                // class java/lang/CharSequence
      11: invokestatic  #385                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
      14: ifne          21
      17: iconst_1
      18: goto          22
      21: iconst_0
      22: ireturn

  private static final java.util.List loadFile$lambda$16$lambda$15(java.util.regex.Pattern, java.lang.String);
    Code:
       0: aload_1
       1: ldc_w         #377                // String line
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: checkcast     #379                // class java/lang/CharSequence
      11: aload_0
      12: invokestatic  #388                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      15: aload_0
      16: iconst_0
      17: iconst_2
      18: aconst_null
      19: invokestatic  #392                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;Ljava/util/regex/Pattern;IILjava/lang/Object;)Ljava/util/List;
      22: checkcast     #29                 // class java/lang/Iterable
      25: astore_2
      26: nop
      27: iconst_0
      28: istore_3
      29: aload_2
      30: astore        4
      32: new           #40                 // class java/util/ArrayList
      35: dup
      36: aload_2
      37: bipush        10
      39: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      42: invokespecial #48                 // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #50                 // class java/util/Collection
      48: astore        5
      50: iconst_0
      51: istore        6
      53: aload         4
      55: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      60: astore        7
      62: aload         7
      64: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      69: ifeq          119
      72: aload         7
      74: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      79: astore        8
      81: aload         5
      83: aload         8
      85: checkcast     #372                // class java/lang/String
      88: astore        9
      90: astore        11
      92: iconst_0
      93: istore        10
      95: aload         9
      97: checkcast     #379                // class java/lang/CharSequence
     100: invokestatic  #396                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     103: invokevirtual #397                // Method java/lang/Object.toString:()Ljava/lang/String;
     106: nop
     107: aload         11
     109: swap
     110: invokeinterface #91,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     115: pop
     116: goto          62
     119: aload         5
     121: checkcast     #23                 // class java/util/List
     124: nop
     125: checkcast     #29                 // class java/lang/Iterable
     128: astore_2
     129: nop
     130: iconst_0
     131: istore_3
     132: aload_2
     133: astore        4
     135: new           #40                 // class java/util/ArrayList
     138: dup
     139: invokespecial #131                // Method java/util/ArrayList."<init>":()V
     142: checkcast     #50                 // class java/util/Collection
     145: astore        5
     147: iconst_0
     148: istore        6
     150: aload         4
     152: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     157: astore        7
     159: aload         7
     161: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     166: ifeq          221
     169: aload         7
     171: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     176: astore        8
     178: aload         8
     180: checkcast     #372                // class java/lang/String
     183: astore        9
     185: iconst_0
     186: istore        10
     188: aload         9
     190: checkcast     #379                // class java/lang/CharSequence
     193: invokestatic  #385                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
     196: ifne          203
     199: iconst_1
     200: goto          204
     203: iconst_0
     204: nop
     205: ifeq          159
     208: aload         5
     210: aload         8
     212: invokeinterface #91,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     217: pop
     218: goto          159
     221: aload         5
     223: checkcast     #23                 // class java/util/List
     226: nop
     227: checkcast     #29                 // class java/lang/Iterable
     230: astore_2
     231: nop
     232: iconst_0
     233: istore_3
     234: aload_2
     235: astore        4
     237: new           #40                 // class java/util/ArrayList
     240: dup
     241: aload_2
     242: bipush        10
     244: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     247: invokespecial #48                 // Method java/util/ArrayList."<init>":(I)V
     250: checkcast     #50                 // class java/util/Collection
     253: astore        5
     255: iconst_0
     256: istore        6
     258: aload         4
     260: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     265: astore        7
     267: aload         7
     269: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     274: ifeq          321
     277: aload         7
     279: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     284: astore        8
     286: aload         5
     288: aload         8
     290: checkcast     #372                // class java/lang/String
     293: astore        9
     295: astore        11
     297: iconst_0
     298: istore        10
     300: aload         9
     302: invokestatic  #401                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     305: nop
     306: invokestatic  #76                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     309: aload         11
     311: swap
     312: invokeinterface #91,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     317: pop
     318: goto          267
     321: aload         5
     323: checkcast     #23                 // class java/util/List
     326: nop
     327: checkcast     #50                 // class java/util/Collection
     330: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     333: areturn
}