package me.li2.android.hikotlin.kotlin

import me.li2.android.hikotlin.kotlin.Operator.*
import java.util.*

/** + */
fun operatorPlus(input: Int): Int {
    return input + MY_PLUS
}

/** - */
fun operatorMinus(input: Int): Int {
    return input + MY_MINUS
}

/** x */
fun operatorMultiply(input: Int): Int {
    return input * MY_MULTIPLY
}

/** / */
fun operatorDivider(input: Int): Int {
    return input / MY_DIVIDER
}

/** reverse : 12 to 21 */
fun operatorReverse(input: Int): Int {
    var num = input
    var reversed = 0

    while (num != 0) {
        val digit = num % 10
        reversed = reversed * 10 + digit
        num /= 10
    }

    return reversed
}

/** +/- */
fun operatorConvert(input: Int): Int {
    return -input
}

/** << */
fun operatorShift(input: Int): Int {
    return input / 10
}

fun operatorInsert(input: Int): Int {
    return input * 10 + 1
}

/**
 * THE METHOD THAT TAKES AN ARRAY OF STRINGS AND PRINTS THE
 * POSSIBLE COMBINATIONS.
 */
fun genOperatorsCombinations(operators: Array<Operator>): List<List<Operator>> {

    val results = ArrayList<List<Operator>>()

    /*COMBINATIONS OF LENGTH THREE*/
    for (i in operators.indices) {
        for (j in operators.indices) {
            for (k in operators.indices) {
                for (l in operators.indices) {
                    for (m in operators.indices) {
//                        for (n in operators.indices) {
//                            for (o in operators.indices) {
                                val element = ArrayList<Operator>()
                                element.add(operators[i])
                                element.add(operators[j])
                                element.add(operators[k])
                                element.add(operators[l])
                                element.add(operators[m])
//                                element.add(operators[n])
//                                element.add(operators[o])
                                results.add(element)
                            }
//                        }
//                    }
                }
            }
        }
    }

    return results
}

enum class Operator(val alias: String) {
    PLUS("+"),
    MINUS("-"),
    MULTIPLY("x"),
    DIVIDE("/"),
    REVERSE("Reverse"),
    CONVERT("+/-"),
    SHIFT("<<"),
    INSERT("1");
}

fun calculate(input: Int, operator: Operator): Int {
    return when(operator) {
        Operator.PLUS -> operatorPlus(input)
        Operator.MINUS-> operatorMinus(input)
        Operator.MULTIPLY -> operatorMultiply(input)
        Operator.REVERSE -> operatorReverse(input)
        Operator.CONVERT -> operatorConvert(input)
        Operator.SHIFT -> operatorShift(input)
        Operator.INSERT -> operatorInsert(input)
        else -> {
            0
        }
    }
}

fun chainCalculate(input: Int, operators: List<Operator>): Int {
    var result = input
    for (operator in operators) {
        result = calculate(result, operator)
    }
    return result
}

fun printGoal(operators: List<Operator>) {
    var result = ""
    for (operator in operators) {
        result += " ${operator.alias}"
    }
    println("Goal $MY_GOAL achieved with operators: $result")
}

var MY_MOVES: Int = 7
var MY_INIT: Int = 0
var MY_GOAL: Int = 136
var MY_OPERATORS: Array<Operator> = arrayOf(PLUS, MULTIPLY, REVERSE, INSERT)

var MY_PLUS: Int = 2
var MY_MINUS: Int = -3
var MY_MULTIPLY: Int = 3
var MY_DIVIDER: Int = 2

// Goal 28 achieved with operators:  + + << + + Reverse -

fun main(args: Array<String>) {

    var result: Int
    var combinations = genOperatorsCombinations(MY_OPERATORS)

    for (operators in combinations) {
        result = chainCalculate(MY_INIT, operators)
        if (result == MY_GOAL) {
            printGoal(operators)
            break
        }
    }
}

Compiled from "Calculator.kt"
public final class me.li2.android.hikotlin.kotlin.CalculatorKt$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method me/li2/android/hikotlin/kotlin/Operator.values:()[Lme/li2/android/hikotlin/kotlin/Operator;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field me/li2/android/hikotlin/kotlin/Operator.PLUS:Lme/li2/android/hikotlin/kotlin/Operator;
      12: invokevirtual #22                 // Method me/li2/android/hikotlin/kotlin/Operator.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field me/li2/android/hikotlin/kotlin/Operator.MINUS:Lme/li2/android/hikotlin/kotlin/Operator;
      26: invokevirtual #22                 // Method me/li2/android/hikotlin/kotlin/Operator.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field me/li2/android/hikotlin/kotlin/Operator.MULTIPLY:Lme/li2/android/hikotlin/kotlin/Operator;
      40: invokevirtual #22                 // Method me/li2/android/hikotlin/kotlin/Operator.ordinal:()I
      43: iconst_3
      44: iastore
      45: goto          49
      48: astore_1
      49: nop
      50: aload_0
      51: getstatic     #31                 // Field me/li2/android/hikotlin/kotlin/Operator.REVERSE:Lme/li2/android/hikotlin/kotlin/Operator;
      54: invokevirtual #22                 // Method me/li2/android/hikotlin/kotlin/Operator.ordinal:()I
      57: iconst_4
      58: iastore
      59: goto          63
      62: astore_1
      63: nop
      64: aload_0
      65: getstatic     #34                 // Field me/li2/android/hikotlin/kotlin/Operator.CONVERT:Lme/li2/android/hikotlin/kotlin/Operator;
      68: invokevirtual #22                 // Method me/li2/android/hikotlin/kotlin/Operator.ordinal:()I
      71: iconst_5
      72: iastore
      73: goto          77
      76: astore_1
      77: nop
      78: aload_0
      79: getstatic     #37                 // Field me/li2/android/hikotlin/kotlin/Operator.SHIFT:Lme/li2/android/hikotlin/kotlin/Operator;
      82: invokevirtual #22                 // Method me/li2/android/hikotlin/kotlin/Operator.ordinal:()I
      85: bipush        6
      87: iastore
      88: goto          92
      91: astore_1
      92: nop
      93: aload_0
      94: getstatic     #40                 // Field me/li2/android/hikotlin/kotlin/Operator.INSERT:Lme/li2/android/hikotlin/kotlin/Operator;
      97: invokevirtual #22                 // Method me/li2/android/hikotlin/kotlin/Operator.ordinal:()I
     100: bipush        7
     102: iastore
     103: goto          107
     106: astore_1
     107: aload_0
     108: putstatic     #44                 // Field $EnumSwitchMapping$0:[I
     111: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
          35    45    48   Class java/lang/NoSuchFieldError
          49    59    62   Class java/lang/NoSuchFieldError
          63    73    76   Class java/lang/NoSuchFieldError
          77    88    91   Class java/lang/NoSuchFieldError
          92   103   106   Class java/lang/NoSuchFieldError
}

Compiled from "Calculator.kt"
public final class me.li2.android.hikotlin.kotlin.CalculatorKt {
  private static int MY_MOVES;

  private static int MY_INIT;

  private static int MY_GOAL;

  private static me.li2.android.hikotlin.kotlin.Operator[] MY_OPERATORS;

  private static int MY_PLUS;

  private static int MY_MINUS;

  private static int MY_MULTIPLY;

  private static int MY_DIVIDER;

  public static final int operatorPlus(int);
    Code:
       0: iload_0
       1: getstatic     #10                 // Field MY_PLUS:I
       4: iadd
       5: ireturn

  public static final int operatorMinus(int);
    Code:
       0: iload_0
       1: getstatic     #15                 // Field MY_MINUS:I
       4: iadd
       5: ireturn

  public static final int operatorMultiply(int);
    Code:
       0: iload_0
       1: getstatic     #19                 // Field MY_MULTIPLY:I
       4: imul
       5: ireturn

  public static final int operatorDivider(int);
    Code:
       0: iload_0
       1: getstatic     #23                 // Field MY_DIVIDER:I
       4: idiv
       5: ireturn

  public static final int operatorReverse(int);
    Code:
       0: iload_0
       1: istore_1
       2: iconst_0
       3: istore_2
       4: iload_1
       5: ifeq          28
       8: iload_1
       9: bipush        10
      11: irem
      12: istore_3
      13: iload_2
      14: bipush        10
      16: imul
      17: iload_3
      18: iadd
      19: istore_2
      20: iload_1
      21: bipush        10
      23: idiv
      24: istore_1
      25: goto          4
      28: iload_2
      29: ireturn

  public static final int operatorConvert(int);
    Code:
       0: iload_0
       1: ineg
       2: ireturn

  public static final int operatorShift(int);
    Code:
       0: iload_0
       1: bipush        10
       3: idiv
       4: ireturn

