package com.eugenenosenko.coding.problems.arrays.pair_with_sum_x

fun findPairSolution(arr: IntArray, sum: Int): IntArray {
    // sort array first from smallest to largest
    // you'll end up with an array [0,1,2,3,5,6]
    arr.sort()

    // create two pointers
    var left = 0
    var right = arr.size - 1

    while (left < right) {
        val rightV = arr[right]
        val leftV = arr[left]

        when {
            // for example,  sum is 7, result should be 1, 6
            // upon first iteration you'll compare numbers 0, 6
            // this will land you on the second case and increment left counter by one
            // next iteration will be between 1 and 6 which is what we're looking for

            // right value is too large
            leftV + rightV > sum -> right--
            // left value is too small
            leftV + rightV < sum -> left++
            // just right!
            leftV + rightV == sum -> return intArrayOf(leftV, rightV)
        }
    }
    return intArrayOf()
}

fun findPairOnceSolution(arr: IntArray, sum: Int): IntArray {
    val visited = HashSet<Int>()

    for (v in arr) {
        // calculate different, i.e. 17 - 7 = 10
        val tmp = sum - v

        if (visited.contains(tmp)) {
            return intArrayOf(tmp, v)
        }
        visited.add(v)
    }

    return intArrayOf()
}

Compiled from "FindPairWithSumXSolution.kt"
public final class com.eugenenosenko.coding.problems.arrays.pair_with_sum_x.FindPairWithSumXSolutionKt {
  public static final int[] findPairSolution(int[], int);
    Code:
       0: aload_0
       1: ldc           #9                  // String arr
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #21                 // Method kotlin/collections/ArraysKt.sort:([I)V
      10: iconst_0
      11: istore_2
      12: aload_0
      13: arraylength
      14: iconst_1
      15: isub
      16: istore_3
      17: iload_2
      18: iload_3
      19: if_icmpge     92
      22: aload_0
      23: iload_3
      24: iaload
      25: istore        4
      27: aload_0
      28: iload_2
      29: iaload
      30: istore        5
      32: nop
      33: iload         5
      35: iload         4
      37: iadd
      38: iload_1
      39: if_icmple     48
      42: iinc          3, -1
      45: goto          17
      48: iload         5
      50: iload         4
      52: iadd
      53: iload_1
      54: if_icmpge     63
      57: iinc          2, 1
      60: goto          17
      63: iload         5
      65: iload         4
      67: iadd
      68: iload_1
      69: if_icmpne     17
      72: iconst_2
      73: newarray       int
      75: astore        6
      77: aload         6
      79: iconst_0
      80: iload         5
      82: iastore
      83: aload         6
      85: iconst_1
      86: iload         4
      88: iastore
      89: aload         6
      91: areturn
      92: iconst_0
      93: newarray       int
      95: areturn

  public static final int[] findPairOnceSolution(int[], int);
    Code:
       0: aload_0
       1: ldc           #9                  // String arr
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #31                 // class java/util/HashSet
       9: dup
      10: invokespecial #35                 // Method java/util/HashSet."<init>":()V
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_0
      17: arraylength
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     85
      26: aload_0
      27: iload_3
      28: iaload
      29: istore        5
      31: iload_1
      32: iload         5
      34: isub
      35: istore        6
      37: aload_2
      38: iload         6
      40: invokestatic  #41                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      43: invokevirtual #45                 // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
      46: ifeq          69
      49: iconst_2
      50: newarray       int
      52: astore        7
      54: aload         7
      56: iconst_0
      57: iload         6
      59: iastore
      60: aload         7
      62: iconst_1
      63: iload         5
      65: iastore
      66: aload         7
      68: areturn
      69: aload_2
      70: iload         5
      72: invokestatic  #41                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      75: invokevirtual #48                 // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
      78: pop
      79: iinc          3, 1
      82: goto          20
      85: iconst_0
      86: newarray       int
      88: areturn
}


package day03

class Solution {

    fun solve(items: List<String>): Int {
        val sums = countArray(items)

        val target = items.size / 2
        val gammaRate = count(sums) { if (it < target) 0 else 1 }
        val epsilonRate = count(sums) { if (it < target) 1 else 0 }

        return gammaRate * epsilonRate
    }

    private fun countArray(items: List<String>): IntArray {
        val sums = IntArray(items[0].length)
        for (item in items) {
            item.split("")
                .filter { it.isNotEmpty() }
                .map { it.toInt() }
                .forEachIndexed { idx, value -> sums[idx] += value }
        }
        return sums
    }

    private fun count(sums: IntArray, transform: (Int) -> Int): Int {
        val str = sums.map { transform(it) }.joinToString("")
        return str.toInt(2)
    }

    fun getOxygenGeneratorRating(input: List<String>): Int {
        return filter(input) { value, moreCommon -> value == moreCommon }
    }

    fun getCO2ScrubberRating(input: List<String>): Int {
        return filter(input) { value, moreCommon -> value != moreCommon }
    }

    private fun filter(input:List<String>, predicate: (Int, Int) -> Boolean): Int {
        val filtered = input.toMutableList();
        for(i in 0..<input[0].length) {
            val sums = countArray(filtered)
            filtered.retainAll { predicate.invoke(it[i].toString().toInt(), moreCommon(sums[i], filtered)) }
            if (filtered.size == 1) {
                break
            }
        }

        return filtered[0].toInt(2)
    }

    private fun moreCommon(value: Int, input: List<String>): Int {
        val target = input.size / 2.0

        return if (value >= target) 1 else 0
    }

