package com.leetcode.random_problems.easy.substract_product_and_sum

fun main() {
    println("SOLUTION 1")
    println("Test case 1:")
    println(Solution().subtractProductAndSum(234)) // 15
    println()

    println("Test case 2:")
    println(Solution().subtractProductAndSum(4421)) // 21
    println()

    println("SOLUTION 2")
    println("Test case 1:")
    println(Solution2().subtractProductAndSum(234)) // 15
    println()

    println("Test case 2:")
    println(Solution2().subtractProductAndSum(4421)) // 21
    println()
}

class Solution {
    fun subtractProductAndSum(n: Int): Int {
        val numbers = n.toString().toCharArray().map { it.toString().toInt() }

        var product = 1
        var sum = 0
        numbers.forEach { num ->
            product *= num
            sum += num
        }

        return product - sum
    }
}

class Solution2 {
    fun subtractProductAndSum(n: Int): Int {
        val numbers = n.toString().toCharArray().map { it.toString().toInt() }

        val product = numbers.reduce { acc, i -> acc * i }
        val sum = numbers.sum()

        return product - sum
    }
}

Compiled from "Main.kt"
public final class com.leetcode.random_problems.easy.substract_product_and_sum.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String SOLUTION 1
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: ldc           #22                 // String Test case 1:
      11: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: swap
      15: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      18: new           #24                 // class com/leetcode/random_problems/easy/substract_product_and_sum/Solution
      21: dup
      22: invokespecial #27                 // Method com/leetcode/random_problems/easy/substract_product_and_sum/Solution."<init>":()V
      25: sipush        234
      28: invokevirtual #31                 // Method com/leetcode/random_problems/easy/substract_product_and_sum/Solution.subtractProductAndSum:(I)I
      31: istore_0
      32: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      35: iload_0
      36: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
      39: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      42: invokevirtual #36                 // Method java/io/PrintStream.println:()V
      45: ldc           #38                 // String Test case 2:
      47: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      54: new           #24                 // class com/leetcode/random_problems/easy/substract_product_and_sum/Solution
      57: dup
      58: invokespecial #27                 // Method com/leetcode/random_problems/easy/substract_product_and_sum/Solution."<init>":()V
      61: sipush        4421
      64: invokevirtual #31                 // Method com/leetcode/random_problems/easy/substract_product_and_sum/Solution.subtractProductAndSum:(I)I
      67: istore_0
      68: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      71: iload_0
      72: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
      75: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      78: invokevirtual #36                 // Method java/io/PrintStream.println:()V
      81: ldc           #40                 // String SOLUTION 2
      83: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      86: swap
      87: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      90: ldc           #22                 // String Test case 1:
      92: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      95: swap
      96: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      99: new           #42                 // class com/leetcode/random_problems/easy/substract_product_and_sum/Solution2
     102: dup
     103: invokespecial #43                 // Method com/leetcode/random_problems/easy/substract_product_and_sum/Solution2."<init>":()V
     106: sipush        234
     109: invokevirtual #44                 // Method com/leetcode/random_problems/easy/substract_product_and_sum/Solution2.subtractProductAndSum:(I)I
     112: istore_0
     113: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     116: iload_0
     117: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
     120: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     123: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     126: ldc           #38                 // String Test case 2:
     128: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     131: swap
     132: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     135: new           #42                 // class com/leetcode/random_problems/easy/substract_product_and_sum/Solution2
     138: dup
     139: invokespecial #43                 // Method com/leetcode/random_problems/easy/substract_product_and_sum/Solution2."<init>":()V
     142: sipush        4421
     145: invokevirtual #44                 // Method com/leetcode/random_problems/easy/substract_product_and_sum/Solution2.subtractProductAndSum:(I)I
     148: istore_0
     149: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     152: iload_0
     153: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
     156: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     159: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     162: return

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


package com.leetcode.random_problems.easy.best_buy_sell_stock

fun main() {
    println("Test case 1:")
    println(Solution().maxProfit(intArrayOf(7, 1, 5, 3, 6, 4))) // 5
    println()

    println("Test case 2:")
    println(Solution().maxProfit(intArrayOf(7, 6, 4, 3, 1))) // 0
    println()

    println("Test case 3:")
    println(Solution().maxProfit(intArrayOf(2, 4, 1))) // 2
    println()

    println("Test case 4:")
    println(Solution().maxProfit(intArrayOf(1, 2, 3, 4, 5))) // 4
    println()

}

class Solution {
    fun maxProfit(prices: IntArray): Int {
        if (prices.isEmpty()) return 0
        var min = prices.first()
        var max = Short.MIN_VALUE.toInt()
        var maxProfit = 0

        prices.forEach {
            if (it < min) {
                min = Math.min(min, it)
                max = Short.MIN_VALUE.toInt()
            } else {
                max = Math.max(max, it)
            }

            maxProfit = Math.max(maxProfit, max - min)
        }

        return maxProfit
    }
}