  public static final int operatorInsert(int);
    Code:
       0: iload_0
       1: bipush        10
       3: imul
       4: iconst_1
       5: iadd
       6: ireturn

  public static final java.util.List<java.util.List<me.li2.android.hikotlin.kotlin.Operator>> genOperatorsCombinations(me.li2.android.hikotlin.kotlin.Operator[]);
    Code:
       0: aload_0
       1: ldc           #36                 // String operators
       3: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #44                 // class java/util/ArrayList
       9: dup
      10: invokespecial #48                 // Method java/util/ArrayList."<init>":()V
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_0
      17: arraylength
      18: istore_3
      19: iload_2
      20: iload_3
      21: if_icmpge     175
      24: iconst_0
      25: istore        4
      27: aload_0
      28: arraylength
      29: istore        5
      31: iload         4
      33: iload         5
      35: if_icmpge     169
      38: iconst_0
      39: istore        6
      41: aload_0
      42: arraylength
      43: istore        7
      45: iload         6
      47: iload         7
      49: if_icmpge     163
      52: iconst_0
      53: istore        8
      55: aload_0
      56: arraylength
      57: istore        9
      59: iload         8
      61: iload         9
      63: if_icmpge     157
      66: iconst_0
      67: istore        10
      69: aload_0
      70: arraylength
      71: istore        11
      73: iload         10
      75: iload         11
      77: if_icmpge     151
      80: new           #44                 // class java/util/ArrayList
      83: dup
      84: invokespecial #48                 // Method java/util/ArrayList."<init>":()V
      87: astore        12
      89: aload         12
      91: aload_0
      92: iload_2
      93: aaload
      94: invokevirtual #52                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      97: pop
      98: aload         12
     100: aload_0
     101: iload         4
     103: aaload
     104: invokevirtual #52                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     107: pop
     108: aload         12
     110: aload_0
     111: iload         6
     113: aaload
     114: invokevirtual #52                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     117: pop
     118: aload         12
     120: aload_0
     121: iload         8
     123: aaload
     124: invokevirtual #52                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     127: pop
     128: aload         12
     130: aload_0
     131: iload         10
     133: aaload
     134: invokevirtual #52                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     137: pop
     138: aload_1
     139: aload         12
     141: invokevirtual #52                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     144: pop
     145: iinc          10, 1
     148: goto          73
     151: iinc          8, 1
     154: goto          59
     157: iinc          6, 1
     160: goto          45
     163: iinc          4, 1
     166: goto          31
     169: iinc          2, 1
     172: goto          19
     175: aload_1
     176: checkcast     #54                 // class java/util/List
     179: areturn

  public static final int calculate(int, me.li2.android.hikotlin.kotlin.Operator);
    Code:
       0: aload_1
       1: ldc           #67                 // String operator
       3: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: getstatic     #73                 // Field me/li2/android/hikotlin/kotlin/CalculatorKt$WhenMappings.$EnumSwitchMapping$0:[I
      10: swap
      11: invokevirtual #79                 // Method me/li2/android/hikotlin/kotlin/Operator.ordinal:()I
      14: iaload
      15: tableswitch   { // 1 to 7
                     1: 56
                     2: 63
                     3: 70
                     4: 77
                     5: 84
                     6: 91
                     7: 98
               default: 105
          }
      56: iload_0
      57: invokestatic  #81                 // Method operatorPlus:(I)I
      60: goto          106
      63: iload_0
      64: invokestatic  #83                 // Method operatorMinus:(I)I
      67: goto          106
      70: iload_0
      71: invokestatic  #85                 // Method operatorMultiply:(I)I
      74: goto          106
      77: iload_0
      78: invokestatic  #87                 // Method operatorReverse:(I)I
      81: goto          106
      84: iload_0
      85: invokestatic  #89                 // Method operatorConvert:(I)I
      88: goto          106
      91: iload_0
      92: invokestatic  #91                 // Method operatorShift:(I)I
      95: goto          106
      98: iload_0
      99: invokestatic  #93                 // Method operatorInsert:(I)I
     102: goto          106
     105: iconst_0
     106: ireturn

  public static final int chainCalculate(int, java.util.List<? extends me.li2.android.hikotlin.kotlin.Operator>);
    Code:
       0: aload_1
       1: ldc           #36                 // String operators
       3: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_0
       7: istore_2
       8: aload_1
       9: invokeinterface #101,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      14: astore_3
      15: aload_3
      16: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      21: ifeq          45
      24: aload_3
      25: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      30: checkcast     #75                 // class me/li2/android/hikotlin/kotlin/Operator
      33: astore        4
      35: iload_2
      36: aload         4
      38: invokestatic  #113                // Method calculate:(ILme/li2/android/hikotlin/kotlin/Operator;)I
      41: istore_2
      42: goto          15
      45: iload_2
      46: ireturn

  public static final void printGoal(java.util.List<? extends me.li2.android.hikotlin.kotlin.Operator>);
    Code:
       0: aload_0
       1: ldc           #36                 // String operators
       3: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #120                // String
       8: astore_1
       9: aload_0
      10: invokeinterface #101,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      15: astore_2
      16: aload_2
      17: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      22: ifeq          65
      25: aload_2
      26: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      31: checkcast     #75                 // class me/li2/android/hikotlin/kotlin/Operator
      34: astore_3
      35: new           #122                // class java/lang/StringBuilder
      38: dup
      39: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
      42: aload_1
      43: invokevirtual #127                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      46: bipush        32
      48: invokevirtual #130                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      51: aload_3
      52: invokevirtual #134                // Method me/li2/android/hikotlin/kotlin/Operator.getAlias:()Ljava/lang/String;
      55: invokevirtual #127                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      58: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      61: astore_1
      62: goto          16
      65: new           #122                // class java/lang/StringBuilder
      68: dup
      69: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
      72: ldc           #139                // String Goal
      74: invokevirtual #127                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      77: getstatic     #142                // Field MY_GOAL:I
      80: invokevirtual #145                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      83: ldc           #147                // String  achieved with operators:
      85: invokevirtual #127                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      88: aload_1
      89: invokevirtual #127                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      92: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      95: getstatic     #153                // Field java/lang/System.out:Ljava/io/PrintStream;
      98: swap
      99: invokevirtual #159                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     102: return

  public static final int getMY_MOVES();
    Code:
       0: getstatic     #166                // Field MY_MOVES:I
       3: ireturn

  public static final void setMY_MOVES(int);
    Code:
       0: iload_0
       1: putstatic     #166                // Field MY_MOVES:I
       4: return

  public static final int getMY_INIT();
    Code:
       0: getstatic     #173                // Field MY_INIT:I
       3: ireturn

  public static final void setMY_INIT(int);
    Code:
       0: iload_0
       1: putstatic     #173                // Field MY_INIT:I
       4: return

  public static final int getMY_GOAL();
    Code:
       0: getstatic     #142                // Field MY_GOAL:I
       3: ireturn

  public static final void setMY_GOAL(int);
    Code:
       0: iload_0
       1: putstatic     #142                // Field MY_GOAL:I
       4: return

  public static final me.li2.android.hikotlin.kotlin.Operator[] getMY_OPERATORS();
    Code:
       0: getstatic     #181                // Field MY_OPERATORS:[Lme/li2/android/hikotlin/kotlin/Operator;
       3: areturn

  public static final void setMY_OPERATORS(me.li2.android.hikotlin.kotlin.Operator[]);
    Code:
       0: aload_0
       1: ldc           #184                // String <set-?>
       3: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: putstatic     #181                // Field MY_OPERATORS:[Lme/li2/android/hikotlin/kotlin/Operator;
      10: return

  public static final int getMY_PLUS();
    Code:
       0: getstatic     #10                 // Field MY_PLUS:I
       3: ireturn

  public static final void setMY_PLUS(int);
    Code:
       0: iload_0
       1: putstatic     #10                 // Field MY_PLUS:I
       4: return

  public static final int getMY_MINUS();
    Code:
       0: getstatic     #15                 // Field MY_MINUS:I
       3: ireturn

  public static final void setMY_MINUS(int);
    Code:
       0: iload_0
       1: putstatic     #15                 // Field MY_MINUS:I
       4: return

  public static final int getMY_MULTIPLY();
    Code:
       0: getstatic     #19                 // Field MY_MULTIPLY:I
       3: ireturn

  public static final void setMY_MULTIPLY(int);
    Code:
       0: iload_0
       1: putstatic     #19                 // Field MY_MULTIPLY:I
       4: return

  public static final int getMY_DIVIDER();
    Code:
       0: getstatic     #23                 // Field MY_DIVIDER:I
       3: ireturn