    fun solve2(input: List<String>): Int {
        return getCO2ScrubberRating(input) * getOxygenGeneratorRating(input)
    }
}

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

  public final int solve(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String items
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #26                 // Method countArray:(Ljava/util/List;)[I
      11: astore_2
      12: aload_1
      13: invokeinterface #32,  1           // InterfaceMethod java/util/List.size:()I
      18: iconst_2
      19: idiv
      20: istore_3
      21: aload_0
      22: aload_2
      23: iload_3
      24: invokedynamic #52,  0             // InvokeDynamic #0:invoke:(I)Lkotlin/jvm/functions/Function1;
      29: invokespecial #56                 // Method count:([ILkotlin/jvm/functions/Function1;)I
      32: istore        4
      34: aload_0
      35: aload_2
      36: iload_3
      37: invokedynamic #61,  0             // InvokeDynamic #1:invoke:(I)Lkotlin/jvm/functions/Function1;
      42: invokespecial #56                 // Method count:([ILkotlin/jvm/functions/Function1;)I
      45: istore        5
      47: iload         4
      49: iload         5
      51: imul
      52: ireturn

  private final int[] countArray(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: iconst_0
       2: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #75                 // class java/lang/String
      10: invokevirtual #78                 // Method java/lang/String.length:()I
      13: newarray       int
      15: astore_2
      16: aload_1
      17: invokeinterface #82,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      22: astore_3
      23: aload_3
      24: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifeq          372
      32: aload_3
      33: invokeinterface #92,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      38: checkcast     #75                 // class java/lang/String
      41: astore        4
      43: aload         4
      45: checkcast     #94                 // class java/lang/CharSequence
      48: iconst_1
      49: anewarray     #75                 // class java/lang/String
      52: astore        5
      54: aload         5
      56: iconst_0
      57: ldc           #96                 // String
      59: aastore
      60: aload         5
      62: iconst_0
      63: iconst_0
      64: bipush        6
      66: aconst_null
      67: invokestatic  #102                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      70: checkcast     #104                // class java/lang/Iterable
      73: astore        5
      75: nop
      76: iconst_0
      77: istore        6
      79: aload         5
      81: astore        7
      83: new           #106                // class java/util/ArrayList
      86: dup
      87: invokespecial #107                // Method java/util/ArrayList."<init>":()V
      90: checkcast     #109                // class java/util/Collection
      93: astore        8
      95: iconst_0
      96: istore        9
      98: aload         7
     100: invokeinterface #110,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     105: astore        10
     107: aload         10
     109: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     114: ifeq          171
     117: aload         10
     119: invokeinterface #92,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     124: astore        11
     126: aload         11
     128: checkcast     #75                 // class java/lang/String
     131: astore        12
     133: iconst_0
     134: istore        13
     136: aload         12
     138: checkcast     #94                 // class java/lang/CharSequence
     141: invokeinterface #111,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     146: ifle          153
     149: iconst_1
     150: goto          154
     153: iconst_0
     154: nop
     155: ifeq          107
     158: aload         8
     160: aload         11
     162: invokeinterface #115,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     167: pop
     168: goto          107
     171: aload         8
     173: checkcast     #28                 // class java/util/List
     176: nop
     177: checkcast     #104                // class java/lang/Iterable
     180: astore        5
     182: nop
     183: iconst_0
     184: istore        6
     186: aload         5
     188: astore        7
     190: new           #106                // class java/util/ArrayList
     193: dup
     194: aload         5
     196: bipush        10
     198: invokestatic  #121                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     201: invokespecial #124                // Method java/util/ArrayList."<init>":(I)V
     204: checkcast     #109                // class java/util/Collection
     207: astore        8
     209: iconst_0
     210: istore        9
     212: aload         7
     214: invokeinterface #110,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     219: astore        10
     221: aload         10
     223: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     228: ifeq          275
     231: aload         10
     233: invokeinterface #92,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     238: astore        11
     240: aload         8
     242: aload         11
     244: checkcast     #75                 // class java/lang/String
     247: astore        12
     249: astore        14
     251: iconst_0
     252: istore        13
     254: aload         12
     256: invokestatic  #130                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     259: nop
     260: invokestatic  #134                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     263: aload         14
     265: swap
     266: invokeinterface #115,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     271: pop
     272: goto          221
     275: aload         8
     277: checkcast     #28                 // class java/util/List
     280: nop
     281: checkcast     #104                // class java/lang/Iterable
     284: astore        5
     286: nop
     287: iconst_0
     288: istore        6
     290: iconst_0
     291: istore        7
     293: aload         5
     295: invokeinterface #110,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     300: astore        8
     302: aload         8
     304: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     309: ifeq          368
     312: aload         8
     314: invokeinterface #92,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     319: astore        9
     321: iload         7
     323: iinc          7, 1
     326: istore        10
     328: iload         10
     330: ifge          336
     333: invokestatic  #137                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     336: iload         10
     338: aload         9
     340: checkcast     #139                // class java/lang/Number
     343: invokevirtual #142                // Method java/lang/Number.intValue:()I
     346: istore        11
     348: istore        12
     350: iconst_0
     351: istore        13
     353: aload_2
     354: iload         12
     356: aload_2
     357: iload         12
     359: iaload
     360: iload         11
     362: iadd
     363: iastore
     364: nop
     365: goto          302
     368: nop
     369: goto          23
     372: aload_2
     373: areturn

  private final int count(int[], kotlin.jvm.functions.Function1<? super java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_1
       1: astore        4
       3: iconst_0
       4: istore        5
       6: aload         4
       8: astore        6
      10: new           #106                // class java/util/ArrayList
      13: dup
      14: aload         4
      16: arraylength
      17: invokespecial #124                // Method java/util/ArrayList."<init>":(I)V
      20: checkcast     #109                // class java/util/Collection
      23: astore        7
      25: iconst_0
      26: istore        8
      28: iconst_0
      29: istore        9
      31: aload         6
      33: arraylength
      34: istore        10
      36: iload         9
      38: iload         10
      40: if_icmpge     96
      43: aload         6
      45: iload         9
      47: iaload
      48: istore        11
      50: aload         7
      52: iload         11
      54: istore        12
      56: astore        14
      58: iconst_0
      59: istore        13
      61: aload_2
      62: iload         12
      64: invokestatic  #134                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: invokeinterface #174,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      72: checkcast     #139                // class java/lang/Number
      75: invokevirtual #142                // Method java/lang/Number.intValue:()I
      78: invokestatic  #134                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      81: aload         14
      83: swap
      84: invokeinterface #115,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      89: pop
      90: iinc          9, 1
      93: goto          36
      96: aload         7
      98: checkcast     #28                 // class java/util/List
     101: nop
     102: checkcast     #104                // class java/lang/Iterable
     105: ldc           #96                 // String
     107: checkcast     #94                 // class java/lang/CharSequence
     110: aconst_null
     111: aconst_null
     112: iconst_0
     113: aconst_null
     114: aconst_null
     115: bipush        62
     117: aconst_null
     118: invokestatic  #178                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     121: astore_3
     122: aload_3
     123: iconst_2
     124: invokestatic  #184                // Method kotlin/text/CharsKt.checkRadix:(I)I
     127: invokestatic  #187                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     130: ireturn

  public final int getOxygenGeneratorRating(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #194                // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokedynamic #206,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function2;
      13: invokespecial #210                // Method filter:(Ljava/util/List;Lkotlin/jvm/functions/Function2;)I
      16: ireturn

  public final int getCO2ScrubberRating(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #194                // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokedynamic #216,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function2;
      13: invokespecial #210                // Method filter:(Ljava/util/List;Lkotlin/jvm/functions/Function2;)I
      16: ireturn

  private final int filter(java.util.List<java.lang.String>, kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super java.lang.Integer, java.lang.Boolean>);
    Code:
       0: aload_1
       1: checkcast     #109                // class java/util/Collection
       4: invokestatic  #221                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
       7: astore_3
       8: iconst_0
       9: istore        4
      11: aload_1
      12: iconst_0
      13: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      18: checkcast     #75                 // class java/lang/String
      21: invokevirtual #78                 // Method java/lang/String.length:()I
      24: istore        5
      26: iload         4
      28: iload         5
      30: if_icmpge     76
      33: aload_0
      34: aload_3
      35: invokespecial #26                 // Method countArray:(Ljava/util/List;)[I
      38: astore        6
      40: aload_3
      41: aload_2
      42: iload         4
      44: aload_0
      45: aload         6
      47: aload_3
      48: invokedynamic #231,  0            // InvokeDynamic #4:invoke:(Lkotlin/jvm/functions/Function2;ILday03/Solution;[ILjava/util/List;)Lkotlin/jvm/functions/Function1;
      53: invokestatic  #235                // Method kotlin/collections/CollectionsKt.retainAll:(Ljava/util/List;Lkotlin/jvm/functions/Function1;)Z
      56: pop
      57: aload_3
      58: invokeinterface #32,  1           // InterfaceMethod java/util/List.size:()I
      63: iconst_1
      64: if_icmpne     70
      67: goto          76
      70: iinc          4, 1
      73: goto          26
      76: aload_3
      77: iconst_0
      78: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      83: checkcast     #75                 // class java/lang/String
      86: iconst_2
      87: invokestatic  #184                // Method kotlin/text/CharsKt.checkRadix:(I)I
      90: invokestatic  #187                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      93: ireturn

  private final int moreCommon(int, java.util.List<java.lang.String>);
    Code:
       0: aload_2
       1: invokeinterface #32,  1           // InterfaceMethod java/util/List.size:()I
       6: i2d
       7: ldc2_w        #243                // double 2.0d
      10: ddiv
      11: dstore_3
      12: iload_1
      13: i2d
      14: dload_3
      15: dcmpl
      16: iflt          23
      19: iconst_1
      20: goto          24
      23: iconst_0
      24: ireturn

  public final int solve2(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #194                // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokevirtual #248                // Method getCO2ScrubberRating:(Ljava/util/List;)I
      11: aload_0
      12: aload_1
      13: invokevirtual #250                // Method getOxygenGeneratorRating:(Ljava/util/List;)I
      16: imul
      17: ireturn

  private static final int solve$lambda$0(int, int);
    Code:
       0: iload_1
       1: iload_0
       2: if_icmpge     9
       5: iconst_0
       6: goto          10
       9: iconst_1
      10: ireturn

  private static final int solve$lambda$1(int, int);
    Code:
       0: iload_1
       1: iload_0
       2: if_icmpge     9
       5: iconst_1
       6: goto          10
       9: iconst_0
      10: ireturn

  private static final boolean getOxygenGeneratorRating$lambda$6(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: if_icmpne     9
       5: iconst_1
       6: goto          10
       9: iconst_0
      10: ireturn

  private static final boolean getCO2ScrubberRating$lambda$7(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: if_icmpeq     9
       5: iconst_1
       6: goto          10
       9: iconst_0
      10: ireturn

  private static final boolean filter$lambda$8(kotlin.jvm.functions.Function2, int, day03.Solution, int[], java.util.List, java.lang.String);
    Code:
       0: aload         5
       2: ldc           #252                // String it
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload         5
      10: iload_1
      11: invokevirtual #256                // Method java/lang/String.charAt:(I)C
      14: invokestatic  #259                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
      17: invokestatic  #130                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      20: invokestatic  #134                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: aload_2
      24: aload_3
      25: iload_1
      26: iaload
      27: aload         4
      29: invokespecial #261                // Method moreCommon:(ILjava/util/List;)I
      32: invokestatic  #134                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: invokeinterface #265,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      40: checkcast     #267                // class java/lang/Boolean
      43: invokevirtual #270                // Method java/lang/Boolean.booleanValue:()Z
      46: ireturn
}


package day02

class Solution {
    fun navigate(input: List<String>) =
        input.map { it.split(' ') }
            .map { Instruction(it[0], it[1].toInt()) }
            .fold(Result(0, 0)) { acc, instruction ->
                when (instruction.direction) {
                    "up" -> Result(acc.horizontal, acc.depth - instruction.distance)
                    "down" -> Result(acc.horizontal, acc.depth + instruction.distance)
                    "forward" -> Result(acc.horizontal + instruction.distance, acc.depth)
                    else -> throw IllegalArgumentException("Unknown direction: ${instruction.direction}")
                }
            }
            .calculateFinalValue()

    private data class Instruction(val direction: String, val distance: Int)

    private data class Result(val horizontal: Int, val depth: Int) {
        fun calculateFinalValue() = horizontal * depth
    }

    private data class Result2(val horizontal: Int, val depth: Int, val aim: Int = 0) {
        fun calculateFinalValue() = horizontal * depth

        fun process(instruction: Instruction): Result2 {
           return when (instruction.direction) {
                "up" -> UpCommand(instruction.distance)
                "down" -> DownCommand(instruction.distance)
                "forward" -> ForwardCommand(instruction.distance)
                else -> throw IllegalArgumentException("Unknown direction: ${instruction.direction}")
            }.process(this)
        }
    }

    private data class UpCommand(val distance: Int): Command {
        override fun process(state: Result2): Result2 {
            return Result2(state.horizontal, state.depth, state.aim - distance)
        }
    }

    private class DownCommand(val distance: Int): Command {
        override fun process(state: Result2): Result2 {
            return Result2(state.horizontal, state.depth, state.aim + distance)
        }
    }

    private class ForwardCommand(val distance: Int): Command {
        override fun process(state: Result2): Result2 {
            return Result2(state.horizontal + distance, state.depth + state.aim * distance, state.aim)
        }
    }

    private interface Command {
        fun process(state: Result2): Result2
    }

    fun navigate2(input: List<String>) =
        input.map { it.split(' ') }
            .map { Instruction(it[0], it[1].toInt()) }
            .fold(Result2(0, 0, 0)) { acc, instruction -> acc.process(instruction) }
            .calculateFinalValue()
}

Compiled from "Solution.kt"
final class day02.Solution$Result2 {
  private final int horizontal;

  private final int depth;

  private final int aim;

  public day02.Solution$Result2(int, int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field horizontal:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field depth:I
      14: aload_0
      15: iload_3
      16: putfield      #19                 // Field aim:I
      19: return

  public day02.Solution$Result2(int, int, int, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         4
       2: iconst_4
       3: iand
       4: ifeq          9
       7: iconst_0
       8: istore_3
       9: aload_0
      10: iload_1
      11: iload_2
      12: iload_3
      13: invokespecial #24                 // Method "<init>":(III)V
      16: return

  public final int getHorizontal();
    Code:
       0: aload_0
       1: getfield      #13                 // Field horizontal:I
       4: ireturn

  public final int getDepth();
    Code:
       0: aload_0
       1: getfield      #16                 // Field depth:I
       4: ireturn

  public final int getAim();
    Code:
       0: aload_0
       1: getfield      #19                 // Field aim:I
       4: ireturn

  public final int calculateFinalValue();
    Code:
       0: aload_0
       1: getfield      #13                 // Field horizontal:I
       4: aload_0
       5: getfield      #16                 // Field depth:I
       8: imul
       9: ireturn

  public final day02.Solution$Result2 process(day02.Solution$Instruction);
    Code:
       0: aload_1
       1: ldc           #34                 // String instruction
       3: invokestatic  #40                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokevirtual #46                 // Method day02/Solution$Instruction.getDirection:()Ljava/lang/String;
      10: astore_2
      11: aload_2
      12: invokevirtual #51                 // Method java/lang/String.hashCode:()I
      15: lookupswitch  { // 3
            -677145915: 48
                  3739: 60
               3089570: 72
               default: 135
          }
      48: aload_2
      49: ldc           #53                 // String forward
      51: invokevirtual #57                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      54: ifne          118
      57: goto          135
      60: aload_2
      61: ldc           #59                 // String up
      63: invokevirtual #57                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      66: ifne          84
      69: goto          135
      72: aload_2
      73: ldc           #61                 // String down
      75: invokevirtual #57                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      78: ifne          101
      81: goto          135
      84: new           #63                 // class day02/Solution$UpCommand
      87: dup
      88: aload_1
      89: invokevirtual #66                 // Method day02/Solution$Instruction.getDistance:()I
      92: invokespecial #69                 // Method day02/Solution$UpCommand."<init>":(I)V
      95: checkcast     #71                 // class day02/Solution$Command
      98: goto          165
     101: new           #73                 // class day02/Solution$DownCommand
     104: dup
     105: aload_1
     106: invokevirtual #66                 // Method day02/Solution$Instruction.getDistance:()I
     109: invokespecial #74                 // Method day02/Solution$DownCommand."<init>":(I)V
     112: checkcast     #71                 // class day02/Solution$Command
     115: goto          165
     118: new           #76                 // class day02/Solution$ForwardCommand
     121: dup
     122: aload_1
     123: invokevirtual #66                 // Method day02/Solution$Instruction.getDistance:()I
     126: invokespecial #77                 // Method day02/Solution$ForwardCommand."<init>":(I)V
     129: checkcast     #71                 // class day02/Solution$Command
     132: goto          165
     135: new           #79                 // class java/lang/IllegalArgumentException
     138: dup
     139: new           #81                 // class java/lang/StringBuilder
     142: dup
     143: invokespecial #82                 // Method java/lang/StringBuilder."<init>":()V
     146: ldc           #84                 // String Unknown direction:
     148: invokevirtual #88                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     151: aload_1
     152: invokevirtual #46                 // Method day02/Solution$Instruction.getDirection:()Ljava/lang/String;
     155: invokevirtual #88                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     158: invokevirtual #91                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     161: invokespecial #94                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     164: athrow
     165: aload_0
     166: invokeinterface #97,  2           // InterfaceMethod day02/Solution$Command.process:(Lday02/Solution$Result2;)Lday02/Solution$Result2;
     171: areturn

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field horizontal:I
       4: ireturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #16                 // Field depth:I
       4: ireturn

  public final int component3();
    Code:
       0: aload_0
       1: getfield      #19                 // Field aim:I
       4: ireturn

  public final day02.Solution$Result2 copy(int, int, int);
    Code:
       0: new           #2                  // class day02/Solution$Result2
       3: dup
       4: iload_1
       5: iload_2
       6: iload_3
       7: invokespecial #24                 // Method "<init>":(III)V
      10: areturn

  public static day02.Solution$Result2 copy$default(day02.Solution$Result2, int, int, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #13                 // Field horizontal:I
      11: istore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #16                 // Field depth:I
      23: istore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #19                 // Field aim:I
      35: istore_3
      36: aload_0
      37: iload_1
      38: iload_2
      39: iload_3
      40: invokevirtual #107                // Method copy:(III)Lday02/Solution$Result2;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #81                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #82                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #109                // String Result2(horizontal=
       9: invokevirtual #88                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field horizontal:I
      16: invokevirtual #112                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #114                // String , depth=
      21: invokevirtual #88                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field depth:I
      28: invokevirtual #112                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #116                // String , aim=
      33: invokevirtual #88                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #19                 // Field aim:I
      40: invokevirtual #112                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #119                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #91                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field horizontal:I
       4: invokestatic  #124                // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field depth:I
      16: invokestatic  #124                // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #19                 // Field aim:I
      29: invokestatic  #124                // Method java/lang/Integer.hashCode:(I)I
      32: iadd
      33: istore_1
      34: iload_1
      35: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class day02/Solution$Result2
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class day02/Solution$Result2
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field horizontal:I
      25: aload_2
      26: getfield      #13                 // Field horizontal:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field depth:I
      38: aload_2
      39: getfield      #16                 // Field depth:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: getfield      #19                 // Field aim:I
      51: aload_2
      52: getfield      #19                 // Field aim:I
      55: if_icmpeq     60
      58: iconst_0
      59: ireturn
      60: iconst_1
      61: ireturn
}

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

  public final int navigate(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #24                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #26                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #35                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #37                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          117
      56: aload         7
      58: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #53                 // class java/lang/String
      72: astore        9
      74: astore        12
      76: iconst_0
      77: istore        10
      79: aload         9
      81: checkcast     #55                 // class java/lang/CharSequence
      84: iconst_1
      85: newarray       char
      87: astore        11
      89: aload         11
      91: iconst_0
      92: bipush        32
      94: castore
      95: aload         11
      97: iconst_0
      98: iconst_0
      99: bipush        6
     101: aconst_null
     102: invokestatic  #61                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     105: aload         12
     107: swap
     108: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     113: pop
     114: goto          46
     117: aload         5
     119: checkcast     #67                 // class java/util/List
     122: nop
     123: checkcast     #24                 // class java/lang/Iterable
     126: astore_2
     127: nop
     128: iconst_0
     129: istore_3
     130: aload_2
     131: astore        4
     133: new           #26                 // class java/util/ArrayList
     136: dup
     137: aload_2
     138: bipush        10
     140: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     143: invokespecial #35                 // Method java/util/ArrayList."<init>":(I)V
     146: checkcast     #37                 // class java/util/Collection
     149: astore        5
     151: iconst_0
     152: istore        6
     154: aload         4
     156: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     161: astore        7
     163: aload         7
     165: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     170: ifeq          240
     173: aload         7
     175: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     180: astore        8
     182: aload         5
     184: aload         8
     186: checkcast     #67                 // class java/util/List
     189: astore        9
     191: astore        12
     193: iconst_0
     194: istore        10
     196: new           #69                 // class day02/Solution$Instruction
     199: dup
     200: aload         9
     202: iconst_0
     203: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     208: checkcast     #53                 // class java/lang/String
     211: aload         9
     213: iconst_1
     214: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     219: checkcast     #53                 // class java/lang/String
     222: invokestatic  #79                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     225: invokespecial #82                 // Method day02/Solution$Instruction."<init>":(Ljava/lang/String;I)V
     228: aload         12
     230: swap
     231: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     236: pop
     237: goto          163
     240: aload         5
     242: checkcast     #67                 // class java/util/List
     245: nop
     246: checkcast     #24                 // class java/lang/Iterable
     249: astore_2
     250: new           #84                 // class day02/Solution$Result
     253: dup
     254: iconst_0
     255: iconst_0
     256: invokespecial #87                 // Method day02/Solution$Result."<init>":(II)V
     259: astore_3
     260: iconst_0
     261: istore        4
     263: aload_3
     264: astore        5
     266: aload_2
     267: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     272: astore        6
     274: aload         6
     276: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     281: ifeq          506
     284: aload         6
     286: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     291: astore        7
     293: aload         5
     295: aload         7
     297: checkcast     #69                 // class day02/Solution$Instruction
     300: astore        8
     302: astore        9
     304: iconst_0
     305: istore        10
     307: aload         8
     309: invokevirtual #91                 // Method day02/Solution$Instruction.getDirection:()Ljava/lang/String;
     312: astore        11
     314: aload         11
     316: invokevirtual #95                 // Method java/lang/String.hashCode:()I
     319: lookupswitch  { // 3
            -677145915: 352
                  3739: 365
               3089570: 378
               default: 469
          }
     352: aload         11
     354: ldc           #97                 // String forward
     356: invokevirtual #100                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     359: ifne          443
     362: goto          469
     365: aload         11
     367: ldc           #102                // String up
     369: invokevirtual #100                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     372: ifne          391
     375: goto          469
     378: aload         11
     380: ldc           #104                // String down
     382: invokevirtual #100                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     385: ifne          417
     388: goto          469
     391: new           #84                 // class day02/Solution$Result
     394: dup
     395: aload         9
     397: invokevirtual #107                // Method day02/Solution$Result.getHorizontal:()I
     400: aload         9
     402: invokevirtual #110                // Method day02/Solution$Result.getDepth:()I
     405: aload         8
     407: invokevirtual #113                // Method day02/Solution$Instruction.getDistance:()I
     410: isub
     411: invokespecial #87                 // Method day02/Solution$Result."<init>":(II)V
     414: goto          500
     417: new           #84                 // class day02/Solution$Result
     420: dup
     421: aload         9
     423: invokevirtual #107                // Method day02/Solution$Result.getHorizontal:()I
     426: aload         9
     428: invokevirtual #110                // Method day02/Solution$Result.getDepth:()I
     431: aload         8
     433: invokevirtual #113                // Method day02/Solution$Instruction.getDistance:()I
     436: iadd
     437: invokespecial #87                 // Method day02/Solution$Result."<init>":(II)V
     440: goto          500
     443: new           #84                 // class day02/Solution$Result
     446: dup
     447: aload         9
     449: invokevirtual #107                // Method day02/Solution$Result.getHorizontal:()I
     452: aload         8
     454: invokevirtual #113                // Method day02/Solution$Instruction.getDistance:()I
     457: iadd
     458: aload         9
     460: invokevirtual #110                // Method day02/Solution$Result.getDepth:()I
     463: invokespecial #87                 // Method day02/Solution$Result."<init>":(II)V
     466: goto          500
     469: new           #115                // class java/lang/IllegalArgumentException
     472: dup
     473: new           #117                // class java/lang/StringBuilder
     476: dup
     477: invokespecial #118                // Method java/lang/StringBuilder."<init>":()V
     480: ldc           #120                // String Unknown direction:
     482: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     485: aload         8
     487: invokevirtual #91                 // Method day02/Solution$Instruction.getDirection:()Ljava/lang/String;
     490: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     493: invokevirtual #127                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     496: invokespecial #130                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     499: athrow
     500: nop
     501: astore        5
     503: goto          274
     506: aload         5
     508: invokevirtual #133                // Method day02/Solution$Result.calculateFinalValue:()I
     511: ireturn

  public final int navigate2(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #24                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #26                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #35                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #37                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          117
      56: aload         7
      58: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #53                 // class java/lang/String
      72: astore        9
      74: astore        12
      76: iconst_0
      77: istore        10
      79: aload         9
      81: checkcast     #55                 // class java/lang/CharSequence
      84: iconst_1
      85: newarray       char
      87: astore        11
      89: aload         11
      91: iconst_0
      92: bipush        32
      94: castore
      95: aload         11
      97: iconst_0
      98: iconst_0
      99: bipush        6
     101: aconst_null
     102: invokestatic  #61                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     105: aload         12
     107: swap
     108: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     113: pop
     114: goto          46
     117: aload         5
     119: checkcast     #67                 // class java/util/List
     122: nop
     123: checkcast     #24                 // class java/lang/Iterable
     126: astore_2
     127: nop
     128: iconst_0
     129: istore_3
     130: aload_2
     131: astore        4
     133: new           #26                 // class java/util/ArrayList
     136: dup
     137: aload_2
     138: bipush        10
     140: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     143: invokespecial #35                 // Method java/util/ArrayList."<init>":(I)V
     146: checkcast     #37                 // class java/util/Collection
     149: astore        5
     151: iconst_0
     152: istore        6
     154: aload         4
     156: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     161: astore        7
     163: aload         7
     165: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     170: ifeq          240
     173: aload         7
     175: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     180: astore        8
     182: aload         5
     184: aload         8
     186: checkcast     #67                 // class java/util/List
     189: astore        9
     191: astore        12
     193: iconst_0
     194: istore        10
     196: new           #69                 // class day02/Solution$Instruction
     199: dup
     200: aload         9
     202: iconst_0
     203: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     208: checkcast     #53                 // class java/lang/String
     211: aload         9
     213: iconst_1
     214: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     219: checkcast     #53                 // class java/lang/String
     222: invokestatic  #79                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     225: invokespecial #82                 // Method day02/Solution$Instruction."<init>":(Ljava/lang/String;I)V
     228: aload         12
     230: swap
     231: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     236: pop
     237: goto          163
     240: aload         5
     242: checkcast     #67                 // class java/util/List
     245: nop
     246: checkcast     #24                 // class java/lang/Iterable
     249: astore_2
     250: new           #161                // class day02/Solution$Result2
     253: dup
     254: iconst_0
     255: iconst_0
     256: iconst_0
     257: invokespecial #164                // Method day02/Solution$Result2."<init>":(III)V
     260: astore_3
     261: iconst_0
     262: istore        4
     264: aload_3
     265: astore        5
     267: aload_2
     268: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     273: astore        6
     275: aload         6
     277: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     282: ifeq          320
     285: aload         6
     287: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     292: astore        7
     294: aload         5
     296: aload         7
     298: checkcast     #69                 // class day02/Solution$Instruction
     301: astore        8
     303: astore        9
     305: iconst_0
     306: istore        10
     308: aload         9
     310: aload         8
     312: invokevirtual #168                // Method day02/Solution$Result2.process:(Lday02/Solution$Instruction;)Lday02/Solution$Result2;
     315: astore        5
     317: goto          275
     320: aload         5
     322: invokevirtual #169                // Method day02/Solution$Result2.calculateFinalValue:()I
     325: ireturn
}

Compiled from "Solution.kt"
final class day02.Solution$DownCommand implements day02.Solution$Command {
  private final int distance;

  public day02.Solution$DownCommand(int);
    Code:
       0: aload_0
       1: invokespecial #11                 // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #15                 // Field distance:I
       9: return

  public final int getDistance();
    Code:
       0: aload_0
       1: getfield      #15                 // Field distance:I
       4: ireturn

  public day02.Solution$Result2 process(day02.Solution$Result2);
    Code:
       0: aload_1
       1: ldc           #24                 // String state
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #32                 // class day02/Solution$Result2
       9: dup
      10: aload_1
      11: invokevirtual #35                 // Method day02/Solution$Result2.getHorizontal:()I
      14: aload_1
      15: invokevirtual #38                 // Method day02/Solution$Result2.getDepth:()I
      18: aload_1
      19: invokevirtual #41                 // Method day02/Solution$Result2.getAim:()I
      22: aload_0
      23: getfield      #15                 // Field distance:I
      26: iadd
      27: invokespecial #44                 // Method day02/Solution$Result2."<init>":(III)V
      30: areturn
}

Compiled from "Solution.kt"
final class day02.Solution$UpCommand implements day02.Solution$Command {
  private final int distance;

  public day02.Solution$UpCommand(int);
    Code:
       0: aload_0
       1: invokespecial #11                 // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #15                 // Field distance:I
       9: return

  public final int getDistance();
    Code:
       0: aload_0
       1: getfield      #15                 // Field distance:I
       4: ireturn

  public day02.Solution$Result2 process(day02.Solution$Result2);
    Code:
       0: aload_1
       1: ldc           #24                 // String state
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #32                 // class day02/Solution$Result2
       9: dup
      10: aload_1
      11: invokevirtual #35                 // Method day02/Solution$Result2.getHorizontal:()I
      14: aload_1
      15: invokevirtual #38                 // Method day02/Solution$Result2.getDepth:()I
      18: aload_1
      19: invokevirtual #41                 // Method day02/Solution$Result2.getAim:()I
      22: aload_0
      23: getfield      #15                 // Field distance:I
      26: isub
      27: invokespecial #44                 // Method day02/Solution$Result2."<init>":(III)V
      30: areturn

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #15                 // Field distance:I
       4: ireturn

  public final day02.Solution$UpCommand copy(int);
    Code:
       0: new           #2                  // class day02/Solution$UpCommand
       3: dup
       4: iload_1
       5: invokespecial #50                 // Method "<init>":(I)V
       8: areturn

  public static day02.Solution$UpCommand copy$default(day02.Solution$UpCommand, int, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #15                 // Field distance:I
      10: istore_1
      11: aload_0
      12: iload_1
      13: invokevirtual #54                 // Method copy:(I)Lday02/Solution$UpCommand;
      16: areturn

  public java.lang.String toString();
    Code:
       0: new           #58                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #59                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #61                 // String UpCommand(distance=
       9: invokevirtual #65                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #15                 // Field distance:I
      16: invokevirtual #68                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: bipush        41
      21: invokevirtual #71                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      24: invokevirtual #73                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      27: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #15                 // Field distance:I
       4: invokestatic  #79                 // Method java/lang/Integer.hashCode:(I)I
       7: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class day02/Solution$UpCommand
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class day02/Solution$UpCommand
      20: astore_2
      21: aload_0
      22: getfield      #15                 // Field distance:I
      25: aload_2
      26: getfield      #15                 // Field distance:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: iconst_1
      35: ireturn
}

Compiled from "Solution.kt"
interface day02.Solution$Command {
  public abstract day02.Solution$Result2 process(day02.Solution$Result2);
}

Compiled from "Solution.kt"
final class day02.Solution$Instruction {
  private final java.lang.String direction;

  private final int distance;

  public day02.Solution$Instruction(java.lang.String, int);
    Code:
       0: aload_1
       1: ldc           #9                  // String direction
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #21                 // Field direction:Ljava/lang/String;
      15: aload_0
      16: iload_2
      17: putfield      #25                 // Field distance:I
      20: return

  public final java.lang.String getDirection();
    Code:
       0: aload_0
       1: getfield      #21                 // Field direction:Ljava/lang/String;
       4: areturn

  public final int getDistance();
    Code:
       0: aload_0
       1: getfield      #25                 // Field distance:I
       4: ireturn

  public final java.lang.String component1();
    Code:
       0: aload_0
       1: getfield      #21                 // Field direction:Ljava/lang/String;
       4: areturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #25                 // Field distance:I
       4: ireturn

  public final day02.Solution$Instruction copy(java.lang.String, int);
    Code:
       0: aload_1
       1: ldc           #9                  // String direction
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class day02/Solution$Instruction
       9: dup
      10: aload_1
      11: iload_2
      12: invokespecial #37                 // Method "<init>":(Ljava/lang/String;I)V
      15: areturn

  public static day02.Solution$Instruction copy$default(day02.Solution$Instruction, java.lang.String, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #21                 // Field direction:Ljava/lang/String;
      10: astore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #25                 // Field distance:I
      21: istore_2
      22: aload_0
      23: aload_1
      24: iload_2
      25: invokevirtual #41                 // Method copy:(Ljava/lang/String;I)Lday02/Solution$Instruction;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #44                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #45                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #47                 // String Instruction(direction=
       9: invokevirtual #51                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #21                 // Field direction:Ljava/lang/String;
      16: invokevirtual #51                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      19: ldc           #53                 // String , distance=
      21: invokevirtual #51                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #25                 // Field distance:I
      28: invokevirtual #56                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #59                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #21                 // Field direction:Ljava/lang/String;
       4: invokevirtual #66                 // Method java/lang/String.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #25                 // Field distance:I
      16: invokestatic  #71                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class day02/Solution$Instruction
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class day02/Solution$Instruction
      20: astore_2
      21: aload_0
      22: getfield      #21                 // Field direction:Ljava/lang/String;
      25: aload_2
      26: getfield      #21                 // Field direction:Ljava/lang/String;
      29: invokestatic  #79                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #25                 // Field distance:I
      41: aload_2
      42: getfield      #25                 // Field distance:I
      45: if_icmpeq     50
      48: iconst_0
      49: ireturn
      50: iconst_1
      51: ireturn
}

Compiled from "Solution.kt"
final class day02.Solution$ForwardCommand implements day02.Solution$Command {
  private final int distance;

  public day02.Solution$ForwardCommand(int);
    Code:
       0: aload_0
       1: invokespecial #11                 // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #15                 // Field distance:I
       9: return

  public final int getDistance();
    Code:
       0: aload_0
       1: getfield      #15                 // Field distance:I
       4: ireturn

  public day02.Solution$Result2 process(day02.Solution$Result2);
    Code:
       0: aload_1
       1: ldc           #24                 // String state
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #32                 // class day02/Solution$Result2
       9: dup
      10: aload_1
      11: invokevirtual #35                 // Method day02/Solution$Result2.getHorizontal:()I
      14: aload_0
      15: getfield      #15                 // Field distance:I
      18: iadd
      19: aload_1
      20: invokevirtual #38                 // Method day02/Solution$Result2.getDepth:()I
      23: aload_1
      24: invokevirtual #41                 // Method day02/Solution$Result2.getAim:()I
      27: aload_0
      28: getfield      #15                 // Field distance:I
      31: imul
      32: iadd
      33: aload_1
      34: invokevirtual #41                 // Method day02/Solution$Result2.getAim:()I
      37: invokespecial #44                 // Method day02/Solution$Result2."<init>":(III)V
      40: areturn
}

Compiled from "Solution.kt"
final class day02.Solution$Result {
  private final int horizontal;

  private final int depth;

  public day02.Solution$Result(int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field horizontal:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field depth:I
      14: return

  public final int getHorizontal();
    Code:
       0: aload_0
       1: getfield      #13                 // Field horizontal:I
       4: ireturn

  public final int getDepth();
    Code:
       0: aload_0
       1: getfield      #16                 // Field depth:I
       4: ireturn

  public final int calculateFinalValue();
    Code:
       0: aload_0
       1: getfield      #13                 // Field horizontal:I
       4: aload_0
       5: getfield      #16                 // Field depth:I
       8: imul
       9: ireturn

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field horizontal:I
       4: ireturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #16                 // Field depth:I
       4: ireturn

  public final day02.Solution$Result copy(int, int);
    Code:
       0: new           #2                  // class day02/Solution$Result
       3: dup
       4: iload_1
       5: iload_2
       6: invokespecial #29                 // Method "<init>":(II)V
       9: areturn

  public static day02.Solution$Result copy$default(day02.Solution$Result, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #13                 // Field horizontal:I
      10: istore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #16                 // Field depth:I
      21: istore_2
      22: aload_0
      23: iload_1
      24: iload_2
      25: invokevirtual #33                 // Method copy:(II)Lday02/Solution$Result;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #37                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #38                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #40                 // String Result(horizontal=
       9: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field horizontal:I
      16: invokevirtual #47                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #49                 // String , depth=
      21: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field depth:I
      28: invokevirtual #47                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #54                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field horizontal:I
       4: invokestatic  #60                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field depth:I
      16: invokestatic  #60                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class day02/Solution$Result
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class day02/Solution$Result
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field horizontal:I
      25: aload_2
      26: getfield      #13                 // Field horizontal:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field depth:I
      38: aload_2
      39: getfield      #16                 // Field depth:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: iconst_1
      48: ireturn
}


package processor

import kotlin.math.pow

class Matrix(private val matrix: Array<Array<Double>>) {

    companion object {
        fun empty(n: Int, m: Int = n): Matrix {
            require(n > 0)
            require(m > 0)
            return Matrix(Array(n) { Array(m) { 0.0 } })
        }
    }

    val sizesOfDimensions: IntArray
        get() {
            val n = matrix.size
            val m = matrix.firstOrNull()?.size ?: 0
            return intArrayOf(n, m)
        }

    operator fun get(n: Int, m: Int): Double = matrix[n][m]

    operator fun set(n: Int, m: Int, value: Double) {
        matrix[n][m] = value
    }

    fun swap(x1: Int, y1: Int, x2: Int, y2: Int) {
        val temp = this[x1, y1]
        this[x1, y1] = this[x2, y2]
        this[x2, y2] = temp
    }

    fun isSquare(): Boolean {
        val (x, y) = this.sizesOfDimensions
        return x == y
    }

    fun determinant(): Double {
        require(this.isSquare())
        val (n) = this.sizesOfDimensions
        return when {
            n == 1 -> this[0, 0]
            n == 2 -> (this[0, 0] * this[1, 1]) - (this[0, 1] * this[1, 0])
            n >= 3 -> {
                var res = 0.0
                repeat(n) {
                    res += this[0, it] * cofactor(0, it)
                }
                res
            }
            else -> 0.0
        }
    }

    private fun cofactor(x: Int, y: Int): Double {
        return (-1.0).pow(x + y) * subMatrixExcluding(x, y).determinant()
    }

    private fun subMatrixExcluding(xExclude: Int, yExclude: Int): Matrix {
        val (n, m) = this.sizesOfDimensions
        require(xExclude in 0 until n) { "Index out of range: $xExclude" }
        require(yExclude in 0 until m) { "Index out of range: $yExclude" }
        val result = empty(n - 1, m - 1)
        var i = 0
        for (x in 0 until n) {
            if (x == xExclude) {
                continue
            }
            var j = 0
            for (y in 0 until m) {
                if (y == yExclude) {
                    continue
                }
                result[i, j] = this[x, y]
                j++
            }
            i++
        }
        return result
    }

    fun toCofactorMatrix(): Matrix {
        require(isSquare())
        val (n) = sizesOfDimensions
        val result = empty(n)
        for (x in 0 until n) {
            for (y in 0 until n) {
                result[x, y] = cofactor(x, y)
            }
        }
        return result
    }
}

interface TransposeStrategy {
    companion object {
        fun byNumber(number: Int): TransposeStrategy = when (number) {
            1 -> MainDiagonalTransposeStrategy
            2 -> SideDiagonalTransposeStrategy
            3 -> VerticalLineTransposeStrategy
            4 -> HorizontalLineTransposeStrategy
            else -> NullTransposeStrategy
        }
    }

    fun transpose(matrix: Matrix)
}

object MainDiagonalTransposeStrategy : TransposeStrategy {
    override fun transpose(matrix: Matrix) {
        val (n, m) = matrix.sizesOfDimensions
        check(n == m)
        for (x in 0 until n) {
            for (y in 0 until x) {
                matrix.swap(x, y, y, x)
            }
        }
    }
}

object SideDiagonalTransposeStrategy : TransposeStrategy {
    override fun transpose(matrix: Matrix) {
        val (n, m) = matrix.sizesOfDimensions
        check(n == m)
        for (x in 0 until n) {
            for (y in (0 until m - x - 1)) {
                matrix.swap(x, y, n - 1 - y, m - 1 - x)
            }
        }
    }
}

object VerticalLineTransposeStrategy : TransposeStrategy {
    override fun transpose(matrix: Matrix) {
        val (n, m) = matrix.sizesOfDimensions
        check(n == m)
        for (x in 0 until n) {
            for (y in 0 until m / 2) {
                matrix.swap(x, y, x, m - 1 - y)
            }
        }
    }
}

object HorizontalLineTransposeStrategy : TransposeStrategy {
    override fun transpose(matrix: Matrix) {
        val (n, m) = matrix.sizesOfDimensions
        check(n == m)
        for (x in 0 until n / 2) {
            for (y in 0 until m) {
                matrix.swap(x, y, n - 1 - x, y)
            }
        }
    }
}

object NullTransposeStrategy : TransposeStrategy {
    override fun transpose(matrix: Matrix) {
    }
}

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

  public final processor.Matrix empty(int, int);
    Code:
       0: iload_1
       1: ifle          8
       4: iconst_1
       5: goto          9
       8: iconst_0
       9: ifne          29
      12: ldc           #15                 // String Failed requirement.
      14: astore        4
      16: new           #17                 // class java/lang/IllegalArgumentException
      19: dup
      20: aload         4
      22: invokevirtual #21                 // Method java/lang/Object.toString:()Ljava/lang/String;
      25: invokespecial #24                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      28: athrow
      29: iload_2
      30: ifle          37
      33: iconst_1
      34: goto          38
      37: iconst_0
      38: ifne          58
      41: ldc           #15                 // String Failed requirement.
      43: astore        4
      45: new           #17                 // class java/lang/IllegalArgumentException
      48: dup
      49: aload         4
      51: invokevirtual #21                 // Method java/lang/Object.toString:()Ljava/lang/String;
      54: invokespecial #24                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      57: athrow
      58: iconst_0
      59: istore_3
      60: iload_1
      61: anewarray     #26                 // class "[Ljava/lang/Double;"
      64: astore        4
      66: iload_3
      67: iload_1
      68: if_icmpge     129
      71: iload_3
      72: istore        5
      74: aload         4
      76: iload         5
      78: iconst_0
      79: istore        6
      81: iload_2
      82: anewarray     #28                 // class java/lang/Double
      85: astore        7
      87: istore        10
      89: astore        9
      91: iload         6
      93: iload_2
      94: if_icmpge     116
      97: iload         6
      99: istore        8
     101: aload         7
     103: iload         8
     105: dconst_0
     106: invokestatic  #32                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     109: aastore
     110: iinc          6, 1
     113: goto          91
     116: aload         9
     118: iload         10
     120: aload         7
     122: aastore
     123: iinc          3, 1
     126: goto          66
     129: aload         4
     131: astore        11
     133: new           #34                 // class processor/Matrix
     136: dup
     137: aload         11
     139: invokespecial #37                 // Method processor/Matrix."<init>":([[Ljava/lang/Double;)V
     142: areturn

  public static processor.Matrix empty$default(processor.Matrix$Companion, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iload_1
       7: istore_2
       8: aload_0
       9: iload_1
      10: iload_2
      11: invokevirtual #46                 // Method empty:(II)Lprocessor/Matrix;
      14: areturn

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

Compiled from "Matrix.kt"
public final class processor.Matrix {
  public static final processor.Matrix$Companion Companion;

  private final java.lang.Double[][] matrix;

  public processor.Matrix(java.lang.Double[][]);
    Code:
       0: aload_1
       1: ldc           #9                  // String matrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #21                 // Field matrix:[[Ljava/lang/Double;
      15: return

  public final int[] getSizesOfDimensions();
    Code:
       0: aload_0
       1: getfield      #21                 // Field matrix:[[Ljava/lang/Double;
       4: checkcast     #27                 // class "[Ljava/lang/Object;"
       7: arraylength
       8: istore_1
       9: aload_0
      10: getfield      #21                 // Field matrix:[[Ljava/lang/Double;
      13: checkcast     #27                 // class "[Ljava/lang/Object;"
      16: invokestatic  #33                 // Method kotlin/collections/ArraysKt.firstOrNull:([Ljava/lang/Object;)Ljava/lang/Object;
      19: checkcast     #35                 // class "[Ljava/lang/Double;"
      22: dup
      23: ifnull        30
      26: arraylength
      27: goto          32
      30: pop
      31: iconst_0
      32: istore_2
      33: iconst_2
      34: newarray       int
      36: astore_3
      37: aload_3
      38: iconst_0
      39: iload_1
      40: iastore
      41: aload_3
      42: iconst_1
      43: iload_2
      44: iastore
      45: aload_3
      46: areturn

  public final double get(int, int);
    Code:
       0: aload_0
       1: getfield      #21                 // Field matrix:[[Ljava/lang/Double;
       4: iload_1
       5: aaload
       6: iload_2
       7: aaload
       8: invokevirtual #46                 // Method java/lang/Double.doubleValue:()D
      11: dreturn

  public final void set(int, int, double);
    Code:
       0: aload_0
       1: getfield      #21                 // Field matrix:[[Ljava/lang/Double;
       4: iload_1
       5: aaload
       6: iload_2
       7: dload_3
       8: invokestatic  #52                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      11: aastore
      12: return

  public final void swap(int, int, int, int);
    Code:
       0: aload_0
       1: iload_1
       2: iload_2
       3: invokevirtual #58                 // Method get:(II)D
       6: dstore        5
       8: aload_0
       9: iload_1
      10: iload_2
      11: aload_0
      12: iload_3
      13: iload         4
      15: invokevirtual #58                 // Method get:(II)D
      18: invokevirtual #60                 // Method set:(IID)V
      21: aload_0
      22: iload_3
      23: iload         4
      25: dload         5
      27: invokevirtual #60                 // Method set:(IID)V
      30: return

  public final boolean isSquare();
    Code:
       0: aload_0
       1: invokevirtual #69                 // Method getSizesOfDimensions:()[I
       4: astore_1
       5: aload_1
       6: iconst_0
       7: iaload
       8: istore_2
       9: aload_1
      10: iconst_1
      11: iaload
      12: istore_3
      13: iload_2
      14: iload_3
      15: if_icmpne     22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ireturn

  public final double determinant();
    Code:
       0: aload_0
       1: invokevirtual #76                 // Method isSquare:()Z
       4: ifne          22
       7: ldc           #78                 // String Failed requirement.
       9: astore_1
      10: new           #80                 // class java/lang/IllegalArgumentException
      13: dup
      14: aload_1
      15: invokevirtual #84                 // Method java/lang/Object.toString:()Ljava/lang/String;
      18: invokespecial #87                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      21: athrow
      22: aload_0
      23: invokevirtual #69                 // Method getSizesOfDimensions:()[I
      26: iconst_0
      27: iaload
      28: istore_1
      29: nop
      30: iload_1
      31: iconst_1
      32: if_icmpne     44
      35: aload_0
      36: iconst_0
      37: iconst_0
      38: invokevirtual #58                 // Method get:(II)D
      41: goto          130
      44: iload_1
      45: iconst_2
      46: if_icmpne     79
      49: aload_0
      50: iconst_0
      51: iconst_0
      52: invokevirtual #58                 // Method get:(II)D
      55: aload_0
      56: iconst_1
      57: iconst_1
      58: invokevirtual #58                 // Method get:(II)D
      61: dmul
      62: aload_0
      63: iconst_0
      64: iconst_1
      65: invokevirtual #58                 // Method get:(II)D
      68: aload_0
      69: iconst_1
      70: iconst_0
      71: invokevirtual #58                 // Method get:(II)D
      74: dmul
      75: dsub
      76: goto          130
      79: iload_1
      80: iconst_3
      81: if_icmplt     129
      84: dconst_0
      85: dstore        5
      87: iconst_0
      88: istore_2
      89: iload_2
      90: iload_1
      91: if_icmpge     124
      94: iload_2
      95: istore_3
      96: iconst_0
      97: istore        4
      99: dload         5
     101: aload_0
     102: iconst_0
     103: iload_3
     104: invokevirtual #58                 // Method get:(II)D
     107: aload_0
     108: iconst_0
     109: iload_3
     110: invokespecial #90                 // Method cofactor:(II)D
     113: dmul
     114: dadd
     115: dstore        5
     117: nop
     118: iinc          2, 1
     121: goto          89
     124: dload         5
     126: goto          130
     129: dconst_0
     130: dreturn

  private final double cofactor(int, int);
    Code:
       0: ldc2_w        #94                 // double -1.0d
       3: iload_1
       4: iload_2
       5: iadd
       6: i2d
       7: invokestatic  #101                // Method java/lang/Math.pow:(DD)D
      10: aload_0
      11: iload_1
      12: iload_2
      13: invokespecial #105                // Method subMatrixExcluding:(II)Lprocessor/Matrix;
      16: invokevirtual #107                // Method determinant:()D
      19: dmul
      20: dreturn

  private final processor.Matrix subMatrixExcluding(int, int);
    Code:
       0: aload_0
       1: invokevirtual #69                 // Method getSizesOfDimensions:()[I
       4: astore_3
       5: aload_3
       6: iconst_0
       7: iaload
       8: istore        4
      10: aload_3
      11: iconst_1
      12: iaload
      13: istore        5
      15: iconst_0
      16: iload_1
      17: if_icmpgt     34
      20: iload_1
      21: iload         4
      23: if_icmpge     30
      26: iconst_1
      27: goto          35
      30: iconst_0
      31: goto          35
      34: iconst_0
      35: ifne          75
      38: iconst_0
      39: istore        7
      41: new           #109                // class java/lang/StringBuilder
      44: dup
      45: invokespecial #110                // Method java/lang/StringBuilder."<init>":()V
      48: ldc           #112                // String Index out of range:
      50: invokevirtual #116                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      53: iload_1
      54: invokevirtual #119                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      57: invokevirtual #120                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      60: astore        7
      62: new           #80                 // class java/lang/IllegalArgumentException
      65: dup
      66: aload         7
      68: invokevirtual #84                 // Method java/lang/Object.toString:()Ljava/lang/String;
      71: invokespecial #87                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      74: athrow
      75: iconst_0
      76: iload_2
      77: if_icmpgt     94
      80: iload_2
      81: iload         5
      83: if_icmpge     90
      86: iconst_1
      87: goto          95
      90: iconst_0
      91: goto          95
      94: iconst_0
      95: ifne          135
      98: iconst_0
      99: istore        7
     101: new           #109                // class java/lang/StringBuilder
     104: dup
     105: invokespecial #110                // Method java/lang/StringBuilder."<init>":()V
     108: ldc           #112                // String Index out of range:
     110: invokevirtual #116                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     113: iload_2
     114: invokevirtual #119                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     117: invokevirtual #120                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     120: astore        7
     122: new           #80                 // class java/lang/IllegalArgumentException
     125: dup
     126: aload         7
     128: invokevirtual #84                 // Method java/lang/Object.toString:()Ljava/lang/String;
     131: invokespecial #87                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     134: athrow
     135: getstatic     #124                // Field Companion:Lprocessor/Matrix$Companion;
     138: iload         4
     140: iconst_1
     141: isub
     142: iload         5
     144: iconst_1
     145: isub
     146: invokevirtual #129                // Method processor/Matrix$Companion.empty:(II)Lprocessor/Matrix;
     149: astore        6
     151: iconst_0
     152: istore        7
     154: iconst_0
     155: istore        8
     157: iload         8
     159: iload         4
     161: if_icmpge     230
     164: iload         8
     166: iload_1
     167: if_icmpne     173
     170: goto          224
     173: iconst_0
     174: istore        9
     176: iconst_0
     177: istore        10
     179: iload         10
     181: iload         5
     183: if_icmpge     221
     186: iload         10
     188: iload_2
     189: if_icmpne     195
     192: goto          215
     195: aload         6
     197: iload         7
     199: iload         9
     201: aload_0
     202: iload         8
     204: iload         10
     206: invokevirtual #58                 // Method get:(II)D
     209: invokevirtual #60                 // Method set:(IID)V
     212: iinc          9, 1
     215: iinc          10, 1
     218: goto          179
     221: iinc          7, 1
     224: iinc          8, 1
     227: goto          157
     230: aload         6
     232: areturn

  public final processor.Matrix toCofactorMatrix();
    Code:
       0: aload_0
       1: invokevirtual #76                 // Method isSquare:()Z
       4: ifne          22
       7: ldc           #78                 // String Failed requirement.
       9: astore_1
      10: new           #80                 // class java/lang/IllegalArgumentException
      13: dup
      14: aload_1
      15: invokevirtual #84                 // Method java/lang/Object.toString:()Ljava/lang/String;
      18: invokespecial #87                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      21: athrow
      22: aload_0
      23: invokevirtual #69                 // Method getSizesOfDimensions:()[I
      26: iconst_0
      27: iaload
      28: istore_1
      29: getstatic     #124                // Field Companion:Lprocessor/Matrix$Companion;
      32: iload_1
      33: iconst_0
      34: iconst_2
      35: aconst_null
      36: invokestatic  #142                // Method processor/Matrix$Companion.empty$default:(Lprocessor/Matrix$Companion;IIILjava/lang/Object;)Lprocessor/Matrix;
      39: astore_2
      40: iconst_0
      41: istore_3
      42: iload_3
      43: iload_1
      44: if_icmpge     82
      47: iconst_0
      48: istore        4
      50: iload         4
      52: iload_1
      53: if_icmpge     76
      56: aload_2
      57: iload_3
      58: iload         4
      60: aload_0
      61: iload_3
      62: iload         4
      64: invokespecial #90                 // Method cofactor:(II)D
      67: invokevirtual #60                 // Method set:(IID)V
      70: iinc          4, 1
      73: goto          50
      76: iinc          3, 1
      79: goto          42
      82: aload_2
      83: areturn

  static {};
    Code:
       0: new           #126                // class processor/Matrix$Companion
       3: dup
       4: aconst_null
       5: invokespecial #146                // Method processor/Matrix$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #124                // Field Companion:Lprocessor/Matrix$Companion;
      11: return
}