Compiled from "Main.kt"
public final class com.leetcode.random_problems.easy.best_buy_sell_stock.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Test case 1:
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: new           #22                 // class com/leetcode/random_problems/easy/best_buy_sell_stock/Solution
      12: dup
      13: invokespecial #25                 // Method com/leetcode/random_problems/easy/best_buy_sell_stock/Solution."<init>":()V
      16: bipush        6
      18: newarray       int
      20: astore_0
      21: aload_0
      22: iconst_0
      23: bipush        7
      25: iastore
      26: aload_0
      27: iconst_1
      28: iconst_1
      29: iastore
      30: aload_0
      31: iconst_2
      32: iconst_5
      33: iastore
      34: aload_0
      35: iconst_3
      36: iconst_3
      37: iastore
      38: aload_0
      39: iconst_4
      40: bipush        6
      42: iastore
      43: aload_0
      44: iconst_5
      45: iconst_4
      46: iastore
      47: aload_0
      48: invokevirtual #29                 // Method com/leetcode/random_problems/easy/best_buy_sell_stock/Solution.maxProfit:([I)I
      51: istore_0
      52: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      55: iload_0
      56: invokevirtual #32                 // Method java/io/PrintStream.println:(I)V
      59: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: invokevirtual #34                 // Method java/io/PrintStream.println:()V
      65: ldc           #36                 // String Test case 2:
      67: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      70: swap
      71: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      74: new           #22                 // class com/leetcode/random_problems/easy/best_buy_sell_stock/Solution
      77: dup
      78: invokespecial #25                 // Method com/leetcode/random_problems/easy/best_buy_sell_stock/Solution."<init>":()V
      81: iconst_5
      82: newarray       int
      84: astore_0
      85: aload_0
      86: iconst_0
      87: bipush        7
      89: iastore
      90: aload_0
      91: iconst_1
      92: bipush        6
      94: iastore
      95: aload_0
      96: iconst_2
      97: iconst_4
      98: iastore
      99: aload_0
     100: iconst_3
     101: iconst_3
     102: iastore
     103: aload_0
     104: iconst_4
     105: iconst_1
     106: iastore
     107: aload_0
     108: invokevirtual #29                 // Method com/leetcode/random_problems/easy/best_buy_sell_stock/Solution.maxProfit:([I)I
     111: istore_0
     112: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     115: iload_0
     116: invokevirtual #32                 // Method java/io/PrintStream.println:(I)V
     119: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     122: invokevirtual #34                 // Method java/io/PrintStream.println:()V
     125: ldc           #38                 // String Test case 3:
     127: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     130: swap
     131: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     134: new           #22                 // class com/leetcode/random_problems/easy/best_buy_sell_stock/Solution
     137: dup
     138: invokespecial #25                 // Method com/leetcode/random_problems/easy/best_buy_sell_stock/Solution."<init>":()V
     141: iconst_3
     142: newarray       int
     144: astore_0
     145: aload_0
     146: iconst_0
     147: iconst_2
     148: iastore
     149: aload_0
     150: iconst_1
     151: iconst_4
     152: iastore
     153: aload_0
     154: iconst_2
     155: iconst_1
     156: iastore
     157: aload_0
     158: invokevirtual #29                 // Method com/leetcode/random_problems/easy/best_buy_sell_stock/Solution.maxProfit:([I)I
     161: istore_0
     162: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     165: iload_0
     166: invokevirtual #32                 // Method java/io/PrintStream.println:(I)V
     169: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     172: invokevirtual #34                 // Method java/io/PrintStream.println:()V
     175: ldc           #40                 // String Test case 4:
     177: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     180: swap
     181: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     184: new           #22                 // class com/leetcode/random_problems/easy/best_buy_sell_stock/Solution
     187: dup
     188: invokespecial #25                 // Method com/leetcode/random_problems/easy/best_buy_sell_stock/Solution."<init>":()V
     191: iconst_5
     192: newarray       int
     194: astore_0
     195: aload_0
     196: iconst_0
     197: iconst_1
     198: iastore
     199: aload_0
     200: iconst_1
     201: iconst_2
     202: iastore
     203: aload_0
     204: iconst_2
     205: iconst_3
     206: iastore
     207: aload_0
     208: iconst_3
     209: iconst_4
     210: iastore
     211: aload_0
     212: iconst_4
     213: iconst_5
     214: iastore
     215: aload_0
     216: invokevirtual #29                 // Method com/leetcode/random_problems/easy/best_buy_sell_stock/Solution.maxProfit:([I)I
     219: istore_0
     220: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     223: iload_0
     224: invokevirtual #32                 // Method java/io/PrintStream.println:(I)V
     227: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     230: invokevirtual #34                 // Method java/io/PrintStream.println:()V
     233: return

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


package com.leetcode.random_problems.easy.roman_to_integer

fun main() {
    println("Test case 1:")
    println(Solution().romanToInt("III")) // 3
    println()

    println("Test case 2:")
    println(Solution().romanToInt("IV")) // 4
    println()

    println("Test case 3:")
    println(Solution().romanToInt("IX")) // 9
    println()

    println("Test case 4:")
    println(Solution().romanToInt("LVIII")) // 58 Explanation: L = 50, V= 5, III = 3.
    println()

    println("Test case 5:")
    println(Solution().romanToInt("MCMXCIV")) // 1994 Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
    println()

}

class Solution {

    val numberMap = mapOf(
        'I' to 1,
        'V' to 5,
        'X' to 10,
        'L' to 50,
        'C' to 100,
        'D' to 500,
        'M' to 1000
    )

    fun romanToInt(s: String): Int {
        var current: Int
        var previous = -1

        val operations = s.map { c ->
            current = numberMap[c] ?: throw IllegalArgumentException("Map doesnt contain $c")

            when {
                previous == -1 -> {
                    previous = current
                    +current
                }
                previous < current -> {
                    +(current - (previous * 2))
                }
                else -> {
                    previous = current
                    current
                }
            }
        }

        return operations.reduce { acc, i -> acc + i }
    }
}

Compiled from "Main.kt"
public final class com.leetcode.random_problems.easy.roman_to_integer.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Test case 1:
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: new           #22                 // class com/leetcode/random_problems/easy/roman_to_integer/Solution
      12: dup
      13: invokespecial #25                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution."<init>":()V
      16: ldc           #27                 // String III
      18: invokevirtual #31                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution.romanToInt:(Ljava/lang/String;)I
      21: istore_0
      22: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      25: iload_0
      26: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
      29: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      32: invokevirtual #36                 // Method java/io/PrintStream.println:()V
      35: ldc           #38                 // String Test case 2:
      37: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      40: swap
      41: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      44: new           #22                 // class com/leetcode/random_problems/easy/roman_to_integer/Solution
      47: dup
      48: invokespecial #25                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution."<init>":()V
      51: ldc           #40                 // String IV
      53: invokevirtual #31                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution.romanToInt:(Ljava/lang/String;)I
      56: istore_0
      57: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      60: iload_0
      61: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
      64: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      67: invokevirtual #36                 // Method java/io/PrintStream.println:()V
      70: ldc           #42                 // String Test case 3:
      72: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      75: swap
      76: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      79: new           #22                 // class com/leetcode/random_problems/easy/roman_to_integer/Solution
      82: dup
      83: invokespecial #25                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution."<init>":()V
      86: ldc           #44                 // String IX
      88: invokevirtual #31                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution.romanToInt:(Ljava/lang/String;)I
      91: istore_0
      92: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      95: iload_0
      96: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
      99: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     102: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     105: ldc           #46                 // String Test case 4:
     107: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     110: swap
     111: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     114: new           #22                 // class com/leetcode/random_problems/easy/roman_to_integer/Solution
     117: dup
     118: invokespecial #25                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution."<init>":()V
     121: ldc           #48                 // String LVIII
     123: invokevirtual #31                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution.romanToInt:(Ljava/lang/String;)I
     126: istore_0
     127: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     130: iload_0
     131: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
     134: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     137: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     140: ldc           #50                 // String Test case 5:
     142: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     145: swap
     146: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     149: new           #22                 // class com/leetcode/random_problems/easy/roman_to_integer/Solution
     152: dup
     153: invokespecial #25                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution."<init>":()V
     156: ldc           #52                 // String MCMXCIV
     158: invokevirtual #31                 // Method com/leetcode/random_problems/easy/roman_to_integer/Solution.romanToInt:(Ljava/lang/String;)I
     161: istore_0
     162: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     165: iload_0
     166: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
     169: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     172: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     175: return

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


package com.leetcode.random_problems.medium.atoi