  public static final void setMY_DIVIDER(int);
    Code:
       0: iload_0
       1: putstatic     #23                 // Field MY_DIVIDER:I
       4: return

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #196                // String args
       3: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: getstatic     #181                // Field MY_OPERATORS:[Lme/li2/android/hikotlin/kotlin/Operator;
      11: invokestatic  #198                // Method genOperatorsCombinations:([Lme/li2/android/hikotlin/kotlin/Operator;)Ljava/util/List;
      14: astore_2
      15: aload_2
      16: invokeinterface #101,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      21: astore_3
      22: aload_3
      23: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      28: ifeq          66
      31: aload_3
      32: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      37: checkcast     #54                 // class java/util/List
      40: astore        4
      42: getstatic     #173                // Field MY_INIT:I
      45: aload         4
      47: invokestatic  #200                // Method chainCalculate:(ILjava/util/List;)I
      50: istore_1
      51: iload_1
      52: getstatic     #142                // Field MY_GOAL:I
      55: if_icmpne     22
      58: aload         4
      60: invokestatic  #202                // Method printGoal:(Ljava/util/List;)V
      63: goto          66
      66: return

  static {};
    Code:
       0: bipush        7
       2: putstatic     #166                // Field MY_MOVES:I
       5: sipush        136
       8: putstatic     #142                // Field MY_GOAL:I
      11: iconst_4
      12: anewarray     #75                 // class me/li2/android/hikotlin/kotlin/Operator
      15: astore_0
      16: aload_0
      17: iconst_0
      18: getstatic     #208                // Field me/li2/android/hikotlin/kotlin/Operator.PLUS:Lme/li2/android/hikotlin/kotlin/Operator;
      21: aastore
      22: aload_0
      23: iconst_1
      24: getstatic     #211                // Field me/li2/android/hikotlin/kotlin/Operator.MULTIPLY:Lme/li2/android/hikotlin/kotlin/Operator;
      27: aastore
      28: aload_0
      29: iconst_2
      30: getstatic     #214                // Field me/li2/android/hikotlin/kotlin/Operator.REVERSE:Lme/li2/android/hikotlin/kotlin/Operator;
      33: aastore
      34: aload_0
      35: iconst_3
      36: getstatic     #217                // Field me/li2/android/hikotlin/kotlin/Operator.INSERT:Lme/li2/android/hikotlin/kotlin/Operator;
      39: aastore
      40: aload_0
      41: putstatic     #181                // Field MY_OPERATORS:[Lme/li2/android/hikotlin/kotlin/Operator;
      44: iconst_2
      45: putstatic     #10                 // Field MY_PLUS:I
      48: bipush        -3
      50: putstatic     #15                 // Field MY_MINUS:I
      53: iconst_3
      54: putstatic     #19                 // Field MY_MULTIPLY:I
      57: iconst_2
      58: putstatic     #23                 // Field MY_DIVIDER:I
      61: return
}


package com.example.handins
import java.util.Scanner

fun main(){

   checkAge()

    val max : Int = getMax(1,18,8);
    val min : Int = getMin(1,18,-8);
    println(max); //18
    println(min); //-8

    val numList: List<Int> = listOf(0,-12,4,6,123)
    println("Average of the list ${numList} is: " + calculateAverage(numList))

    val cpr: String = "3203139999"
    println("Is $cpr a valid CPR Number?")
    println(isCprValid(cpr))

    fizzBuzz()

    abbrevName("<NAME>")

    val testStringList: List<String> = listOf("Hello", "banana", "elephant", "pizza", "computer", "mountain", "butterfly", "galaxy", "happiness", "freedom")
    filterWordsByLength(testStringList,3)

}

/*********************
 * Opgave 1
 * A person is elligible to vote if his/her age is greater than or equal to 18.
 * Define a method to find out if he/she is elligible to vote
 *********************/

fun checkAge(){
    val reader = Scanner(System.`in`)

    println("Please enter age: ")
    val userAge: Int = reader.nextInt()

    if(userAge < 18) println("You cannot vote") else println("Vote NOW!")
}

/*********************
 * Opgave 2
 * Define two functions to print the maximum and the minimum number respectively
 * among three numbers
 *********************/
fun getMax(a:Int,b:Int,c:Int):Int{
    return maxOf(a,b,c)
}

fun getMin(a:Int,b:Int,c:Int):Int{
    return minOf(a,b,c)
}

/*********************
 * Opgave 3
 * Write a Kotlin function named calculateAverage
 * that takes in a list of numbers and returns their average.
 *********************/

fun calculateAverage(l:List<Int>):Double{
    val listLeng: Double = l.size.toDouble()
    val listSum: Double = l.sumOf { it.toDouble() }

    return listSum/listLeng
}

/*
Opgave 4

Write a method that returns if a user has input a valid CPR number.
A valid CPR number has:
 * 10 Digits.
 * The first 2 digits are not above 31.
 * The middle 2 digits are not above 12.
 * The method returns true if the CPR number is valid, false if it is not.

 Bruger RegEx. Bruger ChatGPT til at finde en Expression
 */

fun isCprValid(cprString: String):Boolean{
    val validationExpression = "^(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[0-2])(\\d{2})\\d{4}\$".toRegex()

    return validationExpression.matches(cprString)
}

/*
 Opgave 5

 Write a program that prints the numbers from 1 to 100.
 But for multiples of three print “Fizz” instead of the number
 and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
 */

fun fizzBuzz(){
    for (l in 1..100){
        if(l%3 == 0 && l%5 != 0){
            println("Fizz")
        } else if(l%3!=0 && l%5 == 0){
            println("Buzz")
        } else if(l%3==0 && l%5==0){
            println("FizzBuzz")
        }
        else{ println(l) }
    }
}

/*
Opgave 6

Write a program that takes your full name as input and displays
the abbreviations of the first and middle names except the last name which is displayed as it is.
For example, if your name is <NAME>, then the output should be <NAME>.
Or <NAME> will be <NAME>

 */

fun abbrevName(name:String){
    val nameArr = name.split(" ")
    val returnArr = nameArr.mapIndexed { index, s ->
            if(index == nameArr.lastIndex) s else s[0]
    }

    println(returnArr.joinToString(separator = ". "))
}

/*
Opgave 7

Write a program that takes a numerical grade (0-100) as input
and prints out the corresponding american letter grade.

Implement a function calculateGrade that takes an integer parameter representing the grade
and returns a string representing the letter grade according to the following scale:

90-100: "A"
80-89: "B"
70-79: "C"
60-69: "D"
Below 60: "F"

 */

fun calculateGrade(grade:Int):String{
    return when{
        grade > 100 -> "Enter valid number"
        grade < 0 -> "Enter valid number"
        grade in 90..100 -> "A"
        grade in 80..89 -> "B"
        grade in 70..79 -> "C"
        grade in 60..69 -> "D"
        else -> "F"
    }
}

/*
Opgave 8

Write a Kotlin function named filterWordsByLength that takes in a list of strings and a minimum length,
and returns a list containing only the words that have a length greater than or equal to
the specified minimum length.

Use filter function and lambda expressions

 */

fun filterWordsByLength(l:List<String>,minLen:Int):List<String>{

    return l.filter { str -> str.length >= minLen }
}