fun main() {
    println("Test case 1:")
    println(Solution().myAtoi("42")) // 42
    println()

    println("Test case 2:")
    println(Solution().myAtoi("   -42")) // -42
    println()

    println("Test case 3:")
    println(Solution().myAtoi("4193 with words")) // 4193
    println()

    println("Test case 4:")
    println(Solution().myAtoi("-91283472332")) // -2147483648
    println()

    println("Test case 5:")
    println(Solution().myAtoi("words and 987")) // 0
    println()

    println("Test case 6:")
    println(Solution().myAtoi("3.14159")) // 3
    println()

    println("Test case 7:")
    println(Solution().myAtoi("+-12")) // 0
    println()

    println("Test case 8:")
    println(Solution().myAtoi(".1")) // 0
    println()

}

class Solution {
    fun myAtoi(s: String): Int {
        if (s.trim().isEmpty()) return 0
        val isPositive = s.trim().first() != '-'
        var firstDigit = true
        var finalNumb = ""
        val isFirstSign = s.trim().first() == '+' || s.trim().first() == '-'
        val drop = if (isFirstSign) 1 else 0

        s.trim().drop(drop).takeWhile { it.isDigit() }.toCharArray().forEach {
            if (!it.isDigit() && !it.isWhitespace() && firstDigit) {
                return 0
            } else if (it.isDigit() && firstDigit) {
                finalNumb += it
                firstDigit = false
            } else if (it.isDigit() && finalNumb.isNotEmpty()) {
                finalNumb += it
                if (finalNumb.toBigInteger() !in Int.MIN_VALUE.toBigInteger()..Int.MAX_VALUE.toBigInteger()) {
                    return if (isPositive) {
                        Int.MAX_VALUE
                    } else {
                        Int.MIN_VALUE
                    }
                }
            } else if (!it.isDigit() && finalNumb.isNotEmpty() && !firstDigit) {
                return if (isPositive) finalNumb.toInt() else finalNumb.toInt() * -1
            }
        }
        if (finalNumb.isEmpty()) finalNumb = "0"

        return if (isPositive) finalNumb.toInt() else finalNumb.toInt() * -1
    }
}

Compiled from "Main.kt"
public final class com.leetcode.random_problems.medium.atoi.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Test case 1:
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: new           #22                 // class com/leetcode/random_problems/medium/atoi/Solution
      12: dup
      13: invokespecial #25                 // Method com/leetcode/random_problems/medium/atoi/Solution."<init>":()V
      16: ldc           #27                 // String 42
      18: invokevirtual #31                 // Method com/leetcode/random_problems/medium/atoi/Solution.myAtoi:(Ljava/lang/String;)I
      21: istore_0
      22: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      25: iload_0
      26: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
      29: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      32: invokevirtual #36                 // Method java/io/PrintStream.println:()V
      35: ldc           #38                 // String Test case 2:
      37: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      40: swap
      41: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      44: new           #22                 // class com/leetcode/random_problems/medium/atoi/Solution
      47: dup
      48: invokespecial #25                 // Method com/leetcode/random_problems/medium/atoi/Solution."<init>":()V
      51: ldc           #40                 // String    -42
      53: invokevirtual #31                 // Method com/leetcode/random_problems/medium/atoi/Solution.myAtoi:(Ljava/lang/String;)I
      56: istore_0
      57: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      60: iload_0
      61: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
      64: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      67: invokevirtual #36                 // Method java/io/PrintStream.println:()V
      70: ldc           #42                 // String Test case 3:
      72: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      75: swap
      76: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      79: new           #22                 // class com/leetcode/random_problems/medium/atoi/Solution
      82: dup
      83: invokespecial #25                 // Method com/leetcode/random_problems/medium/atoi/Solution."<init>":()V
      86: ldc           #44                 // String 4193 with words
      88: invokevirtual #31                 // Method com/leetcode/random_problems/medium/atoi/Solution.myAtoi:(Ljava/lang/String;)I
      91: istore_0
      92: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      95: iload_0
      96: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
      99: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     102: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     105: ldc           #46                 // String Test case 4:
     107: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     110: swap
     111: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     114: new           #22                 // class com/leetcode/random_problems/medium/atoi/Solution
     117: dup
     118: invokespecial #25                 // Method com/leetcode/random_problems/medium/atoi/Solution."<init>":()V
     121: ldc           #48                 // String -91283472332
     123: invokevirtual #31                 // Method com/leetcode/random_problems/medium/atoi/Solution.myAtoi:(Ljava/lang/String;)I
     126: istore_0
     127: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     130: iload_0
     131: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
     134: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     137: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     140: ldc           #50                 // String Test case 5:
     142: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     145: swap
     146: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     149: new           #22                 // class com/leetcode/random_problems/medium/atoi/Solution
     152: dup
     153: invokespecial #25                 // Method com/leetcode/random_problems/medium/atoi/Solution."<init>":()V
     156: ldc           #52                 // String words and 987
     158: invokevirtual #31                 // Method com/leetcode/random_problems/medium/atoi/Solution.myAtoi:(Ljava/lang/String;)I
     161: istore_0
     162: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     165: iload_0
     166: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
     169: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     172: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     175: ldc           #54                 // String Test case 6:
     177: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     180: swap
     181: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     184: new           #22                 // class com/leetcode/random_problems/medium/atoi/Solution
     187: dup
     188: invokespecial #25                 // Method com/leetcode/random_problems/medium/atoi/Solution."<init>":()V
     191: ldc           #56                 // String 3.14159
     193: invokevirtual #31                 // Method com/leetcode/random_problems/medium/atoi/Solution.myAtoi:(Ljava/lang/String;)I
     196: istore_0
     197: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     200: iload_0
     201: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
     204: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     207: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     210: ldc           #58                 // String Test case 7:
     212: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     215: swap
     216: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     219: new           #22                 // class com/leetcode/random_problems/medium/atoi/Solution
     222: dup
     223: invokespecial #25                 // Method com/leetcode/random_problems/medium/atoi/Solution."<init>":()V
     226: ldc           #60                 // String +-12
     228: invokevirtual #31                 // Method com/leetcode/random_problems/medium/atoi/Solution.myAtoi:(Ljava/lang/String;)I
     231: istore_0
     232: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     235: iload_0
     236: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
     239: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     242: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     245: ldc           #62                 // String Test case 8:
     247: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     250: swap
     251: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     254: new           #22                 // class com/leetcode/random_problems/medium/atoi/Solution
     257: dup
     258: invokespecial #25                 // Method com/leetcode/random_problems/medium/atoi/Solution."<init>":()V
     261: ldc           #64                 // String .1
     263: invokevirtual #31                 // Method com/leetcode/random_problems/medium/atoi/Solution.myAtoi:(Ljava/lang/String;)I
     266: istore_0
     267: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     270: iload_0
     271: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
     274: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     277: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     280: return

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


package day4

import java.io.File

data class Board(val numbers: Map<Int, Pair<Int, Int>>) {
    private val rows = numbers.values.maxOf { it.first } + 1
    private val cols = numbers.values.maxOf { it.second } + 1
    private val matches = mutableListOf<Int>()
    private val rowCounts = MutableList(rows) { 0 }
    private val colCounts = MutableList(cols) { 0 }