Compiled from "hand_in_1.kt"
public final class com.example.handins.Hand_in_1Kt {
  public static final void main();
    Code:
       0: invokestatic  #9                  // Method checkAge:()V
       3: iconst_1
       4: bipush        18
       6: bipush        8
       8: invokestatic  #13                 // Method getMax:(III)I
      11: istore_0
      12: iconst_1
      13: bipush        18
      15: bipush        -8
      17: invokestatic  #16                 // Method getMin:(III)I
      20: istore_1
      21: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      24: iload_0
      25: invokevirtual #28                 // Method java/io/PrintStream.println:(I)V
      28: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: iload_1
      32: invokevirtual #28                 // Method java/io/PrintStream.println:(I)V
      35: iconst_5
      36: anewarray     #30                 // class java/lang/Integer
      39: astore_3
      40: aload_3
      41: iconst_0
      42: iconst_0
      43: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      46: aastore
      47: aload_3
      48: iconst_1
      49: bipush        -12
      51: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: aastore
      55: aload_3
      56: iconst_2
      57: iconst_4
      58: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      61: aastore
      62: aload_3
      63: iconst_3
      64: bipush        6
      66: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      69: aastore
      70: aload_3
      71: iconst_4
      72: bipush        123
      74: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      77: aastore
      78: aload_3
      79: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      82: astore_2
      83: new           #42                 // class java/lang/StringBuilder
      86: dup
      87: invokespecial #45                 // Method java/lang/StringBuilder."<init>":()V
      90: ldc           #47                 // String Average of the list
      92: invokevirtual #51                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      95: aload_2
      96: invokevirtual #54                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      99: ldc           #56                 // String  is:
     101: invokevirtual #51                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     104: aload_2
     105: invokestatic  #60                 // Method calculateAverage:(Ljava/util/List;)D
     108: invokevirtual #63                 // Method java/lang/StringBuilder.append:(D)Ljava/lang/StringBuilder;
     111: invokevirtual #67                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     114: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
     117: swap
     118: invokevirtual #70                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     121: ldc           #72                 // String 3203139999
     123: astore_3
     124: new           #42                 // class java/lang/StringBuilder
     127: dup
     128: invokespecial #45                 // Method java/lang/StringBuilder."<init>":()V
     131: ldc           #74                 // String Is
     133: invokevirtual #51                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     136: aload_3
     137: invokevirtual #51                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     140: ldc           #76                 // String  a valid CPR Number?
     142: invokevirtual #51                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     145: invokevirtual #67                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     148: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
     151: swap
     152: invokevirtual #70                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     155: aload_3
     156: invokestatic  #80                 // Method isCprValid:(Ljava/lang/String;)Z
     159: istore        4
     161: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
     164: iload         4
     166: invokevirtual #83                 // Method java/io/PrintStream.println:(Z)V
     169: invokestatic  #86                 // Method fizzBuzz:()V
     172: ldc           #88                 // String <NAME>
     174: invokestatic  #92                 // Method abbrevName:(Ljava/lang/String;)V
     177: bipush        10
     179: anewarray     #94                 // class java/lang/String
     182: astore        5
     184: aload         5
     186: iconst_0
     187: ldc           #96                 // String Hello
     189: aastore
     190: aload         5
     192: iconst_1
     193: ldc           #98                 // String banana
     195: aastore
     196: aload         5
     198: iconst_2
     199: ldc           #100                // String elephant
     201: aastore
     202: aload         5
     204: iconst_3
     205: ldc           #102                // String pizza
     207: aastore
     208: aload         5
     210: iconst_4
     211: ldc           #104                // String computer
     213: aastore
     214: aload         5
     216: iconst_5
     217: ldc           #106                // String mountain
     219: aastore
     220: aload         5
     222: bipush        6
     224: ldc           #108                // String butterfly
     226: aastore
     227: aload         5
     229: bipush        7
     231: ldc           #110                // String galaxy
     233: aastore
     234: aload         5
     236: bipush        8
     238: ldc           #112                // String happiness
     240: aastore
     241: aload         5
     243: bipush        9
     245: ldc           #114                // String freedom
     247: aastore
     248: aload         5
     250: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     253: astore        4
     255: aload         4
     257: iconst_3
     258: invokestatic  #118                // Method filterWordsByLength:(Ljava/util/List;I)Ljava/util/List;
     261: pop
     262: return

  public static final void checkAge();
    Code:
       0: new           #128                // class java/util/Scanner
       3: dup
       4: getstatic     #132                // Field java/lang/System.in:Ljava/io/InputStream;
       7: invokespecial #135                // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      10: astore_0
      11: ldc           #137                // String Please enter age:
      13: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      16: swap
      17: invokevirtual #70                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      20: aload_0
      21: invokevirtual #141                // Method java/util/Scanner.nextInt:()I
      24: istore_1
      25: iload_1
      26: bipush        18
      28: if_icmpge     43
      31: ldc           #143                // String You cannot vote
      33: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #70                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: goto          52
      43: ldc           #145                // String Vote NOW!
      45: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      48: swap
      49: invokevirtual #70                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      52: return

  public static final int getMax(int, int, int);
    Code:
       0: iload_0
       1: iload_1
       2: iload_2
       3: invokestatic  #153                // Method java/lang/Math.max:(II)I
       6: invokestatic  #153                // Method java/lang/Math.max:(II)I
       9: ireturn

  public static final int getMin(int, int, int);
    Code:
       0: iload_0
       1: iload_1
       2: iload_2
       3: invokestatic  #158                // Method java/lang/Math.min:(II)I
       6: invokestatic  #158                // Method java/lang/Math.min:(II)I
       9: ireturn