    fun play(number: Int): Boolean {
        val coords = numbers[number]
        if (coords != null) {
            matches.add(number)
            rowCounts[coords.first] += 1
            colCounts[coords.second] += 1
            return rowCounts[coords.first] == rows || colCounts[coords.second] == cols
        }
        return false
    }

    fun score() = (numbers.keys.sum() - matches.sum()) * matches.last()
}

fun main() {
    val parts = File("src/day4/input.txt").readText().split("\n\n")
    val numbers = parts[0].split(",").map { it.toInt() }
    var boards = parts.subList(1, parts.size).map { it.readBoard() }

    val scores = mutableListOf<Int>()
    for (number in numbers) {
        val newBoards = mutableListOf<Board>()
        for (board in boards) {
            if (board.play(number)) {
                scores += board.score()
            } else {
                newBoards += board
            }
        }
        boards = newBoards
    }

    println(scores.first())
    println(scores.last())
}

fun String.readBoard() : Board {
    val numbers = mutableMapOf<Int, Pair<Int, Int>>()
    for ((row, line) in this.lines().withIndex()) {
        numbers.putAll(line.split(" ")
            .filter { it.isNotEmpty() }
            .map { it.toInt() }
            .mapIndexed { col, number -> number to Pair(row, col) })
    }
    return Board(numbers)
}