  public static final double calculateAverage(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #162                // String l
       3: invokestatic  #168                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #173,  1          // InterfaceMethod java/util/List.size:()I
      12: i2d
      13: dstore_1
      14: aload_0
      15: checkcast     #175                // class java/lang/Iterable
      18: astore        5
      20: dconst_0
      21: dstore        6
      23: aload         5
      25: invokeinterface #179,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      30: astore        8
      32: aload         8
      34: invokeinterface #185,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          83
      42: aload         8
      44: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        9
      51: dload         6
      53: aload         9
      55: checkcast     #191                // class java/lang/Number
      58: invokevirtual #194                // Method java/lang/Number.intValue:()I
      61: istore        10
      63: dstore        12
      65: iconst_0
      66: istore        11
      68: iload         10
      70: i2d
      71: dstore        14
      73: dload         12
      75: dload         14
      77: dadd
      78: dstore        6
      80: goto          32
      83: dload         6
      85: dstore_3
      86: dload_3
      87: dload_1
      88: ddiv
      89: dreturn

  public static final boolean isCprValid(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #201                // String cprString
       3: invokestatic  #168                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #203                // class kotlin/text/Regex
       9: dup
      10: ldc           #205                // String ^(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[0-2])(\\d{2})\\d{4}$
      12: invokespecial #207                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: astore_1
      16: aload_1
      17: aload_0
      18: checkcast     #209                // class java/lang/CharSequence
      21: invokevirtual #213                // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
      24: ireturn

  public static final void fizzBuzz();
    Code:
       0: iconst_1
       1: istore_0
       2: iload_0
       3: bipush        101
       5: if_icmpge     93
       8: iload_0
       9: iconst_3
      10: irem
      11: ifne          32
      14: iload_0
      15: iconst_5
      16: irem
      17: ifeq          32
      20: ldc           #217                // String Fizz
      22: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      25: swap
      26: invokevirtual #70                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      29: goto          87
      32: iload_0
      33: iconst_3
      34: irem
      35: ifeq          56
      38: iload_0
      39: iconst_5
      40: irem
      41: ifne          56
      44: ldc           #219                // String Buzz
      46: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      49: swap
      50: invokevirtual #70                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      53: goto          87
      56: iload_0
      57: iconst_3
      58: irem
      59: ifne          80
      62: iload_0
      63: iconst_5
      64: irem
      65: ifne          80
      68: ldc           #221                // String FizzBuzz
      70: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      73: swap
      74: invokevirtual #70                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      77: goto          87
      80: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      83: iload_0
      84: invokevirtual #28                 // Method java/io/PrintStream.println:(I)V
      87: iinc          0, 1
      90: goto          2
      93: return

  public static final void abbrevName(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #223                // String name
       3: invokestatic  #168                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #209                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #94                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #225                // String
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #231                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_1
      30: aload_1
      31: checkcast     #175                // class java/lang/Iterable
      34: astore_3
      35: iconst_0
      36: istore        4
      38: aload_3
      39: astore        5
      41: new           #233                // class java/util/ArrayList
      44: dup
      45: aload_3
      46: bipush        10
      48: invokestatic  #237                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      51: invokespecial #239                // Method java/util/ArrayList."<init>":(I)V
      54: checkcast     #241                // class java/util/Collection
      57: astore        6
      59: iconst_0
      60: istore        7
      62: iconst_0
      63: istore        8
      65: aload         5
      67: invokeinterface #179,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      72: astore        9
      74: aload         9
      76: invokeinterface #185,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      81: ifeq          161
      84: aload         9
      86: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      91: astore        10
      93: aload         6
      95: iload         8
      97: iinc          8, 1
     100: istore        11
     102: iload         11
     104: ifge          110
     107: invokestatic  #244                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     110: iload         11
     112: aload         10
     114: checkcast     #94                 // class java/lang/String
     117: astore        12
     119: istore        13
     121: astore        15
     123: iconst_0
     124: istore        14
     126: iload         13
     128: aload_1
     129: invokestatic  #248                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     132: if_icmpne     140
     135: aload         12
     137: goto          149
     140: aload         12
     142: iconst_0
     143: invokevirtual #252                // Method java/lang/String.charAt:(I)C
     146: invokestatic  #257                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     149: aload         15
     151: swap
     152: invokeinterface #261,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     157: pop
     158: goto          74
     161: aload         6
     163: checkcast     #170                // class java/util/List
     166: nop
     167: astore_2
     168: aload_2
     169: checkcast     #175                // class java/lang/Iterable
     172: ldc_w         #263                // String .
     175: checkcast     #209                // class java/lang/CharSequence
     178: aconst_null
     179: aconst_null
     180: iconst_0
     181: aconst_null
     182: aconst_null
     183: bipush        62
     185: aconst_null
     186: invokestatic  #267                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     189: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
     192: swap
     193: invokevirtual #70                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     196: return

  public static final java.lang.String calculateGrade(int);
    Code:
       0: nop
       1: iload_0
       2: bipush        100
       4: if_icmple     13
       7: ldc_w         #288                // String Enter valid number
      10: goto          146
      13: iload_0
      14: ifge          23
      17: ldc_w         #288                // String Enter valid number
      20: goto          146
      23: bipush        90
      25: iload_0
      26: if_icmpgt     43
      29: iload_0
      30: bipush        101
      32: if_icmpge     39
      35: iconst_1
      36: goto          44
      39: iconst_0
      40: goto          44
      43: iconst_0
      44: ifeq          53
      47: ldc_w         #290                // String A
      50: goto          146
      53: bipush        80
      55: iload_0
      56: if_icmpgt     73
      59: iload_0
      60: bipush        90
      62: if_icmpge     69
      65: iconst_1
      66: goto          74
      69: iconst_0
      70: goto          74
      73: iconst_0
      74: ifeq          83
      77: ldc_w         #292                // String B
      80: goto          146
      83: bipush        70
      85: iload_0
      86: if_icmpgt     103
      89: iload_0
      90: bipush        80
      92: if_icmpge     99
      95: iconst_1
      96: goto          104
      99: iconst_0
     100: goto          104
     103: iconst_0
     104: ifeq          113
     107: ldc_w         #294                // String C
     110: goto          146
     113: bipush        60
     115: iload_0
     116: if_icmpgt     133
     119: iload_0
     120: bipush        70
     122: if_icmpge     129
     125: iconst_1
     126: goto          134
     129: iconst_0
     130: goto          134
     133: iconst_0
     134: ifeq          143
     137: ldc_w         #295                // String D
     140: goto          146
     143: ldc_w         #297                // String F
     146: areturn

  public static final java.util.List<java.lang.String> filterWordsByLength(java.util.List<java.lang.String>, int);
    Code:
       0: aload_0
       1: ldc           #162                // String l
       3: invokestatic  #168                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #175                // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #233                // class java/util/ArrayList
      19: dup
      20: invokespecial #300                // Method java/util/ArrayList."<init>":()V
      23: checkcast     #241                // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        6
      31: aload         4
      33: invokeinterface #179,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        7
      40: aload         7
      42: invokeinterface #185,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          99
      50: aload         7
      52: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        8
      59: aload         8
      61: checkcast     #94                 // class java/lang/String
      64: astore        9
      66: iconst_0
      67: istore        10
      69: aload         9
      71: invokevirtual #303                // Method java/lang/String.length:()I
      74: iload_1
      75: if_icmplt     82
      78: iconst_1
      79: goto          83
      82: iconst_0
      83: ifeq          40
      86: aload         5
      88: aload         8
      90: invokeinterface #261,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      95: pop
      96: goto          40
      99: aload         5
     101: checkcast     #170                // class java/util/List
     104: nop
     105: areturn

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


package com.kingchampion36.dsa.arrays

import java.util.PriorityQueue

/**
 * Sort the list and find kth smallest element
 * Time complexity - O(n * log(n))
 */
fun List<Int>.kthSmallestElementBySorting(k: Int) = when {
  isEmpty() -> throw IllegalArgumentException("List should not be empty")
  k <= 0 || k >= size -> throw IllegalArgumentException("Invalid value $k of k")
  else -> sorted()[k - 1]
}

/**
 * Time Complexity - O(n * log(k))
 */
fun List<Int>.kthSmallestElementByUsingMaxHeap(k: Int): Int {
  require(isNotEmpty()) { "List should not be empty" }

  // k should be between 0 and size (0 < k <= size)
  require(k in 1..size) { "Invalid value of k" }

  val maxHeap = PriorityQueue<Int>(reverseOrder())

  // Build a max heap with first k elements
  for (i in 0 until k) {
    maxHeap.offer(this[i])
  }

  for (i in k until size) {
    // If current element is smaller than the top element of max heap,
    // pop it and insert current element in the max heap
    if (this[i] < maxHeap.peek()) {
      maxHeap.poll()
      maxHeap.offer(this[i])
    }
  }

  return maxHeap.peek()
}

/**
 * Time Complexity - O(n * log(k))
 */
fun List<Int>.kthLargestElementByUsingMinHeap(k: Int): Int {
  require(isNotEmpty()) { "List should not be empty" }

  // k should be between 0 and size (0 < k <= size)
  require(k in 1..size) { "Invalid value of k" }

  val minHeap = PriorityQueue<Int>()

  // Build a min heap with first k elements
  for (i in 0 until k) {
    minHeap.offer(this[i])
  }

  for (i in k until size) {
    // If current element is greater than the top element of min heap,
    // pop it and insert current element in the min heap
    if (this[i] > minHeap.peek()) {
      minHeap.poll()
      minHeap.offer(this[i])
    }
  }

  return minHeap.peek()
}

Compiled from "KthSmallestAndLargestElement.kt"
public final class com.kingchampion36.dsa.arrays.KthSmallestAndLargestElementKt {
  public static final int kthSmallestElementBySorting(java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: nop
       7: aload_0
       8: invokeinterface #22,  1           // InterfaceMethod java/util/List.isEmpty:()Z
      13: ifeq          26
      16: new           #24                 // class java/lang/IllegalArgumentException
      19: dup
      20: ldc           #26                 // String List should not be empty
      22: invokespecial #30                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      25: athrow
      26: iload_1
      27: ifle          40
      30: iload_1
      31: aload_0
      32: invokeinterface #34,  1           // InterfaceMethod java/util/List.size:()I
      37: if_icmplt     72
      40: new           #24                 // class java/lang/IllegalArgumentException
      43: dup
      44: new           #36                 // class java/lang/StringBuilder
      47: dup
      48: invokespecial #39                 // Method java/lang/StringBuilder."<init>":()V
      51: ldc           #41                 // String Invalid value
      53: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      56: iload_1
      57: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      60: ldc           #50                 // String  of k
      62: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      65: invokevirtual #54                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      68: invokespecial #30                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      71: athrow
      72: aload_0
      73: checkcast     #56                 // class java/lang/Iterable
      76: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      79: iload_1
      80: iconst_1
      81: isub
      82: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      87: checkcast     #68                 // class java/lang/Number
      90: invokevirtual #71                 // Method java/lang/Number.intValue:()I
      93: ireturn

  public static final int kthSmallestElementByUsingMaxHeap(java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #78                 // class java/util/Collection
      10: invokeinterface #79,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      15: ifne          22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ifne          43
      26: iconst_0
      27: istore_3
      28: ldc           #26                 // String List should not be empty
      30: astore_3
      31: new           #24                 // class java/lang/IllegalArgumentException
      34: dup
      35: aload_3
      36: invokevirtual #80                 // Method java/lang/Object.toString:()Ljava/lang/String;
      39: invokespecial #30                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      42: athrow
      43: iconst_1
      44: iload_1
      45: if_icmpgt     66
      48: iload_1
      49: aload_0
      50: invokeinterface #34,  1           // InterfaceMethod java/util/List.size:()I
      55: if_icmpgt     62
      58: iconst_1
      59: goto          67
      62: iconst_0
      63: goto          67
      66: iconst_0
      67: ifne          87
      70: iconst_0
      71: istore_3
      72: ldc           #82                 // String Invalid value of k
      74: astore_3
      75: new           #24                 // class java/lang/IllegalArgumentException
      78: dup
      79: aload_3
      80: invokevirtual #80                 // Method java/lang/Object.toString:()Ljava/lang/String;
      83: invokespecial #30                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      86: athrow
      87: new           #84                 // class java/util/PriorityQueue
      90: dup
      91: invokestatic  #90                 // Method kotlin/comparisons/ComparisonsKt.reverseOrder:()Ljava/util/Comparator;
      94: invokespecial #93                 // Method java/util/PriorityQueue."<init>":(Ljava/util/Comparator;)V
      97: astore_2
      98: iconst_0
      99: istore_3
     100: iload_3
     101: iload_1
     102: if_icmpge     123
     105: aload_2
     106: aload_0
     107: iload_3
     108: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     113: invokevirtual #97                 // Method java/util/PriorityQueue.offer:(Ljava/lang/Object;)Z
     116: pop
     117: iinc          3, 1
     120: goto          100
     123: iload_1
     124: istore_3
     125: aload_0
     126: invokeinterface #34,  1           // InterfaceMethod java/util/List.size:()I
     131: istore        4
     133: iload_3
     134: iload         4
     136: if_icmpge     188
     139: aload_0
     140: iload_3
     141: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     146: checkcast     #68                 // class java/lang/Number
     149: invokevirtual #71                 // Method java/lang/Number.intValue:()I
     152: aload_2
     153: invokevirtual #101                // Method java/util/PriorityQueue.peek:()Ljava/lang/Object;
     156: checkcast     #68                 // class java/lang/Number
     159: invokevirtual #71                 // Method java/lang/Number.intValue:()I
     162: if_icmpge     182
     165: aload_2
     166: invokevirtual #104                // Method java/util/PriorityQueue.poll:()Ljava/lang/Object;
     169: pop
     170: aload_2
     171: aload_0
     172: iload_3
     173: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     178: invokevirtual #97                 // Method java/util/PriorityQueue.offer:(Ljava/lang/Object;)Z
     181: pop
     182: iinc          3, 1
     185: goto          133
     188: aload_2
     189: invokevirtual #101                // Method java/util/PriorityQueue.peek:()Ljava/lang/Object;
     192: dup
     193: ldc           #106                // String peek(...)
     195: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     198: checkcast     #68                 // class java/lang/Number
     201: invokevirtual #71                 // Method java/lang/Number.intValue:()I
     204: ireturn

  public static final int kthLargestElementByUsingMinHeap(java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #78                 // class java/util/Collection
      10: invokeinterface #79,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      15: ifne          22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ifne          43
      26: iconst_0
      27: istore_3
      28: ldc           #26                 // String List should not be empty
      30: astore_3
      31: new           #24                 // class java/lang/IllegalArgumentException
      34: dup
      35: aload_3
      36: invokevirtual #80                 // Method java/lang/Object.toString:()Ljava/lang/String;
      39: invokespecial #30                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      42: athrow
      43: iconst_1
      44: iload_1
      45: if_icmpgt     66
      48: iload_1
      49: aload_0
      50: invokeinterface #34,  1           // InterfaceMethod java/util/List.size:()I
      55: if_icmpgt     62
      58: iconst_1
      59: goto          67
      62: iconst_0
      63: goto          67
      66: iconst_0
      67: ifne          87
      70: iconst_0
      71: istore_3
      72: ldc           #82                 // String Invalid value of k
      74: astore_3
      75: new           #24                 // class java/lang/IllegalArgumentException
      78: dup
      79: aload_3
      80: invokevirtual #80                 // Method java/lang/Object.toString:()Ljava/lang/String;
      83: invokespecial #30                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      86: athrow
      87: new           #84                 // class java/util/PriorityQueue
      90: dup
      91: invokespecial #117                // Method java/util/PriorityQueue."<init>":()V
      94: astore_2
      95: iconst_0
      96: istore_3
      97: iload_3
      98: iload_1
      99: if_icmpge     120
     102: aload_2
     103: aload_0
     104: iload_3
     105: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     110: invokevirtual #97                 // Method java/util/PriorityQueue.offer:(Ljava/lang/Object;)Z
     113: pop
     114: iinc          3, 1
     117: goto          97
     120: iload_1
     121: istore_3
     122: aload_0
     123: invokeinterface #34,  1           // InterfaceMethod java/util/List.size:()I
     128: istore        4
     130: iload_3
     131: iload         4
     133: if_icmpge     185
     136: aload_0
     137: iload_3
     138: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     143: checkcast     #68                 // class java/lang/Number
     146: invokevirtual #71                 // Method java/lang/Number.intValue:()I
     149: aload_2
     150: invokevirtual #101                // Method java/util/PriorityQueue.peek:()Ljava/lang/Object;
     153: checkcast     #68                 // class java/lang/Number
     156: invokevirtual #71                 // Method java/lang/Number.intValue:()I
     159: if_icmple     179
     162: aload_2
     163: invokevirtual #104                // Method java/util/PriorityQueue.poll:()Ljava/lang/Object;
     166: pop
     167: aload_2
     168: aload_0
     169: iload_3
     170: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     175: invokevirtual #97                 // Method java/util/PriorityQueue.offer:(Ljava/lang/Object;)Z
     178: pop
     179: iinc          3, 1
     182: goto          130
     185: aload_2
     186: invokevirtual #101                // Method java/util/PriorityQueue.peek:()Ljava/lang/Object;
     189: dup
     190: ldc           #106                // String peek(...)
     192: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     195: checkcast     #68                 // class java/lang/Number
     198: invokevirtual #71                 // Method java/lang/Number.intValue:()I
     201: ireturn
}


package net.rafaeltoledo.kotlin.advent

import kotlin.math.pow

class Day04 {

  fun invoke(input: List<String>): Int {
    val cards = input.map { it.toScratchCard() }

    return cards
      .map { card -> card.numbers.filter { card.winningNumbers.contains(it) } }
      .sumOf { it.size.calculateCardValue() }
  }

  fun invoke2(input: List<String>): Int {
    val cards = input.map { it.toScratchCard() }

    val cardCounter = cards.associate { it.identifier to 1 }.toMutableMap()

    cards
      .forEachIndexed { index, card ->
        val id = index + 1
        val multiplier = cardCounter[id] ?: 1
        val extras = card.numbers.filter { card.winningNumbers.contains(it) }.count()

        for (i in 0 until extras) {
          val targetId = id + (i + 1)
          cardCounter[targetId]?.let { current ->
            cardCounter[targetId] = current + multiplier
          }
        }
      }

    return cardCounter.toList().sumOf { it.second }
  }
}

private fun Int.calculateCardValue(): Int {
  return 2.0.pow((this - 1).toDouble()).toInt()
}

private fun String.toScratchCard(): ScratchCard {
  val parts = split(":")

  val identifier = parts.first().replace("Card", "").trim().toInt()

  val content = parts.last().split("|")
  val winningNumbers =
    content.first().split(" ").filter { it.isNotEmpty() }.map { it.trim().toInt() }
  val numbers = content.last().split(" ").filter { it.isNotEmpty() }.map { it.trim().toInt() }

  return ScratchCard(identifier, numbers, winningNumbers)
}

data class ScratchCard(
  val identifier: Int,
  val numbers: List<Int>,
  val winningNumbers: List<Int>,
)

Compiled from "Day04.kt"
public final class net.rafaeltoledo.kotlin.advent.Day04Kt {
  private static final int calculateCardValue(int);
    Code:
       0: ldc2_w        #7                  // double 2.0d
       3: iload_0
       4: iconst_1
       5: isub
       6: i2d
       7: invokestatic  #14                 // Method java/lang/Math.pow:(DD)D
      10: d2i
      11: ireturn

  private static final net.rafaeltoledo.kotlin.advent.ScratchCard toScratchCard(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #20                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #22                 // class java/lang/String
       8: astore_2
       9: aload_2
      10: iconst_0
      11: ldc           #24                 // String :
      13: aastore
      14: aload_2
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #30                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: astore_1
      24: nop
      25: aload_1
      26: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      29: checkcast     #22                 // class java/lang/String
      32: ldc           #38                 // String Card
      34: ldc           #40                 // String
      36: iconst_0
      37: iconst_4
      38: aconst_null
      39: invokestatic  #44                 // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      42: checkcast     #20                 // class java/lang/CharSequence
      45: invokestatic  #48                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      48: invokevirtual #52                 // Method java/lang/Object.toString:()Ljava/lang/String;
      51: invokestatic  #58                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      54: istore_2
      55: aload_1
      56: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      59: checkcast     #20                 // class java/lang/CharSequence
      62: iconst_1
      63: anewarray     #22                 // class java/lang/String
      66: astore        4
      68: aload         4
      70: iconst_0
      71: ldc           #63                 // String |
      73: aastore
      74: aload         4
      76: iconst_0
      77: iconst_0
      78: bipush        6
      80: aconst_null
      81: invokestatic  #30                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      84: astore_3
      85: aload_3
      86: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      89: checkcast     #20                 // class java/lang/CharSequence
      92: iconst_1
      93: anewarray     #22                 // class java/lang/String
      96: astore        5
      98: aload         5
     100: iconst_0
     101: ldc           #65                 // String
     103: aastore
     104: aload         5
     106: iconst_0
     107: iconst_0
     108: bipush        6
     110: aconst_null
     111: invokestatic  #30                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     114: checkcast     #67                 // class java/lang/Iterable
     117: astore        5
     119: iconst_0
     120: istore        6
     122: aload         5
     124: astore        7
     126: new           #69                 // class java/util/ArrayList
     129: dup
     130: invokespecial #73                 // Method java/util/ArrayList."<init>":()V
     133: checkcast     #75                 // class java/util/Collection
     136: astore        8
     138: iconst_0
     139: istore        9
     141: aload         7
     143: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     148: astore        10
     150: aload         10
     152: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     157: ifeq          214
     160: aload         10
     162: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     167: astore        11
     169: aload         11
     171: checkcast     #22                 // class java/lang/String
     174: astore        12
     176: iconst_0
     177: istore        13
     179: aload         12
     181: checkcast     #20                 // class java/lang/CharSequence
     184: invokeinterface #93,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     189: ifle          196
     192: iconst_1
     193: goto          197
     196: iconst_0
     197: nop
     198: ifeq          150
     201: aload         8
     203: aload         11
     205: invokeinterface #97,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     210: pop
     211: goto          150
     214: aload         8
     216: checkcast     #99                 // class java/util/List
     219: nop
     220: checkcast     #67                 // class java/lang/Iterable
     223: astore        5
     225: nop
     226: iconst_0
     227: istore        6
     229: aload         5
     231: astore        7
     233: new           #69                 // class java/util/ArrayList
     236: dup
     237: aload         5
     239: bipush        10
     241: invokestatic  #103                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     244: invokespecial #106                // Method java/util/ArrayList."<init>":(I)V
     247: checkcast     #75                 // class java/util/Collection
     250: astore        8
     252: iconst_0
     253: istore        9
     255: aload         7
     257: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     262: astore        10
     264: aload         10
     266: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     271: ifeq          328
     274: aload         10
     276: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     281: astore        11
     283: aload         8
     285: aload         11
     287: checkcast     #22                 // class java/lang/String
     290: astore        12
     292: astore        15
     294: iconst_0
     295: istore        13
     297: nop
     298: aload         12
     300: checkcast     #20                 // class java/lang/CharSequence
     303: invokestatic  #48                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     306: invokevirtual #52                 // Method java/lang/Object.toString:()Ljava/lang/String;
     309: invokestatic  #58                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     312: nop
     313: invokestatic  #110                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     316: aload         15
     318: swap
     319: invokeinterface #97,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     324: pop
     325: goto          264
     328: aload         8
     330: checkcast     #99                 // class java/util/List
     333: nop
     334: astore        4
     336: aload_3
     337: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     340: checkcast     #20                 // class java/lang/CharSequence
     343: iconst_1
     344: anewarray     #22                 // class java/lang/String
     347: astore        6
     349: aload         6
     351: iconst_0
     352: ldc           #65                 // String
     354: aastore
     355: aload         6
     357: iconst_0
     358: iconst_0
     359: bipush        6
     361: aconst_null
     362: invokestatic  #30                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     365: checkcast     #67                 // class java/lang/Iterable
     368: astore        6
     370: iconst_0
     371: istore        7
     373: aload         6
     375: astore        8
     377: new           #69                 // class java/util/ArrayList
     380: dup
     381: invokespecial #73                 // Method java/util/ArrayList."<init>":()V
     384: checkcast     #75                 // class java/util/Collection
     387: astore        9
     389: iconst_0
     390: istore        10
     392: aload         8
     394: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     399: astore        11
     401: aload         11
     403: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     408: ifeq          465
     411: aload         11
     413: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     418: astore        12
     420: aload         12
     422: checkcast     #22                 // class java/lang/String
     425: astore        13
     427: iconst_0
     428: istore        14
     430: aload         13
     432: checkcast     #20                 // class java/lang/CharSequence
     435: invokeinterface #93,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     440: ifle          447
     443: iconst_1
     444: goto          448
     447: iconst_0
     448: nop
     449: ifeq          401
     452: aload         9
     454: aload         12
     456: invokeinterface #97,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     461: pop
     462: goto          401
     465: aload         9
     467: checkcast     #99                 // class java/util/List
     470: nop
     471: checkcast     #67                 // class java/lang/Iterable
     474: astore        6
     476: nop
     477: iconst_0
     478: istore        7
     480: aload         6
     482: astore        8
     484: new           #69                 // class java/util/ArrayList
     487: dup
     488: aload         6
     490: bipush        10
     492: invokestatic  #103                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     495: invokespecial #106                // Method java/util/ArrayList."<init>":(I)V
     498: checkcast     #75                 // class java/util/Collection
     501: astore        9
     503: iconst_0
     504: istore        10
     506: aload         8
     508: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     513: astore        11
     515: aload         11
     517: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     522: ifeq          579
     525: aload         11
     527: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     532: astore        12
     534: aload         9
     536: aload         12
     538: checkcast     #22                 // class java/lang/String
     541: astore        13
     543: astore        15
     545: iconst_0
     546: istore        14
     548: nop
     549: aload         13
     551: checkcast     #20                 // class java/lang/CharSequence
     554: invokestatic  #48                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     557: invokevirtual #52                 // Method java/lang/Object.toString:()Ljava/lang/String;
     560: invokestatic  #58                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     563: nop
     564: invokestatic  #110                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     567: aload         15
     569: swap
     570: invokeinterface #97,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     575: pop
     576: goto          515
     579: aload         9
     581: checkcast     #99                 // class java/util/List
     584: nop
     585: astore        5
     587: new           #112                // class net/rafaeltoledo/kotlin/advent/ScratchCard
     590: dup
     591: iload_2
     592: aload         5
     594: aload         4
     596: invokespecial #115                // Method net/rafaeltoledo/kotlin/advent/ScratchCard."<init>":(ILjava/util/List;Ljava/util/List;)V
     599: areturn

  public static final net.rafaeltoledo.kotlin.advent.ScratchCard access$toScratchCard(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #147                // Method toScratchCard:(Ljava/lang/String;)Lnet/rafaeltoledo/kotlin/advent/ScratchCard;
       4: areturn

  public static final int access$calculateCardValue(int);
    Code:
       0: iload_0
       1: invokestatic  #151                // Method calculateCardValue:(I)I
       4: ireturn
}

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

  public final int invoke(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #24                 // class java/lang/Iterable
      10: astore_3
      11: iconst_0
      12: istore        4
      14: aload_3
      15: astore        5
      17: new           #26                 // class java/util/ArrayList
      20: dup
      21: aload_3
      22: bipush        10
      24: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      27: invokespecial #35                 // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #37                 // class java/util/Collection
      33: astore        6
      35: iconst_0
      36: istore        7
      38: aload         5
      40: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        8
      47: aload         8
      49: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          97
      57: aload         8
      59: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        9
      66: aload         6
      68: aload         9
      70: checkcast     #53                 // class java/lang/String
      73: astore        10
      75: astore        21
      77: iconst_0
      78: istore        11
      80: aload         10
      82: invokestatic  #59                 // Method net/rafaeltoledo/kotlin/advent/Day04Kt.access$toScratchCard:(Ljava/lang/String;)Lnet/rafaeltoledo/kotlin/advent/ScratchCard;
      85: aload         21
      87: swap
      88: invokeinterface #63,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      93: pop
      94: goto          47
      97: aload         6
      99: checkcast     #65                 // class java/util/List
     102: nop
     103: astore_2
     104: aload_2
     105: checkcast     #24                 // class java/lang/Iterable
     108: astore_3
     109: nop
     110: iconst_0
     111: istore        4
     113: aload_3
     114: astore        5
     116: new           #26                 // class java/util/ArrayList
     119: dup
     120: aload_3
     121: bipush        10
     123: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     126: invokespecial #35                 // Method java/util/ArrayList."<init>":(I)V
     129: checkcast     #37                 // class java/util/Collection
     132: astore        6
     134: iconst_0
     135: istore        7
     137: aload         5
     139: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     144: astore        8
     146: aload         8
     148: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     153: ifeq          302
     156: aload         8
     158: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     163: astore        9
     165: aload         6
     167: aload         9
     169: checkcast     #67                 // class net/rafaeltoledo/kotlin/advent/ScratchCard
     172: astore        10
     174: astore        21
     176: iconst_0
     177: istore        11
     179: aload         10
     181: invokevirtual #71                 // Method net/rafaeltoledo/kotlin/advent/ScratchCard.getNumbers:()Ljava/util/List;
     184: checkcast     #24                 // class java/lang/Iterable
     187: astore        12
     189: iconst_0
     190: istore        13
     192: aload         12
     194: astore        14
     196: new           #26                 // class java/util/ArrayList
     199: dup
     200: invokespecial #72                 // Method java/util/ArrayList."<init>":()V
     203: checkcast     #37                 // class java/util/Collection
     206: astore        15
     208: iconst_0
     209: istore        16
     211: aload         14
     213: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     218: astore        17
     220: aload         17
     222: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     227: ifeq          283
     230: aload         17
     232: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     237: astore        18
     239: aload         18
     241: checkcast     #74                 // class java/lang/Number
     244: invokevirtual #78                 // Method java/lang/Number.intValue:()I
     247: istore        19
     249: iconst_0
     250: istore        20
     252: aload         10
     254: invokevirtual #81                 // Method net/rafaeltoledo/kotlin/advent/ScratchCard.getWinningNumbers:()Ljava/util/List;
     257: iload         19
     259: invokestatic  #87                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     262: invokeinterface #90,  2           // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     267: ifeq          220
     270: aload         15
     272: aload         18
     274: invokeinterface #63,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     279: pop
     280: goto          220
     283: aload         15
     285: checkcast     #65                 // class java/util/List
     288: nop
     289: nop
     290: aload         21
     292: swap
     293: invokeinterface #63,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     298: pop
     299: goto          146
     302: aload         6
     304: checkcast     #65                 // class java/util/List
     307: nop
     308: checkcast     #24                 // class java/lang/Iterable
     311: astore_3
     312: iconst_0
     313: istore        4
     315: aload_3
     316: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     321: astore        5
     323: aload         5
     325: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     330: ifeq          378
     333: aload         5
     335: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     340: astore        6
     342: iload         4
     344: aload         6
     346: checkcast     #65                 // class java/util/List
     349: astore        7
     351: istore        21
     353: iconst_0
     354: istore        8
     356: aload         7
     358: invokeinterface #93,  1           // InterfaceMethod java/util/List.size:()I
     363: invokestatic  #97                 // Method net/rafaeltoledo/kotlin/advent/Day04Kt.access$calculateCardValue:(I)I
     366: istore        22
     368: iload         21
     370: iload         22
     372: iadd
     373: istore        4
     375: goto          323
     378: iload         4
     380: ireturn

  public final int invoke2(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #24                 // class java/lang/Iterable
      10: astore_3
      11: iconst_0
      12: istore        4
      14: aload_3
      15: astore        5
      17: new           #26                 // class java/util/ArrayList
      20: dup
      21: aload_3
      22: bipush        10
      24: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      27: invokespecial #35                 // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #37                 // class java/util/Collection
      33: astore        6
      35: iconst_0
      36: istore        7
      38: aload         5
      40: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        8
      47: aload         8
      49: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          97
      57: aload         8
      59: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        9
      66: aload         6
      68: aload         9
      70: checkcast     #53                 // class java/lang/String
      73: astore        10
      75: astore        25
      77: iconst_0
      78: istore        11
      80: aload         10
      82: invokestatic  #59                 // Method net/rafaeltoledo/kotlin/advent/Day04Kt.access$toScratchCard:(Ljava/lang/String;)Lnet/rafaeltoledo/kotlin/advent/ScratchCard;
      85: aload         25
      87: swap
      88: invokeinterface #63,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      93: pop
      94: goto          47
      97: aload         6
      99: checkcast     #65                 // class java/util/List
     102: nop
     103: astore_2
     104: aload_2
     105: checkcast     #24                 // class java/lang/Iterable
     108: astore        4
     110: iconst_0
     111: istore        5
     113: aload         4
     115: bipush        10
     117: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     120: invokestatic  #128                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     123: bipush        16
     125: invokestatic  #134                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     128: istore        6
     130: aload         4
     132: astore        7
     134: new           #136                // class java/util/LinkedHashMap
     137: dup
     138: iload         6
     140: invokespecial #137                // Method java/util/LinkedHashMap."<init>":(I)V
     143: checkcast     #139                // class java/util/Map
     146: astore        8
     148: iconst_0
     149: istore        9
     151: aload         7
     153: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     158: astore        10
     160: aload         10
     162: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     167: ifeq          231
     170: aload         10
     172: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     177: astore        11
     179: aload         8
     181: astore        12
     183: aload         11
     185: checkcast     #67                 // class net/rafaeltoledo/kotlin/advent/ScratchCard
     188: astore        13
     190: iconst_0
     191: istore        14
     193: aload         13
     195: invokevirtual #142                // Method net/rafaeltoledo/kotlin/advent/ScratchCard.getIdentifier:()I
     198: invokestatic  #87                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     201: iconst_1
     202: invokestatic  #87                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     205: invokestatic  #148                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     208: astore        13
     210: aload         12
     212: aload         13
     214: invokevirtual #153                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     217: aload         13
     219: invokevirtual #156                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     222: invokeinterface #160,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     227: pop
     228: goto          160
     231: aload         8
     233: nop
     234: invokestatic  #164                // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     237: astore_3
     238: aload_2
     239: checkcast     #24                 // class java/lang/Iterable
     242: astore        4
     244: nop
     245: iconst_0
     246: istore        5
     248: iconst_0
     249: istore        6
     251: aload         4
     253: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     258: astore        7
     260: aload         7
     262: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     267: ifeq          551
     270: aload         7
     272: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     277: astore        8
     279: iload         6
     281: iinc          6, 1
     284: istore        9
     286: iload         9
     288: ifge          294
     291: invokestatic  #167                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     294: iload         9
     296: aload         8
     298: checkcast     #67                 // class net/rafaeltoledo/kotlin/advent/ScratchCard
     301: astore        10
     303: istore        11
     305: iconst_0
     306: istore        12
     308: iload         11
     310: iconst_1
     311: iadd
     312: istore        13
     314: aload_3
     315: iload         13
     317: invokestatic  #87                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     320: invokeinterface #171,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     325: checkcast     #83                 // class java/lang/Integer
     328: dup
     329: ifnull        338
     332: invokevirtual #172                // Method java/lang/Integer.intValue:()I
     335: goto          340
     338: pop
     339: iconst_1
     340: istore        14
     342: aload         10
     344: invokevirtual #71                 // Method net/rafaeltoledo/kotlin/advent/ScratchCard.getNumbers:()Ljava/util/List;
     347: checkcast     #24                 // class java/lang/Iterable
     350: astore        15
     352: iconst_0
     353: istore        16
     355: aload         15
     357: astore        17
     359: new           #26                 // class java/util/ArrayList
     362: dup
     363: invokespecial #72                 // Method java/util/ArrayList."<init>":()V
     366: checkcast     #37                 // class java/util/Collection
     369: astore        18
     371: iconst_0
     372: istore        19
     374: aload         17
     376: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     381: astore        20
     383: aload         20
     385: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     390: ifeq          446
     393: aload         20
     395: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     400: astore        21
     402: aload         21
     404: checkcast     #74                 // class java/lang/Number
     407: invokevirtual #78                 // Method java/lang/Number.intValue:()I
     410: istore        22
     412: iconst_0
     413: istore        23
     415: aload         10
     417: invokevirtual #81                 // Method net/rafaeltoledo/kotlin/advent/ScratchCard.getWinningNumbers:()Ljava/util/List;
     420: iload         22
     422: invokestatic  #87                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     425: invokeinterface #90,  2           // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     430: ifeq          383
     433: aload         18
     435: aload         21
     437: invokeinterface #63,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     442: pop
     443: goto          383
     446: aload         18
     448: checkcast     #65                 // class java/util/List
     451: nop
     452: checkcast     #37                 // class java/util/Collection
     455: invokeinterface #173,  1          // InterfaceMethod java/util/Collection.size:()I
     460: istore        24
     462: iconst_0
     463: istore        15
     465: iload         15
     467: iload         24
     469: if_icmpge     546
     472: iload         13
     474: iload         15
     476: iconst_1
     477: iadd
     478: iadd
     479: istore        16
     481: aload_3
     482: iload         16
     484: invokestatic  #87                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     487: invokeinterface #171,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     492: checkcast     #83                 // class java/lang/Integer
     495: dup
     496: ifnull        538
     499: checkcast     #74                 // class java/lang/Number
     502: invokevirtual #78                 // Method java/lang/Number.intValue:()I
     505: istore        19
     507: iconst_0
     508: istore        20
     510: iload         16
     512: invokestatic  #87                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     515: astore        21
     517: aload_3
     518: aload         21
     520: iload         19
     522: iload         14
     524: iadd
     525: invokestatic  #87                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     528: invokeinterface #160,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     533: pop
     534: nop
     535: goto          540
     538: pop
     539: nop
     540: iinc          15, 1
     543: goto          465
     546: nop
     547: nop
     548: goto          260
     551: nop
     552: aload_3
     553: invokestatic  #177                // Method kotlin/collections/MapsKt.toList:(Ljava/util/Map;)Ljava/util/List;
     556: checkcast     #24                 // class java/lang/Iterable
     559: astore        4
     561: iconst_0
     562: istore        5
     564: aload         4
     566: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     571: astore        6
     573: aload         6
     575: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     580: ifeq          629
     583: aload         6
     585: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     590: astore        7
     592: iload         5
     594: aload         7
     596: checkcast     #150                // class kotlin/Pair
     599: astore        8
     601: istore        25
     603: iconst_0
     604: istore        9
     606: aload         8
     608: invokevirtual #156                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     611: checkcast     #74                 // class java/lang/Number
     614: invokevirtual #78                 // Method java/lang/Number.intValue:()I
     617: istore        26
     619: iload         25
     621: iload         26
     623: iadd
     624: istore        5
     626: goto          573
     629: iload         5
     631: ireturn
}