Compiled from "result.kt"
public final class day4.ResultKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/day4/input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: checkcast     #22                 // class java/lang/CharSequence
      18: iconst_1
      19: anewarray     #24                 // class java/lang/String
      22: astore_1
      23: aload_1
      24: iconst_0
      25: ldc           #26                 // String \n\n
      27: aastore
      28: aload_1
      29: iconst_0
      30: iconst_0
      31: bipush        6
      33: aconst_null
      34: invokestatic  #32                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      37: astore_0
      38: aload_0
      39: iconst_0
      40: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      45: checkcast     #22                 // class java/lang/CharSequence
      48: iconst_1
      49: anewarray     #24                 // class java/lang/String
      52: astore_2
      53: aload_2
      54: iconst_0
      55: ldc           #40                 // String ,
      57: aastore
      58: aload_2
      59: iconst_0
      60: iconst_0
      61: bipush        6
      63: aconst_null
      64: invokestatic  #32                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      67: checkcast     #42                 // class java/lang/Iterable
      70: astore_2
      71: iconst_0
      72: istore_3
      73: aload_2
      74: astore        4
      76: new           #44                 // class java/util/ArrayList
      79: dup
      80: aload_2
      81: bipush        10
      83: invokestatic  #50                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      86: invokespecial #53                 // Method java/util/ArrayList."<init>":(I)V
      89: checkcast     #55                 // class java/util/Collection
      92: astore        5
      94: iconst_0
      95: istore        6
      97: aload         4
      99: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     104: astore        7
     106: aload         7
     108: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     113: ifeq          160
     116: aload         7
     118: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     123: astore        8
     125: aload         5
     127: aload         8
     129: checkcast     #24                 // class java/lang/String
     132: astore        9
     134: astore        12
     136: iconst_0
     137: istore        10
     139: aload         9
     141: invokestatic  #75                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     144: nop
     145: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     148: aload         12
     150: swap
     151: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     156: pop
     157: goto          106
     160: aload         5
     162: checkcast     #34                 // class java/util/List
     165: nop
     166: astore_1
     167: aload_0
     168: iconst_1
     169: aload_0
     170: invokeinterface #87,  1           // InterfaceMethod java/util/List.size:()I
     175: invokeinterface #91,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     180: checkcast     #42                 // class java/lang/Iterable
     183: astore_3
     184: iconst_0
     185: istore        4
     187: aload_3
     188: astore        5
     190: new           #44                 // class java/util/ArrayList
     193: dup
     194: aload_3
     195: bipush        10
     197: invokestatic  #50                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     200: invokespecial #53                 // Method java/util/ArrayList."<init>":(I)V
     203: checkcast     #55                 // class java/util/Collection
     206: astore        6
     208: iconst_0
     209: istore        7
     211: aload         5
     213: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     218: astore        8
     220: aload         8
     222: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     227: ifeq          270
     230: aload         8
     232: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     237: astore        9
     239: aload         6
     241: aload         9
     243: checkcast     #24                 // class java/lang/String
     246: astore        10
     248: astore        12
     250: iconst_0
     251: istore        11
     253: aload         10
     255: invokestatic  #95                 // Method readBoard:(Ljava/lang/String;)Lday4/Board;
     258: aload         12
     260: swap
     261: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     266: pop
     267: goto          220
     270: aload         6
     272: checkcast     #34                 // class java/util/List
     275: nop
     276: astore_2
     277: new           #44                 // class java/util/ArrayList
     280: dup
     281: invokespecial #97                 // Method java/util/ArrayList."<init>":()V
     284: checkcast     #34                 // class java/util/List
     287: astore_3
     288: aload_1
     289: invokeinterface #98,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     294: astore        4
     296: aload         4
     298: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     303: ifeq          416
     306: aload         4
     308: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     313: checkcast     #100                // class java/lang/Number
     316: invokevirtual #103                // Method java/lang/Number.intValue:()I
     319: istore        5
     321: new           #44                 // class java/util/ArrayList
     324: dup
     325: invokespecial #97                 // Method java/util/ArrayList."<init>":()V
     328: checkcast     #34                 // class java/util/List
     331: astore        6
     333: aload_2
     334: invokeinterface #98,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     339: astore        7
     341: aload         7
     343: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     348: ifeq          410
     351: aload         7
     353: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     358: checkcast     #105                // class day4/Board
     361: astore        8
     363: aload         8
     365: iload         5
     367: invokevirtual #109                // Method day4/Board.play:(I)Z
     370: ifeq          394
     373: aload_3
     374: checkcast     #55                 // class java/util/Collection
     377: aload         8
     379: invokevirtual #112                // Method day4/Board.score:()I
     382: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     385: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     390: pop
     391: goto          341
     394: aload         6
     396: checkcast     #55                 // class java/util/Collection
     399: aload         8
     401: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     406: pop
     407: goto          341
     410: aload         6
     412: astore_2
     413: goto          296
     416: aload_3
     417: invokestatic  #116                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     420: checkcast     #100                // class java/lang/Number
     423: invokevirtual #103                // Method java/lang/Number.intValue:()I
     426: istore        4
     428: getstatic     #122                // Field java/lang/System.out:Ljava/io/PrintStream;
     431: iload         4
     433: invokevirtual #127                // Method java/io/PrintStream.println:(I)V
     436: aload_3
     437: invokestatic  #130                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     440: checkcast     #100                // class java/lang/Number
     443: invokevirtual #103                // Method java/lang/Number.intValue:()I
     446: istore        4
     448: getstatic     #122                // Field java/lang/System.out:Ljava/io/PrintStream;
     451: iload         4
     453: invokevirtual #127                // Method java/io/PrintStream.println:(I)V
     456: return

  public static final day4.Board readBoard(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #158                // String <this>
       3: invokestatic  #164                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #166                // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #167                // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #169                // class java/util/Map
      16: astore_1
      17: aload_0
      18: checkcast     #22                 // class java/lang/CharSequence
      21: invokestatic  #173                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      24: checkcast     #42                 // class java/lang/Iterable
      27: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      32: astore_2
      33: iconst_0
      34: istore_3
      35: aload_2
      36: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          467
      44: iload_3
      45: istore        4
      47: iload_3
      48: iconst_1
      49: iadd
      50: istore_3
      51: aload_2
      52: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: checkcast     #24                 // class java/lang/String
      60: astore        5
      62: aload_1
      63: aload         5
      65: checkcast     #22                 // class java/lang/CharSequence
      68: iconst_1
      69: anewarray     #24                 // class java/lang/String
      72: astore        6
      74: aload         6
      76: iconst_0
      77: ldc           #175                // String
      79: aastore
      80: aload         6
      82: iconst_0
      83: iconst_0
      84: bipush        6
      86: aconst_null
      87: invokestatic  #32                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      90: checkcast     #42                 // class java/lang/Iterable
      93: astore        6
      95: astore        18
      97: iconst_0
      98: istore        7
     100: aload         6
     102: astore        8
     104: new           #44                 // class java/util/ArrayList
     107: dup
     108: invokespecial #97                 // Method java/util/ArrayList."<init>":()V
     111: checkcast     #55                 // class java/util/Collection
     114: astore        9
     116: iconst_0
     117: istore        10
     119: aload         8
     121: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     126: astore        11
     128: aload         11
     130: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     135: ifeq          192
     138: aload         11
     140: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     145: astore        12
     147: aload         12
     149: checkcast     #24                 // class java/lang/String
     152: astore        13
     154: iconst_0
     155: istore        14
     157: aload         13
     159: checkcast     #22                 // class java/lang/CharSequence
     162: invokeinterface #178,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     167: ifle          174
     170: iconst_1
     171: goto          175
     174: iconst_0
     175: nop
     176: ifeq          128
     179: aload         9
     181: aload         12
     183: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     188: pop
     189: goto          128
     192: aload         9
     194: checkcast     #34                 // class java/util/List
     197: nop
     198: aload         18
     200: swap
     201: checkcast     #42                 // class java/lang/Iterable
     204: astore        6
     206: astore        18
     208: iconst_0
     209: istore        7
     211: aload         6
     213: astore        8
     215: new           #44                 // class java/util/ArrayList
     218: dup
     219: aload         6
     221: bipush        10
     223: invokestatic  #50                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     226: invokespecial #53                 // Method java/util/ArrayList."<init>":(I)V
     229: checkcast     #55                 // class java/util/Collection
     232: astore        9
     234: iconst_0
     235: istore        10
     237: aload         8
     239: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     244: astore        11
     246: aload         11
     248: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     253: ifeq          300
     256: aload         11
     258: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     263: astore        12
     265: aload         9
     267: aload         12
     269: checkcast     #24                 // class java/lang/String
     272: astore        13
     274: astore        19
     276: iconst_0
     277: istore        14
     279: aload         13
     281: invokestatic  #75                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     284: nop
     285: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     288: aload         19
     290: swap
     291: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     296: pop
     297: goto          246
     300: aload         9
     302: checkcast     #34                 // class java/util/List
     305: nop
     306: aload         18
     308: swap
     309: checkcast     #42                 // class java/lang/Iterable
     312: astore        6
     314: astore        18
     316: iconst_0
     317: istore        7
     319: aload         6
     321: astore        8
     323: new           #44                 // class java/util/ArrayList
     326: dup
     327: aload         6
     329: bipush        10
     331: invokestatic  #50                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     334: invokespecial #53                 // Method java/util/ArrayList."<init>":(I)V
     337: checkcast     #55                 // class java/util/Collection
     340: astore        9
     342: iconst_0
     343: istore        10
     345: iconst_0
     346: istore        11
     348: aload         8
     350: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     355: astore        12
     357: aload         12
     359: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     364: ifeq          449
     367: aload         12
     369: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     374: astore        13
     376: aload         9
     378: iload         11
     380: iinc          11, 1
     383: istore        14
     385: iload         14
     387: ifge          393
     390: invokestatic  #181                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     393: iload         14
     395: aload         13
     397: checkcast     #100                // class java/lang/Number
     400: invokevirtual #103                // Method java/lang/Number.intValue:()I
     403: istore        15
     405: istore        16
     407: astore        19
     409: iconst_0
     410: istore        17
     412: iload         15
     414: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     417: new           #183                // class kotlin/Pair
     420: dup
     421: iload         4
     423: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     426: iload         16
     428: invokestatic  #79                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     431: invokespecial #186                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     434: invokestatic  #192                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     437: aload         19
     439: swap
     440: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     445: pop
     446: goto          357
     449: aload         9
     451: checkcast     #34                 // class java/util/List
     454: nop
     455: aload         18
     457: swap
     458: checkcast     #42                 // class java/lang/Iterable
     461: invokestatic  #198                // Method kotlin/collections/MapsKt.putAll:(Ljava/util/Map;Ljava/lang/Iterable;)V
     464: goto          35
     467: new           #105                // class day4/Board
     470: dup
     471: aload_1
     472: invokespecial #201                // Method day4/Board."<init>":(Ljava/util/Map;)V
     475: areturn

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


package day3

import java.io.File
import kotlin.reflect.KFunction1

fun main() {
    val lines = File("src/day3/input.txt")
        .readLines()
        .map { line -> line.toList().map { char -> Character.getNumericValue(char) } }
    val columns = lines.transpose()
    println(columns.map { it.gamma() }.toDecimal() * columns.map { it.epsilon() }.toDecimal())
    println(filter(lines, List<Int>::gamma).toDecimal() * filter(lines, List<Int>::epsilon).toDecimal())
}

fun List<Int>.gamma() = if (sum() >= size / 2.0) 1 else 0
fun List<Int>.epsilon() = 1 - gamma()

fun List<Int>.toDecimal() = reduce { a, b -> a * 2 + b }
fun <T> List<List<T>>.transpose(): List<List<T>> = (first().indices).map { column(it) }
fun <T> List<List<T>>.column(index: Int): List<T> = fold(listOf()) { acc, row -> acc + row[index] }

fun filter(lines: List<List<Int>>, fn: KFunction1<List<Int>, Int>): List<Int> =
    lines.indices.fold(lines) { candidates, index ->
        if (candidates.size == 1) candidates
        else candidates.filter { line -> line[index] == fn(candidates.column(index)) } }.single()

Compiled from "result.kt"
public final class day3.ResultKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/day3/input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #22                 // class java/lang/Iterable
      18: astore_1
      19: nop
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #24                 // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #35                 // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          212
      63: aload         6
      65: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        7
      72: aload         4
      74: aload         7
      76: checkcast     #51                 // class java/lang/String
      79: astore        8
      81: astore        20
      83: iconst_0
      84: istore        9
      86: aload         8
      88: checkcast     #53                 // class java/lang/CharSequence
      91: invokestatic  #59                 // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
      94: checkcast     #22                 // class java/lang/Iterable
      97: astore        10
      99: iconst_0
     100: istore        11
     102: aload         10
     104: astore        12
     106: new           #24                 // class java/util/ArrayList
     109: dup
     110: aload         10
     112: bipush        10
     114: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     117: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     120: checkcast     #35                 // class java/util/Collection
     123: astore        13
     125: iconst_0
     126: istore        14
     128: aload         12
     130: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     135: astore        15
     137: aload         15
     139: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     144: ifeq          193
     147: aload         15
     149: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     154: astore        16
     156: aload         13
     158: aload         16
     160: checkcast     #61                 // class java/lang/Character
     163: invokevirtual #65                 // Method java/lang/Character.charValue:()C
     166: istore        17
     168: astore        18
     170: iconst_0
     171: istore        19
     173: iload         17
     175: invokestatic  #69                 // Method java/lang/Character.getNumericValue:(C)I
     178: invokestatic  #75                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     181: aload         18
     183: swap
     184: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     189: pop
     190: goto          137
     193: aload         13
     195: checkcast     #81                 // class java/util/List
     198: nop
     199: nop
     200: aload         20
     202: swap
     203: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     208: pop
     209: goto          53
     212: aload         4
     214: checkcast     #81                 // class java/util/List
     217: nop
     218: astore_0
     219: aload_0
     220: invokestatic  #85                 // Method transpose:(Ljava/util/List;)Ljava/util/List;
     223: astore_1
     224: aload_1
     225: checkcast     #22                 // class java/lang/Iterable
     228: astore_2
     229: iconst_0
     230: istore_3
     231: aload_2
     232: astore        4
     234: new           #24                 // class java/util/ArrayList
     237: dup
     238: aload_2
     239: bipush        10
     241: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     244: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     247: checkcast     #35                 // class java/util/Collection
     250: astore        5
     252: iconst_0
     253: istore        6
     255: aload         4
     257: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     262: astore        7
     264: aload         7
     266: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     271: ifeq          317
     274: aload         7
     276: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     281: astore        8
     283: aload         5
     285: aload         8
     287: checkcast     #81                 // class java/util/List
     290: astore        9
     292: astore        20
     294: iconst_0
     295: istore        10
     297: aload         9
     299: invokestatic  #89                 // Method gamma:(Ljava/util/List;)I
     302: invokestatic  #75                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     305: aload         20
     307: swap
     308: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     313: pop
     314: goto          264
     317: aload         5
     319: checkcast     #81                 // class java/util/List
     322: nop
     323: invokestatic  #92                 // Method toDecimal:(Ljava/util/List;)I
     326: aload_1
     327: checkcast     #22                 // class java/lang/Iterable
     330: astore_2
     331: istore        20
     333: iconst_0
     334: istore_3
     335: aload_2
     336: astore        4
     338: new           #24                 // class java/util/ArrayList
     341: dup
     342: aload_2
     343: bipush        10
     345: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     348: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     351: checkcast     #35                 // class java/util/Collection
     354: astore        5
     356: iconst_0
     357: istore        6
     359: aload         4
     361: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     366: astore        7
     368: aload         7
     370: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     375: ifeq          421
     378: aload         7
     380: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     385: astore        8
     387: aload         5
     389: aload         8
     391: checkcast     #81                 // class java/util/List
     394: astore        9
     396: astore        21
     398: iconst_0
     399: istore        10
     401: aload         9
     403: invokestatic  #95                 // Method epsilon:(Ljava/util/List;)I
     406: invokestatic  #75                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     409: aload         21
     411: swap
     412: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     417: pop
     418: goto          368
     421: aload         5
     423: checkcast     #81                 // class java/util/List
     426: nop
     427: astore        21
     429: iload         20
     431: aload         21
     433: invokestatic  #92                 // Method toDecimal:(Ljava/util/List;)I
     436: imul
     437: istore_2
     438: getstatic     #101                // Field java/lang/System.out:Ljava/io/PrintStream;
     441: iload_2
     442: invokevirtual #106                // Method java/io/PrintStream.println:(I)V
     445: aload_0
     446: getstatic     #112                // Field day3/ResultKt$main$3.INSTANCE:Lday3/ResultKt$main$3;
     449: checkcast     #114                // class kotlin/reflect/KFunction
     452: invokestatic  #118                // Method filter:(Ljava/util/List;Lkotlin/reflect/KFunction;)Ljava/util/List;
     455: invokestatic  #92                 // Method toDecimal:(Ljava/util/List;)I
     458: aload_0
     459: getstatic     #123                // Field day3/ResultKt$main$4.INSTANCE:Lday3/ResultKt$main$4;
     462: checkcast     #114                // class kotlin/reflect/KFunction
     465: invokestatic  #118                // Method filter:(Ljava/util/List;Lkotlin/reflect/KFunction;)Ljava/util/List;
     468: invokestatic  #92                 // Method toDecimal:(Ljava/util/List;)I
     471: imul
     472: istore_2
     473: getstatic     #101                // Field java/lang/System.out:Ljava/io/PrintStream;
     476: iload_2
     477: invokevirtual #106                // Method java/io/PrintStream.println:(I)V
     480: return

  public static final int gamma(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #149                // String <this>
       3: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #22                 // class java/lang/Iterable
      10: invokestatic  #159                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      13: i2d
      14: aload_0
      15: invokeinterface #163,  1          // InterfaceMethod java/util/List.size:()I
      20: i2d
      21: ldc2_w        #164                // double 2.0d
      24: ddiv
      25: dcmpl
      26: iflt          33
      29: iconst_1
      30: goto          34
      33: iconst_0
      34: ireturn

  public static final int epsilon(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #149                // String <this>
       3: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_1
       7: aload_0
       8: invokestatic  #89                 // Method gamma:(Ljava/util/List;)I
      11: isub
      12: ireturn

  public static final int toDecimal(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #149                // String <this>
       3: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #22                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifne          39
      29: new           #169                // class java/lang/UnsupportedOperationException
      32: dup
      33: ldc           #171                // String Empty collection can\'t be reduced.
      35: invokespecial #172                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
      38: athrow
      39: aload_3
      40: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      45: astore        4
      47: aload_3
      48: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          98
      56: aload         4
      58: aload_3
      59: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: checkcast     #174                // class java/lang/Number
      67: invokevirtual #177                // Method java/lang/Number.intValue:()I
      70: istore        5
      72: checkcast     #174                // class java/lang/Number
      75: invokevirtual #177                // Method java/lang/Number.intValue:()I
      78: istore        6
      80: iconst_0
      81: istore        7
      83: iload         6
      85: iconst_2
      86: imul
      87: iload         5
      89: iadd
      90: invokestatic  #75                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      93: astore        4
      95: goto          47
      98: aload         4
     100: checkcast     #174                // class java/lang/Number
     103: invokevirtual #177                // Method java/lang/Number.intValue:()I
     106: ireturn

  public static final <T> java.util.List<java.util.List<T>> transpose(java.util.List<? extends java.util.List<? extends T>>);
    Code:
       0: aload_0
       1: ldc           #149                // String <this>
       3: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #191                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      10: checkcast     #35                 // class java/util/Collection
      13: invokestatic  #195                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
      16: checkcast     #22                 // class java/lang/Iterable
      19: astore_1
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #24                 // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #35                 // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          102
      63: aload         6
      65: checkcast     #197                // class kotlin/collections/IntIterator
      68: invokevirtual #200                // Method kotlin/collections/IntIterator.nextInt:()I
      71: istore        7
      73: aload         4
      75: iload         7
      77: istore        8
      79: astore        10
      81: iconst_0
      82: istore        9
      84: aload_0
      85: iload         8
      87: invokestatic  #204                // Method column:(Ljava/util/List;I)Ljava/util/List;
      90: aload         10
      92: swap
      93: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      98: pop
      99: goto          53
     102: aload         4
     104: checkcast     #81                 // class java/util/List
     107: nop
     108: areturn

  public static final <T> java.util.List<T> column(java.util.List<? extends java.util.List<? extends T>>, int);
    Code:
       0: aload_0
       1: ldc           #149                // String <this>
       3: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #22                 // class java/lang/Iterable
      10: astore_2
      11: invokestatic  #211                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      14: astore_3
      15: nop
      16: iconst_0
      17: istore        4
      19: aload_3
      20: astore        5
      22: aload_2
      23: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      28: astore        6
      30: aload         6
      32: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      37: ifeq          84
      40: aload         6
      42: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      47: astore        7
      49: aload         5
      51: aload         7
      53: checkcast     #81                 // class java/util/List
      56: astore        8
      58: astore        9
      60: iconst_0
      61: istore        10
      63: aload         9
      65: checkcast     #35                 // class java/util/Collection
      68: aload         8
      70: iload_1
      71: invokeinterface #215,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      76: invokestatic  #219                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
      79: astore        5
      81: goto          30
      84: aload         5
      86: areturn

  public static final java.util.List<java.lang.Integer> filter(java.util.List<? extends java.util.List<java.lang.Integer>>, kotlin.reflect.KFunction<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #230                // String lines
       3: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #232                // String fn
       9: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #35                 // class java/util/Collection
      16: invokestatic  #195                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
      19: checkcast     #22                 // class java/lang/Iterable
      22: astore_2
      23: iconst_0
      24: istore_3
      25: aload_0
      26: astore        4
      28: aload_2
      29: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      34: astore        5
      36: aload         5
      38: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          223
      46: aload         5
      48: checkcast     #197                // class kotlin/collections/IntIterator
      51: invokevirtual #200                // Method kotlin/collections/IntIterator.nextInt:()I
      54: istore        6
      56: aload         4
      58: iload         6
      60: istore        7
      62: astore        8
      64: iconst_0
      65: istore        9
      67: aload         8
      69: invokeinterface #163,  1          // InterfaceMethod java/util/List.size:()I
      74: iconst_1
      75: if_icmpne     83
      78: aload         8
      80: goto          217
      83: aload         8
      85: checkcast     #22                 // class java/lang/Iterable
      88: astore        10
      90: iconst_0
      91: istore        11
      93: aload         10
      95: astore        12
      97: new           #24                 // class java/util/ArrayList
     100: dup
     101: invokespecial #234                // Method java/util/ArrayList."<init>":()V
     104: checkcast     #35                 // class java/util/Collection
     107: astore        13
     109: iconst_0
     110: istore        14
     112: aload         12
     114: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     119: astore        15
     121: aload         15
     123: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     128: ifeq          211
     131: aload         15
     133: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     138: astore        16
     140: aload         16
     142: checkcast     #81                 // class java/util/List
     145: astore        17
     147: iconst_0
     148: istore        18
     150: aload         17
     152: iload         7
     154: invokeinterface #215,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     159: checkcast     #174                // class java/lang/Number
     162: invokevirtual #177                // Method java/lang/Number.intValue:()I
     165: aload_1
     166: checkcast     #236                // class kotlin/jvm/functions/Function1
     169: aload         8
     171: iload         7
     173: invokestatic  #204                // Method column:(Ljava/util/List;I)Ljava/util/List;
     176: invokeinterface #240,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     181: checkcast     #174                // class java/lang/Number
     184: invokevirtual #177                // Method java/lang/Number.intValue:()I
     187: if_icmpne     194
     190: iconst_1
     191: goto          195
     194: iconst_0
     195: ifeq          121
     198: aload         13
     200: aload         16
     202: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     207: pop
     208: goto          121
     211: aload         13
     213: checkcast     #81                 // class java/util/List
     216: nop
     217: nop
     218: astore        4
     220: goto          36
     223: aload         4
     225: invokestatic  #243                // Method kotlin/collections/CollectionsKt.single:(Ljava/util/List;)Ljava/lang/Object;
     228: checkcast     #81                 // class java/util/List
     231: areturn

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

Compiled from "result.kt"
final class day3.ResultKt$main$3 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.util.List<? extends java.lang.Integer>, java.lang.Integer> {
  public static final day3.ResultKt$main$3 INSTANCE;

  day3.ResultKt$main$3();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day3/ResultKt
       4: ldc           #13                 // String gamma
       6: ldc           #15                 // String gamma(Ljava/util/List;)I
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Integer invoke(java.util.List<java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #25                 // String p0
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #34                 // Method day3/ResultKt.gamma:(Ljava/util/List;)I
      10: invokestatic  #40                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #44                 // class java/util/List
       5: invokevirtual #46                 // Method invoke:(Ljava/util/List;)Ljava/lang/Integer;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day3/ResultKt$main$3
       3: dup
       4: invokespecial #51                 // Method "<init>":()V
       7: putstatic     #54                 // Field INSTANCE:Lday3/ResultKt$main$3;
      10: return
}

Compiled from "result.kt"
final class day3.ResultKt$main$4 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.util.List<? extends java.lang.Integer>, java.lang.Integer> {
  public static final day3.ResultKt$main$4 INSTANCE;

  day3.ResultKt$main$4();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day3/ResultKt
       4: ldc           #13                 // String epsilon
       6: ldc           #15                 // String epsilon(Ljava/util/List;)I
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Integer invoke(java.util.List<java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #25                 // String p0
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #34                 // Method day3/ResultKt.epsilon:(Ljava/util/List;)I
      10: invokestatic  #40                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #44                 // class java/util/List
       5: invokevirtual #46                 // Method invoke:(Ljava/util/List;)Ljava/lang/Integer;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day3/ResultKt$main$4
       3: dup
       4: invokespecial #51                 // Method "<init>":()V
       7: putstatic     #54                 // Field INSTANCE:Lday3/ResultKt$main$4;
      10: return
}


package day2

import day2.Direction.*
import java.io.File
import java.util.*

fun main() {
    val moves = File("src/day2/input.txt")
        .readLines()
        .map { it.split(" ") }
        .map { Move(valueOf(it[0].uppercase(Locale.getDefault())), it[1].toInt()) }

    println(calculate(PartOneState(), moves))
    println(calculate(PartTwoState(), moves))
}

fun calculate(initialState: State, moves: List<Move>): Int {
    val finalState = moves.fold(initialState) { state, move -> state.transform(move) }
    return finalState.horizontal * finalState.depth
}

enum class Direction { UP, DOWN, FORWARD }
data class Move(val direction: Direction, val units: Int)
interface State {
    val horizontal: Int
    val depth: Int
    fun transform(move: Move): State
}

data class PartOneState(override val horizontal: Int = 0, override val depth: Int = 0) : State {
    override fun transform(move: Move): PartOneState {
        return when (move.direction) {
            UP -> copy(depth = depth - move.units)
            DOWN -> copy(depth = depth + move.units)
            FORWARD -> copy(horizontal = horizontal + move.units)
        }
    }
}

data class PartTwoState(override val horizontal: Int = 0, override val depth: Int = 0, val aim: Int = 0) : State {
    override fun transform(move: Move): PartTwoState {
        return when (move.direction) {
            UP -> copy(aim = aim - move.units)
            DOWN -> copy(aim = aim + move.units)
            FORWARD -> copy(horizontal = horizontal + move.units, depth = depth + aim * move.units)
        }
    }
}

Compiled from "result.kt"
public final class day2.ResultKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/day2/input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #22                 // class java/lang/Iterable
      18: astore_1
      19: nop
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #24                 // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #35                 // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          125
      63: aload         6
      65: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        7
      72: aload         4
      74: aload         7
      76: checkcast     #51                 // class java/lang/String
      79: astore        8
      81: astore        11
      83: iconst_0
      84: istore        9
      86: aload         8
      88: checkcast     #53                 // class java/lang/CharSequence
      91: iconst_1
      92: anewarray     #51                 // class java/lang/String
      95: astore        10
      97: aload         10
      99: iconst_0
     100: ldc           #55                 // String
     102: aastore
     103: aload         10
     105: iconst_0
     106: iconst_0
     107: bipush        6
     109: aconst_null
     110: invokestatic  #61                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     113: aload         11
     115: swap
     116: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          53
     125: aload         4
     127: checkcast     #67                 // class java/util/List
     130: nop
     131: checkcast     #22                 // class java/lang/Iterable
     134: astore_1
     135: nop
     136: iconst_0
     137: istore_2
     138: aload_1
     139: astore_3
     140: new           #24                 // class java/util/ArrayList
     143: dup
     144: aload_1
     145: bipush        10
     147: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     150: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     153: checkcast     #35                 // class java/util/Collection
     156: astore        4
     158: iconst_0
     159: istore        5
     161: aload_3
     162: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     167: astore        6
     169: aload         6
     171: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     176: ifeq          272
     179: aload         6
     181: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     186: astore        7
     188: aload         4
     190: aload         7
     192: checkcast     #67                 // class java/util/List
     195: astore        8
     197: astore        11
     199: iconst_0
     200: istore        9
     202: new           #69                 // class day2/Move
     205: dup
     206: aload         8
     208: iconst_0
     209: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     214: checkcast     #51                 // class java/lang/String
     217: astore        10
     219: invokestatic  #79                 // Method java/util/Locale.getDefault:()Ljava/util/Locale;
     222: dup
     223: ldc           #81                 // String getDefault(...)
     225: invokestatic  #87                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     228: aload         10
     230: swap
     231: invokevirtual #91                 // Method java/lang/String.toUpperCase:(Ljava/util/Locale;)Ljava/lang/String;
     234: dup
     235: ldc           #93                 // String toUpperCase(...)
     237: invokestatic  #87                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     240: invokestatic  #99                 // Method day2/Direction.valueOf:(Ljava/lang/String;)Lday2/Direction;
     243: aload         8
     245: iconst_1
     246: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     251: checkcast     #51                 // class java/lang/String
     254: invokestatic  #105                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     257: invokespecial #108                // Method day2/Move."<init>":(Lday2/Direction;I)V
     260: aload         11
     262: swap
     263: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     268: pop
     269: goto          169
     272: aload         4
     274: checkcast     #67                 // class java/util/List
     277: nop
     278: astore_0
     279: new           #110                // class day2/PartOneState
     282: dup
     283: iconst_0
     284: iconst_0
     285: iconst_3
     286: aconst_null
     287: invokespecial #113                // Method day2/PartOneState."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     290: checkcast     #115                // class day2/State
     293: aload_0
     294: invokestatic  #119                // Method calculate:(Lday2/State;Ljava/util/List;)I
     297: istore_1
     298: getstatic     #125                // Field java/lang/System.out:Ljava/io/PrintStream;
     301: iload_1
     302: invokevirtual #130                // Method java/io/PrintStream.println:(I)V
     305: new           #132                // class day2/PartTwoState
     308: dup
     309: iconst_0
     310: iconst_0
     311: iconst_0
     312: bipush        7
     314: aconst_null
     315: invokespecial #135                // Method day2/PartTwoState."<init>":(IIIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     318: checkcast     #115                // class day2/State
     321: aload_0
     322: invokestatic  #119                // Method calculate:(Lday2/State;Ljava/util/List;)I
     325: istore_1
     326: getstatic     #125                // Field java/lang/System.out:Ljava/io/PrintStream;
     329: iload_1
     330: invokevirtual #130                // Method java/io/PrintStream.println:(I)V
     333: return

  public static final int calculate(day2.State, java.util.List<day2.Move>);
    Code:
       0: aload_0
       1: ldc           #155                // String initialState
       3: invokestatic  #158                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #159                // String moves
       9: invokestatic  #158                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: checkcast     #22                 // class java/lang/Iterable
      16: astore_3
      17: iconst_0
      18: istore        4
      20: aload_0
      21: astore        5
      23: aload_3
      24: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      29: astore        6
      31: aload         6
      33: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      38: ifeq          78
      41: aload         6
      43: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      48: astore        7
      50: aload         5
      52: aload         7
      54: checkcast     #69                 // class day2/Move
      57: astore        8
      59: astore        9
      61: iconst_0
      62: istore        10
      64: aload         9
      66: aload         8
      68: invokeinterface #163,  2          // InterfaceMethod day2/State.transform:(Lday2/Move;)Lday2/State;
      73: astore        5
      75: goto          31
      78: aload         5
      80: astore_2
      81: aload_2
      82: invokeinterface #167,  1          // InterfaceMethod day2/State.getHorizontal:()I
      87: aload_2
      88: invokeinterface #170,  1          // InterfaceMethod day2/State.getDepth:()I
      93: imul
      94: ireturn

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