package string

/**
 * https://leetcode.com/problems/valid-number/description/
 */
class IsNumer {
    enum class TokenType {
        DIGIT,
        SIGN,
        DOT,
        EXPONENT,
        INVALID
    }

    private val dfa = hashMapOf(
        Pair(0, hashMapOf(Pair(TokenType.DIGIT, 1), Pair(TokenType.SIGN, 2), Pair(TokenType.DOT, 3))), // Start
        Pair(1, hashMapOf(Pair(TokenType.DIGIT, 1), Pair(TokenType.DOT, 4), Pair(TokenType.EXPONENT, 5))), // digit
        Pair(2, hashMapOf(Pair(TokenType.DIGIT, 1), Pair(TokenType.DOT, 3))), // optional sign
        Pair(3, hashMapOf(Pair(TokenType.DIGIT, 4))), // dot
        Pair(
            4,
            hashMapOf(Pair(TokenType.DIGIT, 4), Pair(TokenType.EXPONENT, 5))
        ), // this is the digit state after a dot
        Pair(5, hashMapOf(Pair(TokenType.DIGIT, 7), Pair(TokenType.SIGN, 6))), // exponent
        Pair(6, hashMapOf(Pair(TokenType.DIGIT, 7))), // sign after exponent e+
        Pair(7, hashMapOf(Pair(TokenType.DIGIT, 7))) // digit after exponent e7
    )
    private val validStates = setOf(1, 4, 7)

    fun isNumber(s: String): Boolean {
        var state = 0

        for (token in s) {
            val tokenType = getTokenType(token)
            if (tokenType == TokenType.INVALID) {
                return false
            } else {
                val tempState = transition(state, tokenType)
                if (tempState == null) {
                    return false
                } else {
                    state = tempState
                }
            }
        }

        return isValidEndState(state)
    }

    private fun isValidEndState(state: Int): Boolean {
        return validStates.contains(state)
    }

    private fun transition(state: Int, tokenType: TokenType): Int? {
        val currentState = dfa[state]
        return currentState?.let { it[tokenType] }
    }

    private fun getTokenType(token: Char): TokenType {
        return when (token) {
            '+' -> TokenType.SIGN
            '-' -> TokenType.SIGN
            '.' -> TokenType.DOT
            in '0'..'9' -> TokenType.DIGIT
            in "eE" -> TokenType.EXPONENT
            else -> TokenType.INVALID
        }
    }
}

fun main() {
    println(IsNumer().isNumber("a+1"))
    println(IsNumer().isNumber("1"))
    println(IsNumer().isNumber("+123"))
    println(IsNumer().isNumber(".1"))
    println(IsNumer().isNumber("+1e3"))
    println(IsNumer().isNumber("+1e3.5"))
    println(IsNumer().isNumber("+1E3.5"))
    println(IsNumer().isNumber("+1E-356"))
    println(IsNumer().isNumber("+1E+3"))
    println(IsNumer().isNumber("+1.0E+3"))
    println(IsNumer().isNumber("+1.234E+3"))
    println(IsNumer().isNumber(".E3"))
}

Compiled from "IsNumer.kt"
public final class string.IsNumerKt {
  public static final void main();
    Code:
       0: new           #8                  // class string/IsNumer
       3: dup
       4: invokespecial #11                 // Method string/IsNumer."<init>":()V
       7: ldc           #13                 // String a+1
       9: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
      12: istore_0
      13: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
      16: iload_0
      17: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
      20: new           #8                  // class string/IsNumer
      23: dup
      24: invokespecial #11                 // Method string/IsNumer."<init>":()V
      27: ldc           #31                 // String 1
      29: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
      32: istore_0
      33: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: iload_0
      37: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
      40: new           #8                  // class string/IsNumer
      43: dup
      44: invokespecial #11                 // Method string/IsNumer."<init>":()V
      47: ldc           #33                 // String +123
      49: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
      52: istore_0
      53: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
      56: iload_0
      57: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
      60: new           #8                  // class string/IsNumer
      63: dup
      64: invokespecial #11                 // Method string/IsNumer."<init>":()V
      67: ldc           #35                 // String .1
      69: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
      72: istore_0
      73: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
      76: iload_0
      77: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
      80: new           #8                  // class string/IsNumer
      83: dup
      84: invokespecial #11                 // Method string/IsNumer."<init>":()V
      87: ldc           #37                 // String +1e3
      89: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
      92: istore_0
      93: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
      96: iload_0
      97: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
     100: new           #8                  // class string/IsNumer
     103: dup
     104: invokespecial #11                 // Method string/IsNumer."<init>":()V
     107: ldc           #39                 // String +1e3.5
     109: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
     112: istore_0
     113: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
     116: iload_0
     117: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
     120: new           #8                  // class string/IsNumer
     123: dup
     124: invokespecial #11                 // Method string/IsNumer."<init>":()V
     127: ldc           #41                 // String +1E3.5
     129: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
     132: istore_0
     133: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
     136: iload_0
     137: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
     140: new           #8                  // class string/IsNumer
     143: dup
     144: invokespecial #11                 // Method string/IsNumer."<init>":()V
     147: ldc           #43                 // String +1E-356
     149: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
     152: istore_0
     153: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
     156: iload_0
     157: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
     160: new           #8                  // class string/IsNumer
     163: dup
     164: invokespecial #11                 // Method string/IsNumer."<init>":()V
     167: ldc           #45                 // String +1E+3
     169: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
     172: istore_0
     173: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
     176: iload_0
     177: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
     180: new           #8                  // class string/IsNumer
     183: dup
     184: invokespecial #11                 // Method string/IsNumer."<init>":()V
     187: ldc           #47                 // String +1.0E+3
     189: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
     192: istore_0
     193: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
     196: iload_0
     197: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
     200: new           #8                  // class string/IsNumer
     203: dup
     204: invokespecial #11                 // Method string/IsNumer."<init>":()V
     207: ldc           #49                 // String +1.234E+3
     209: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
     212: istore_0
     213: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
     216: iload_0
     217: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
     220: new           #8                  // class string/IsNumer
     223: dup
     224: invokespecial #11                 // Method string/IsNumer."<init>":()V
     227: ldc           #51                 // String .E3
     229: invokevirtual #17                 // Method string/IsNumer.isNumber:(Ljava/lang/String;)Z
     232: istore_0
     233: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
     236: iload_0
     237: invokevirtual #29                 // Method java/io/PrintStream.println:(Z)V
     240: return

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

Compiled from "IsNumer.kt"
public final class string.IsNumer {
  private final java.util.HashMap<java.lang.Integer, java.util.HashMap<string.IsNumer$TokenType, java.lang.Integer>> dfa;

  private final java.util.Set<java.lang.Integer> validStates;

  public string.IsNumer();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: bipush        8
       7: anewarray     #10                 // class kotlin/Pair
      10: astore_1
      11: aload_1
      12: iconst_0
      13: new           #10                 // class kotlin/Pair
      16: dup
      17: iconst_0
      18: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      21: iconst_3
      22: anewarray     #10                 // class kotlin/Pair
      25: astore_2
      26: aload_2
      27: iconst_0
      28: new           #10                 // class kotlin/Pair
      31: dup
      32: getstatic     #22                 // Field string/IsNumer$TokenType.DIGIT:Lstring/IsNumer$TokenType;
      35: iconst_1
      36: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      39: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      42: aastore
      43: aload_2
      44: iconst_1
      45: new           #10                 // class kotlin/Pair
      48: dup
      49: getstatic     #28                 // Field string/IsNumer$TokenType.SIGN:Lstring/IsNumer$TokenType;
      52: iconst_2
      53: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      56: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      59: aastore
      60: aload_2
      61: iconst_2
      62: new           #10                 // class kotlin/Pair
      65: dup
      66: getstatic     #31                 // Field string/IsNumer$TokenType.DOT:Lstring/IsNumer$TokenType;
      69: iconst_3
      70: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      73: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      76: aastore
      77: aload_2
      78: invokestatic  #37                 // Method kotlin/collections/MapsKt.hashMapOf:([Lkotlin/Pair;)Ljava/util/HashMap;
      81: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      84: aastore
      85: aload_1
      86: iconst_1
      87: new           #10                 // class kotlin/Pair
      90: dup
      91: iconst_1
      92: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      95: iconst_3
      96: anewarray     #10                 // class kotlin/Pair
      99: astore_2
     100: aload_2
     101: iconst_0
     102: new           #10                 // class kotlin/Pair
     105: dup
     106: getstatic     #22                 // Field string/IsNumer$TokenType.DIGIT:Lstring/IsNumer$TokenType;
     109: iconst_1
     110: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     113: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     116: aastore
     117: aload_2
     118: iconst_1
     119: new           #10                 // class kotlin/Pair
     122: dup
     123: getstatic     #31                 // Field string/IsNumer$TokenType.DOT:Lstring/IsNumer$TokenType;
     126: iconst_4
     127: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     130: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     133: aastore
     134: aload_2
     135: iconst_2
     136: new           #10                 // class kotlin/Pair
     139: dup
     140: getstatic     #40                 // Field string/IsNumer$TokenType.EXPONENT:Lstring/IsNumer$TokenType;
     143: iconst_5
     144: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     147: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     150: aastore
     151: aload_2
     152: invokestatic  #37                 // Method kotlin/collections/MapsKt.hashMapOf:([Lkotlin/Pair;)Ljava/util/HashMap;
     155: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     158: aastore
     159: aload_1
     160: iconst_2
     161: new           #10                 // class kotlin/Pair
     164: dup
     165: iconst_2
     166: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     169: iconst_2
     170: anewarray     #10                 // class kotlin/Pair
     173: astore_2
     174: aload_2
     175: iconst_0
     176: new           #10                 // class kotlin/Pair
     179: dup
     180: getstatic     #22                 // Field string/IsNumer$TokenType.DIGIT:Lstring/IsNumer$TokenType;
     183: iconst_1
     184: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     187: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     190: aastore
     191: aload_2
     192: iconst_1
     193: new           #10                 // class kotlin/Pair
     196: dup
     197: getstatic     #31                 // Field string/IsNumer$TokenType.DOT:Lstring/IsNumer$TokenType;
     200: iconst_3
     201: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     204: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     207: aastore
     208: aload_2
     209: invokestatic  #37                 // Method kotlin/collections/MapsKt.hashMapOf:([Lkotlin/Pair;)Ljava/util/HashMap;
     212: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     215: aastore
     216: aload_1
     217: iconst_3
     218: new           #10                 // class kotlin/Pair
     221: dup
     222: iconst_3
     223: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     226: iconst_1
     227: anewarray     #10                 // class kotlin/Pair
     230: astore_2
     231: aload_2
     232: iconst_0
     233: new           #10                 // class kotlin/Pair
     236: dup
     237: getstatic     #22                 // Field string/IsNumer$TokenType.DIGIT:Lstring/IsNumer$TokenType;
     240: iconst_4
     241: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     244: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     247: aastore
     248: aload_2
     249: invokestatic  #37                 // Method kotlin/collections/MapsKt.hashMapOf:([Lkotlin/Pair;)Ljava/util/HashMap;
     252: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     255: aastore
     256: aload_1
     257: iconst_4
     258: new           #10                 // class kotlin/Pair
     261: dup
     262: iconst_4
     263: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     266: iconst_2
     267: anewarray     #10                 // class kotlin/Pair
     270: astore_2
     271: aload_2
     272: iconst_0
     273: new           #10                 // class kotlin/Pair
     276: dup
     277: getstatic     #22                 // Field string/IsNumer$TokenType.DIGIT:Lstring/IsNumer$TokenType;
     280: iconst_4
     281: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     284: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     287: aastore
     288: aload_2
     289: iconst_1
     290: new           #10                 // class kotlin/Pair
     293: dup
     294: getstatic     #40                 // Field string/IsNumer$TokenType.EXPONENT:Lstring/IsNumer$TokenType;
     297: iconst_5
     298: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     301: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     304: aastore
     305: aload_2
     306: invokestatic  #37                 // Method kotlin/collections/MapsKt.hashMapOf:([Lkotlin/Pair;)Ljava/util/HashMap;
     309: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     312: aastore
     313: aload_1
     314: iconst_5
     315: new           #10                 // class kotlin/Pair
     318: dup
     319: iconst_5
     320: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     323: iconst_2
     324: anewarray     #10                 // class kotlin/Pair
     327: astore_2
     328: aload_2
     329: iconst_0
     330: new           #10                 // class kotlin/Pair
     333: dup
     334: getstatic     #22                 // Field string/IsNumer$TokenType.DIGIT:Lstring/IsNumer$TokenType;
     337: bipush        7
     339: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     342: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     345: aastore
     346: aload_2
     347: iconst_1
     348: new           #10                 // class kotlin/Pair
     351: dup
     352: getstatic     #28                 // Field string/IsNumer$TokenType.SIGN:Lstring/IsNumer$TokenType;
     355: bipush        6
     357: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     360: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     363: aastore
     364: aload_2
     365: invokestatic  #37                 // Method kotlin/collections/MapsKt.hashMapOf:([Lkotlin/Pair;)Ljava/util/HashMap;
     368: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     371: aastore
     372: aload_1
     373: bipush        6
     375: new           #10                 // class kotlin/Pair
     378: dup
     379: bipush        6
     381: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     384: iconst_1
     385: anewarray     #10                 // class kotlin/Pair
     388: astore_2
     389: aload_2
     390: iconst_0
     391: new           #10                 // class kotlin/Pair
     394: dup
     395: getstatic     #22                 // Field string/IsNumer$TokenType.DIGIT:Lstring/IsNumer$TokenType;
     398: bipush        7
     400: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     403: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     406: aastore
     407: aload_2
     408: invokestatic  #37                 // Method kotlin/collections/MapsKt.hashMapOf:([Lkotlin/Pair;)Ljava/util/HashMap;
     411: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     414: aastore
     415: aload_1
     416: bipush        7
     418: new           #10                 // class kotlin/Pair
     421: dup
     422: bipush        7
     424: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     427: iconst_1
     428: anewarray     #10                 // class kotlin/Pair
     431: astore_2
     432: aload_2
     433: iconst_0
     434: new           #10                 // class kotlin/Pair
     437: dup
     438: getstatic     #22                 // Field string/IsNumer$TokenType.DIGIT:Lstring/IsNumer$TokenType;
     441: bipush        7
     443: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     446: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     449: aastore
     450: aload_2
     451: invokestatic  #37                 // Method kotlin/collections/MapsKt.hashMapOf:([Lkotlin/Pair;)Ljava/util/HashMap;
     454: invokespecial #25                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     457: aastore
     458: aload_1
     459: invokestatic  #37                 // Method kotlin/collections/MapsKt.hashMapOf:([Lkotlin/Pair;)Ljava/util/HashMap;
     462: putfield      #44                 // Field dfa:Ljava/util/HashMap;
     465: aload_0
     466: iconst_3
     467: anewarray     #12                 // class java/lang/Integer
     470: astore_1
     471: aload_1
     472: iconst_0
     473: iconst_1
     474: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     477: aastore
     478: aload_1
     479: iconst_1
     480: iconst_4
     481: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     484: aastore
     485: aload_1
     486: iconst_2
     487: bipush        7
     489: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     492: aastore
     493: aload_1
     494: invokestatic  #50                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     497: putfield      #54                 // Field validStates:Ljava/util/Set;
     500: return

  public final boolean isNumber(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #61                 // String s
       3: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: aload_1
      11: invokevirtual #73                 // Method java/lang/String.length:()I
      14: istore        4
      16: iload_3
      17: iload         4
      19: if_icmpge     75
      22: aload_1
      23: iload_3
      24: invokevirtual #77                 // Method java/lang/String.charAt:(I)C
      27: istore        5
      29: aload_0
      30: iload         5
      32: invokespecial #81                 // Method getTokenType:(C)Lstring/IsNumer$TokenType;
      35: astore        6
      37: aload         6
      39: getstatic     #84                 // Field string/IsNumer$TokenType.INVALID:Lstring/IsNumer$TokenType;
      42: if_acmpne     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: iload_2
      49: aload         6
      51: invokespecial #88                 // Method transition:(ILstring/IsNumer$TokenType;)Ljava/lang/Integer;
      54: astore        7
      56: aload         7
      58: ifnonnull     63
      61: iconst_0
      62: ireturn
      63: aload         7
      65: invokevirtual #91                 // Method java/lang/Integer.intValue:()I
      68: istore_2
      69: iinc          3, 1
      72: goto          16
      75: aload_0
      76: iload_2
      77: invokespecial #95                 // Method isValidEndState:(I)Z
      80: ireturn

  private final boolean isValidEndState(int);
    Code:
       0: aload_0
       1: getfield      #54                 // Field validStates:Ljava/util/Set;
       4: iload_1
       5: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       8: invokeinterface #109,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      13: ireturn

  private final java.lang.Integer transition(int, string.IsNumer$TokenType);
    Code:
       0: aload_0
       1: getfield      #44                 // Field dfa:Ljava/util/HashMap;
       4: iload_1
       5: invokestatic  #16                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       8: invokevirtual #115                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      11: checkcast     #111                // class java/util/HashMap
      14: astore_3
      15: aload_3
      16: dup
      17: ifnull        37
      20: astore        4
      22: iconst_0
      23: istore        5
      25: aload         4
      27: aload_2
      28: invokevirtual #115                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      31: checkcast     #12                 // class java/lang/Integer
      34: goto          39
      37: pop
      38: aconst_null
      39: areturn

  private final string.IsNumer$TokenType getTokenType(char);
    Code:
       0: iload_1
       1: istore_2
       2: iload_2
       3: bipush        43
       5: if_icmpne     14
       8: getstatic     #28                 // Field string/IsNumer$TokenType.SIGN:Lstring/IsNumer$TokenType;
      11: goto          92
      14: iload_2
      15: bipush        45
      17: if_icmpne     26
      20: getstatic     #28                 // Field string/IsNumer$TokenType.SIGN:Lstring/IsNumer$TokenType;
      23: goto          92
      26: iload_2
      27: bipush        46
      29: if_icmpne     38
      32: getstatic     #31                 // Field string/IsNumer$TokenType.DOT:Lstring/IsNumer$TokenType;
      35: goto          92
      38: bipush        48
      40: iload_2
      41: if_icmpgt     58
      44: iload_2
      45: bipush        58
      47: if_icmpge     54
      50: iconst_1
      51: goto          59
      54: iconst_0
      55: goto          59
      58: iconst_0
      59: ifeq          68
      62: getstatic     #22                 // Field string/IsNumer$TokenType.DIGIT:Lstring/IsNumer$TokenType;
      65: goto          92
      68: ldc           #120                // String eE
      70: checkcast     #122                // class java/lang/CharSequence
      73: iload_2
      74: iconst_0
      75: iconst_2
      76: aconst_null
      77: invokestatic  #128                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
      80: ifeq          89
      83: getstatic     #40                 // Field string/IsNumer$TokenType.EXPONENT:Lstring/IsNumer$TokenType;
      86: goto          92
      89: getstatic     #84                 // Field string/IsNumer$TokenType.INVALID:Lstring/IsNumer$TokenType;
      92: areturn
}

Compiled from "IsNumer.kt"
public final class string.IsNumer$TokenType extends java.lang.Enum<string.IsNumer$TokenType> {
  public static final string.IsNumer$TokenType DIGIT;

  public static final string.IsNumer$TokenType SIGN;

  public static final string.IsNumer$TokenType DOT;

  public static final string.IsNumer$TokenType EXPONENT;

  public static final string.IsNumer$TokenType INVALID;

  private static final string.IsNumer$TokenType[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private string.IsNumer$TokenType();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #10                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: return

  public static string.IsNumer$TokenType[] values();
    Code:
       0: getstatic     #22                 // Field $VALUES:[Lstring/IsNumer$TokenType;
       3: invokevirtual #28                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #29                 // class "[Lstring/IsNumer$TokenType;"
       9: areturn

  public static string.IsNumer$TokenType valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class string/IsNumer$TokenType
       2: aload_0
       3: invokestatic  #34                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class string/IsNumer$TokenType
       9: areturn

  public static kotlin.enums.EnumEntries<string.IsNumer$TokenType> getEntries();
    Code:
       0: getstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final string.IsNumer$TokenType[] $values();
    Code:
       0: iconst_5
       1: anewarray     #2                  // class string/IsNumer$TokenType
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #47                 // Field DIGIT:Lstring/IsNumer$TokenType;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #50                 // Field SIGN:Lstring/IsNumer$TokenType;
      16: aastore
      17: aload_0
      18: iconst_2
      19: getstatic     #53                 // Field DOT:Lstring/IsNumer$TokenType;
      22: aastore
      23: aload_0
      24: iconst_3
      25: getstatic     #56                 // Field EXPONENT:Lstring/IsNumer$TokenType;
      28: aastore
      29: aload_0
      30: iconst_4
      31: getstatic     #59                 // Field INVALID:Lstring/IsNumer$TokenType;
      34: aastore
      35: aload_0
      36: areturn

  static {};
    Code:
       0: new           #2                  // class string/IsNumer$TokenType
       3: dup
       4: ldc           #61                 // String DIGIT
       6: iconst_0
       7: invokespecial #62                 // Method "<init>":(Ljava/lang/String;I)V
      10: putstatic     #47                 // Field DIGIT:Lstring/IsNumer$TokenType;
      13: new           #2                  // class string/IsNumer$TokenType
      16: dup
      17: ldc           #63                 // String SIGN
      19: iconst_1
      20: invokespecial #62                 // Method "<init>":(Ljava/lang/String;I)V
      23: putstatic     #50                 // Field SIGN:Lstring/IsNumer$TokenType;
      26: new           #2                  // class string/IsNumer$TokenType
      29: dup
      30: ldc           #64                 // String DOT
      32: iconst_2
      33: invokespecial #62                 // Method "<init>":(Ljava/lang/String;I)V
      36: putstatic     #53                 // Field DOT:Lstring/IsNumer$TokenType;
      39: new           #2                  // class string/IsNumer$TokenType
      42: dup
      43: ldc           #65                 // String EXPONENT
      45: iconst_3
      46: invokespecial #62                 // Method "<init>":(Ljava/lang/String;I)V
      49: putstatic     #56                 // Field EXPONENT:Lstring/IsNumer$TokenType;
      52: new           #2                  // class string/IsNumer$TokenType
      55: dup
      56: ldc           #66                 // String INVALID
      58: iconst_4
      59: invokespecial #62                 // Method "<init>":(Ljava/lang/String;I)V
      62: putstatic     #59                 // Field INVALID:Lstring/IsNumer$TokenType;
      65: invokestatic  #68                 // Method $values:()[Lstring/IsNumer$TokenType;
      68: putstatic     #22                 // Field $VALUES:[Lstring/IsNumer$TokenType;
      71: getstatic     #22                 // Field $VALUES:[Lstring/IsNumer$TokenType;
      74: checkcast     #70                 // class "[Ljava/lang/Enum;"
      77: invokestatic  #76                 // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      80: putstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      83: return
}


package string

/*
https://leetcode.com/problems/minimum-window-substring/
 */
class MinimumWindowSubstring {

    val tMap = HashMap<Char, Int>()
    private fun isAcceptable(map: HashMap<Char, Int>): Boolean {
        for (key in map.keys) {
            if (map[key]!! > 0) {
                return false
            }
        }
        return true
    }

    private fun shouldShrinkWindow(map: java.util.HashMap<Char, Int>): Boolean {
        if (isAcceptable(map)) {
            return true
        }
        for (key in map.keys) {
            if (map[key]!! > 0) {
                return false
            }
        }
        return true
    }

    fun minWindow(src: String, t: String): String {
        for (char in t) { // hash the count of chars in t
            if (tMap.containsKey(char)) {
                tMap[char] = tMap[char]!!.inc()
            } else {
                tMap[char] = 1
            }
        }

        var l = 0
        var r = l
        var minLength = Int.MAX_VALUE
        var rangeStart = 0
        var rangeEnd = 0
        while (r < src.length) {

            val end = src[r]
            if (tMap.containsKey(end)) {
                tMap[end] = tMap[end]!!.dec()
                r++
            } else {
                r++
            }

            while (l <= r && shouldShrinkWindow(map = tMap)) {
                if ((r - l) < minLength) {
                    minLength = r - l
                    rangeStart = l
                    rangeEnd = r
                }

                // try to shrink the window
                val start = src[l]
                if (tMap.containsKey(start)) {
                    if (tMap[start]!!.inc() <= 0) {
                        tMap[start] = tMap[start]!!.inc()
                        l++
                        continue
                    } else {
                        break
                    }
                } else {
                    l++
                }
            }
        }
        return src.substring(startIndex = rangeStart, endIndex = rangeEnd)
    }
}

fun main() {
    println(
        MinimumWindowSubstring().minWindow("ADOBECODEBANC", "ABC")
    )
}
/*
1- Hour debug (java, js, python)
* Code with issues
* Find the bugs and fix them

2- 2 hours take home
* Algorithm coding problem
* Data infra (schema design)
* System design proposal
 */

Compiled from "MinimumWindowSubstring.kt"
public final class string.MinimumWindowSubstring {
  private final java.util.HashMap<java.lang.Character, java.lang.Integer> tMap;

  public string.MinimumWindowSubstring();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: new           #10                 // class java/util/HashMap
       8: dup
       9: invokespecial #11                 // Method java/util/HashMap."<init>":()V
      12: putfield      #15                 // Field tMap:Ljava/util/HashMap;
      15: return

  public final java.util.HashMap<java.lang.Character, java.lang.Integer> getTMap();
    Code:
       0: aload_0
       1: getfield      #15                 // Field tMap:Ljava/util/HashMap;
       4: areturn

  private final boolean isAcceptable(java.util.HashMap<java.lang.Character, java.lang.Integer>);
    Code:
       0: aload_1
       1: invokevirtual #28                 // Method java/util/HashMap.keySet:()Ljava/util/Set;
       4: invokeinterface #34,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
       9: astore_2
      10: aload_2
      11: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      16: ifeq          61
      19: aload_2
      20: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      25: dup
      26: ldc           #46                 // String next(...)
      28: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      31: checkcast     #54                 // class java/lang/Character
      34: invokevirtual #58                 // Method java/lang/Character.charValue:()C
      37: istore_3
      38: aload_1
      39: iload_3
      40: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      43: invokevirtual #66                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      46: dup
      47: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      50: checkcast     #72                 // class java/lang/Number
      53: invokevirtual #76                 // Method java/lang/Number.intValue:()I
      56: ifle          10
      59: iconst_0
      60: ireturn
      61: iconst_1
      62: ireturn

  private final boolean shouldShrinkWindow(java.util.HashMap<java.lang.Character, java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_1
       2: invokespecial #82                 // Method isAcceptable:(Ljava/util/HashMap;)Z
       5: ifeq          10
       8: iconst_1
       9: ireturn
      10: aload_1
      11: invokevirtual #28                 // Method java/util/HashMap.keySet:()Ljava/util/Set;
      14: invokeinterface #34,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      19: astore_2
      20: aload_2
      21: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifeq          71
      29: aload_2
      30: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      35: dup
      36: ldc           #46                 // String next(...)
      38: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      41: checkcast     #54                 // class java/lang/Character
      44: invokevirtual #58                 // Method java/lang/Character.charValue:()C
      47: istore_3
      48: aload_1
      49: iload_3
      50: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      53: invokevirtual #66                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      56: dup
      57: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      60: checkcast     #72                 // class java/lang/Number
      63: invokevirtual #76                 // Method java/lang/Number.intValue:()I
      66: ifle          20
      69: iconst_0
      70: ireturn
      71: iconst_1
      72: ireturn

  public final java.lang.String minWindow(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #86                 // String src
       3: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #91                 // String t
       9: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_3
      14: aload_2
      15: invokevirtual #96                 // Method java/lang/String.length:()I
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     132
      26: aload_2
      27: iload_3
      28: invokevirtual #100                // Method java/lang/String.charAt:(I)C
      31: istore        5
      33: aload_0
      34: getfield      #15                 // Field tMap:Ljava/util/HashMap;
      37: iload         5
      39: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      42: invokevirtual #104                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
      45: ifeq          100
      48: iload         5
      50: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      53: astore        7
      55: aload_0
      56: getfield      #15                 // Field tMap:Ljava/util/HashMap;
      59: checkcast     #106                // class java/util/Map
      62: aload         7
      64: aload_0
      65: getfield      #15                 // Field tMap:Ljava/util/HashMap;
      68: iload         5
      70: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      73: invokevirtual #66                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      76: dup
      77: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      80: checkcast     #72                 // class java/lang/Number
      83: invokevirtual #76                 // Method java/lang/Number.intValue:()I
      86: iconst_1
      87: iadd
      88: invokestatic  #111                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: invokeinterface #115,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      96: pop
      97: goto          126
     100: iload         5
     102: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     105: astore        7
     107: aload_0
     108: getfield      #15                 // Field tMap:Ljava/util/HashMap;
     111: checkcast     #106                // class java/util/Map
     114: aload         7
     116: iconst_1
     117: invokestatic  #111                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     120: invokeinterface #115,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     125: pop
     126: iinc          3, 1
     129: goto          20
     132: iconst_0
     133: istore_3
     134: iload_3
     135: istore        4
     137: ldc           #116                // int 2147483647
     139: istore        5
     141: iconst_0
     142: istore        6
     144: iconst_0
     145: istore        7
     147: iload         4
     149: aload_1
     150: invokevirtual #96                 // Method java/lang/String.length:()I
     153: if_icmpge     389
     156: aload_1
     157: iload         4
     159: invokevirtual #100                // Method java/lang/String.charAt:(I)C
     162: istore        8
     164: aload_0
     165: getfield      #15                 // Field tMap:Ljava/util/HashMap;
     168: iload         8
     170: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     173: invokevirtual #104                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
     176: ifeq          234
     179: iload         8
     181: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     184: astore        10
     186: aload_0
     187: getfield      #15                 // Field tMap:Ljava/util/HashMap;
     190: checkcast     #106                // class java/util/Map
     193: aload         10
     195: aload_0
     196: getfield      #15                 // Field tMap:Ljava/util/HashMap;
     199: iload         8
     201: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     204: invokevirtual #66                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     207: dup
     208: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     211: checkcast     #72                 // class java/lang/Number
     214: invokevirtual #76                 // Method java/lang/Number.intValue:()I
     217: iconst_m1
     218: iadd
     219: invokestatic  #111                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     222: invokeinterface #115,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     227: pop
     228: iinc          4, 1
     231: goto          237
     234: iinc          4, 1
     237: iload_3
     238: iload         4
     240: if_icmpgt     147
     243: aload_0
     244: aload_0
     245: getfield      #15                 // Field tMap:Ljava/util/HashMap;
     248: invokespecial #118                // Method shouldShrinkWindow:(Ljava/util/HashMap;)Z
     251: ifeq          147
     254: iload         4
     256: iload_3
     257: isub
     258: iload         5
     260: if_icmpge     276
     263: iload         4
     265: iload_3
     266: isub
     267: istore        5
     269: iload_3
     270: istore        6
     272: iload         4
     274: istore        7
     276: aload_1
     277: iload_3
     278: invokevirtual #100                // Method java/lang/String.charAt:(I)C
     281: istore        9
     283: aload_0
     284: getfield      #15                 // Field tMap:Ljava/util/HashMap;
     287: iload         9
     289: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     292: invokevirtual #104                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
     295: ifeq          383
     298: aload_0
     299: getfield      #15                 // Field tMap:Ljava/util/HashMap;
     302: iload         9
     304: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     307: invokevirtual #66                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     310: dup
     311: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     314: checkcast     #72                 // class java/lang/Number
     317: invokevirtual #76                 // Method java/lang/Number.intValue:()I
     320: iconst_1
     321: iadd
     322: ifgt          380
     325: iload         9
     327: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     330: astore        11
     332: aload_0
     333: getfield      #15                 // Field tMap:Ljava/util/HashMap;
     336: checkcast     #106                // class java/util/Map
     339: aload         11
     341: aload_0
     342: getfield      #15                 // Field tMap:Ljava/util/HashMap;
     345: iload         9
     347: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     350: invokevirtual #66                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     353: dup
     354: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     357: checkcast     #72                 // class java/lang/Number
     360: invokevirtual #76                 // Method java/lang/Number.intValue:()I
     363: iconst_1
     364: iadd
     365: invokestatic  #111                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     368: invokeinterface #115,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     373: pop
     374: iinc          3, 1
     377: goto          237
     380: goto          147
     383: iinc          3, 1
     386: goto          237
     389: aload_1
     390: iload         6
     392: iload         7
     394: invokevirtual #122                // Method java/lang/String.substring:(II)Ljava/lang/String;
     397: dup
     398: ldc           #124                // String substring(...)
     400: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     403: areturn
}

Compiled from "MinimumWindowSubstring.kt"
public final class string.MinimumWindowSubstringKt {
  public static final void main();
    Code:
       0: new           #8                  // class string/MinimumWindowSubstring
       3: dup
       4: invokespecial #11                 // Method string/MinimumWindowSubstring."<init>":()V
       7: ldc           #13                 // String ADOBECODEBANC
       9: ldc           #15                 // String ABC
      11: invokevirtual #19                 // Method string/MinimumWindowSubstring.minWindow:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      14: astore_0
      15: getstatic     #25                 // Field java/lang/System.out:Ljava/io/PrintStream;
      18: aload_0
      19: invokevirtual #31                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      22: return

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


package prefixSum

import kotlin.math.min
/*
https://leetcode.com/problems/minimum-size-subarray-sum/
 */
class MinSubArrayLen {
    fun minSubArrayLen(target: Int, nums: IntArray): Int {
        if (nums.isEmpty()) {
            return 0
        }
        var minSize = Int.MAX_VALUE
        val prefixSums = IntArray(nums.size)
        prefixSums[0] = nums[0]
        for (i in 1 until nums.size) {
            prefixSums[i] = prefixSums[i - 1] + nums[i]
        }

        for (i in prefixSums.indices) {
            val remainder = prefixSums[i] - target
            if (remainder < 0) {
                continue
            }
            val lowerBound = search(prefixSums, 0, i - 1, prefixSums[i], target)
            if (lowerBound != -1) {
                minSize = min(minSize, i - lowerBound + 1)
            }
        }

        return if (minSize == Int.MAX_VALUE) {
            0
        } else {
            minSize
        }
    }

    private fun search(array: IntArray, low: Int, hi: Int, prefixSum: Int, target: Int): Int {
        var start = low
        var end = hi
        var mid = (start + end) / 2
        while (start <= end) {
            mid = (start + end) / 2
            if (prefixSum - array[mid] == target) {
                return mid + 1
            } else if (prefixSum - array[mid] > target) {
                start = mid + 1
            } else {
                end = mid - 1
            }
        }
        return mid
    }
}

fun main() {
    val m = MinSubArrayLen()
    println(
        m.minSubArrayLen(20, intArrayOf(1, 2, 0, 6, 14, 15))
    ) // 2

//    println(
//        m.minSubArrayLen(20, intArrayOf(2, 16, 14, 15))
//    ) // 2
//
//    println(
//        m.minSubArrayLen(7, intArrayOf(2, 3, 1, 2, 4, 3))
//    ) // 2
//
//    println(
//        m.minSubArrayLen(4, intArrayOf(1, 4, 4))
//    ) // 1
//
//    println(
//        m.minSubArrayLen(15, intArrayOf(1, 2, 3, 4, 5))
//    ) // 5
//
//    println(
//        m.minSubArrayLen(11, intArrayOf(1, 1, 1, 1, 1, 1, 1, 1))
//    ) // 0
}

Compiled from "MinSubArrayLen.kt"
public final class prefixSum.MinSubArrayLenKt {
  public static final void main();
    Code:
       0: new           #8                  // class prefixSum/MinSubArrayLen
       3: dup
       4: invokespecial #11                 // Method prefixSum/MinSubArrayLen."<init>":()V
       7: astore_0
       8: aload_0
       9: bipush        20
      11: bipush        6
      13: newarray       int
      15: astore_1
      16: aload_1
      17: iconst_0
      18: iconst_1
      19: iastore
      20: aload_1
      21: iconst_1
      22: iconst_2
      23: iastore
      24: aload_1
      25: iconst_2
      26: iconst_0
      27: iastore
      28: aload_1
      29: iconst_3
      30: bipush        6
      32: iastore
      33: aload_1
      34: iconst_4
      35: bipush        14
      37: iastore
      38: aload_1
      39: iconst_5
      40: bipush        15
      42: iastore
      43: aload_1
      44: invokevirtual #15                 // Method prefixSum/MinSubArrayLen.minSubArrayLen:(I[I)I
      47: istore_1
      48: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
      51: iload_1
      52: invokevirtual #27                 // Method java/io/PrintStream.println:(I)V
      55: return

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

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

  public final int minSubArrayLen(int, int[]);
    Code:
       0: aload_2
       1: ldc           #15                 // String nums
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: arraylength
       8: ifne          15
      11: iconst_1
      12: goto          16
      15: iconst_0
      16: ifeq          21
      19: iconst_0
      20: ireturn
      21: ldc           #22                 // int 2147483647
      23: istore_3
      24: aload_2
      25: arraylength
      26: newarray       int
      28: astore        4
      30: aload         4
      32: iconst_0
      33: aload_2
      34: iconst_0
      35: iaload
      36: iastore
      37: iconst_1
      38: istore        5
      40: aload_2
      41: arraylength
      42: istore        6
      44: iload         5
      46: iload         6
      48: if_icmpge     74
      51: aload         4
      53: iload         5
      55: aload         4
      57: iload         5
      59: iconst_1
      60: isub
      61: iaload
      62: aload_2
      63: iload         5
      65: iaload
      66: iadd
      67: iastore
      68: iinc          5, 1
      71: goto          44
      74: iconst_0
      75: istore        5
      77: aload         4
      79: arraylength
      80: istore        6
      82: iload         5
      84: iload         6
      86: if_icmpge     149
      89: aload         4
      91: iload         5
      93: iaload
      94: iload_1
      95: isub
      96: istore        7
      98: iload         7
     100: ifge          106
     103: goto          143
     106: aload_0
     107: aload         4
     109: iconst_0
     110: iload         5
     112: iconst_1
     113: isub
     114: aload         4
     116: iload         5
     118: iaload
     119: iload_1
     120: invokespecial #26                 // Method search:([IIIII)I
     123: istore        8
     125: iload         8
     127: iconst_m1
     128: if_icmpeq     143
     131: iload_3
     132: iload         5
     134: iload         8
     136: isub
     137: iconst_1
     138: iadd
     139: invokestatic  #32                 // Method java/lang/Math.min:(II)I
     142: istore_3
     143: iinc          5, 1
     146: goto          82
     149: iload_3
     150: ldc           #22                 // int 2147483647
     152: if_icmpne     159
     155: iconst_0
     156: goto          160
     159: iload_3
     160: ireturn

  private final int search(int[], int, int, int, int);
    Code:
       0: iload_2
       1: istore        6
       3: iload_3
       4: istore        7
       6: iload         6
       8: iload         7
      10: iadd
      11: iconst_2
      12: idiv
      13: istore        8
      15: iload         6
      17: iload         7
      19: if_icmpgt     78
      22: iload         6
      24: iload         7
      26: iadd
      27: iconst_2
      28: idiv
      29: istore        8
      31: iload         4
      33: aload_1
      34: iload         8
      36: iaload
      37: isub
      38: iload         5
      40: if_icmpne     48
      43: iload         8
      45: iconst_1
      46: iadd
      47: ireturn
      48: iload         4
      50: aload_1
      51: iload         8
      53: iaload
      54: isub
      55: iload         5
      57: if_icmple     69
      60: iload         8
      62: iconst_1
      63: iadd
      64: istore        6
      66: goto          15
      69: iload         8
      71: iconst_1
      72: isub
      73: istore        7
      75: goto          15
      78: iload         8
      80: ireturn
}


package tree.segmentTree

import kotlin.math.*

class SubsetSum(list: Array<Int>) {

    private var segmentTree: IntArray

    override fun toString(): String {
        return segmentTree.contentToString()
    }
    init {
        val height = ceil(log(list.size.toDouble(), 2.0))
        val maxSize = (height + 1).pow(2) - 1

        segmentTree = IntArray(maxSize.toInt())

        constructTree(list, 0, 0, list.size - 1)

    }

    private fun constructTree(list: Array<Int>, current: Int, start: Int, end: Int): Int {
        if (start == end) {
            segmentTree[current] = list[start]
            return segmentTree[current]
        }
        val middle = (start + end) / 2
        val left = constructTree(list, current * 2 + 1, start, middle)
        val right = constructTree(list, current * 2 + 2, middle + 1, end)
        segmentTree[current] = left + right
        return segmentTree[current]
    }

    fun getSum(start: Int, end: Int): Int {
        val queryS = max(start, 0)
        val queryE = min(end, segmentTree.size - 1)

        return _getSum(queryS, queryE, 0, segmentTree.size - 1)
    }

    private fun _getSum(queryS: Int, queryE: Int, segmentS: Int, segmentE: Int): Int {
        return if (segmentS == segmentE) {
            if (segmentS > queryS && segmentE <= queryE) {
                segmentTree[segmentS]
            } else {
                0
            }
        } else {
            val segmentM = (segmentS + segmentE) / 2
            val left = _getSum(queryS, queryE, segmentS, segmentM)
            val right = _getSum(queryS, queryE, segmentM + 1, segmentE)
            left + right
        }
    }

    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            val sum = SubsetSum(arrayOf(1, 3, 5, 7, 9, 11))
            println(sum.toString())
//            println(sum.getSum(1, 3))
        }
    }
}

Compiled from "SubsetSum.kt"
public final class tree.segmentTree.SubsetSum {
  public static final tree.segmentTree.SubsetSum$Companion Companion;

  private int[] segmentTree;

  public tree.segmentTree.SubsetSum(java.lang.Integer[]);
    Code:
       0: aload_1
       1: ldc           #9                  // String list
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: nop
      11: aload_1
      12: arraylength
      13: i2d
      14: ldc2_w        #19                 // double 2.0d
      17: invokestatic  #26                 // Method kotlin/math/MathKt.log:(DD)D
      20: invokestatic  #32                 // Method java/lang/Math.ceil:(D)D
      23: dstore_2
      24: dload_2
      25: iconst_1
      26: i2d
      27: dadd
      28: iconst_2
      29: i2d
      30: invokestatic  #35                 // Method java/lang/Math.pow:(DD)D
      33: iconst_1
      34: i2d
      35: dsub
      36: dstore        4
      38: aload_0
      39: dload         4
      41: d2i
      42: newarray       int
      44: putfield      #39                 // Field segmentTree:[I
      47: aload_0
      48: aload_1
      49: iconst_0
      50: iconst_0
      51: aload_1
      52: arraylength
      53: iconst_1
      54: isub
      55: invokespecial #43                 // Method constructTree:([Ljava/lang/Integer;III)I
      58: pop
      59: nop
      60: return

  public java.lang.String toString();
    Code:
       0: aload_0
       1: getfield      #39                 // Field segmentTree:[I
       4: invokestatic  #56                 // Method java/util/Arrays.toString:([I)Ljava/lang/String;
       7: dup
       8: ldc           #58                 // String toString(...)
      10: invokestatic  #61                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      13: areturn

  private final int constructTree(java.lang.Integer[], int, int, int);
    Code:
       0: iload_3
       1: iload         4
       3: if_icmpne     25
       6: aload_0
       7: getfield      #39                 // Field segmentTree:[I
      10: iload_2
      11: aload_1
      12: iload_3
      13: aaload
      14: invokevirtual #67                 // Method java/lang/Integer.intValue:()I
      17: iastore
      18: aload_0
      19: getfield      #39                 // Field segmentTree:[I
      22: iload_2
      23: iaload
      24: ireturn
      25: iload_3
      26: iload         4
      28: iadd
      29: iconst_2
      30: idiv
      31: istore        5
      33: aload_0
      34: aload_1
      35: iload_2
      36: iconst_2
      37: imul
      38: iconst_1
      39: iadd
      40: iload_3
      41: iload         5
      43: invokespecial #43                 // Method constructTree:([Ljava/lang/Integer;III)I
      46: istore        6
      48: aload_0
      49: aload_1
      50: iload_2
      51: iconst_2
      52: imul
      53: iconst_2
      54: iadd
      55: iload         5
      57: iconst_1
      58: iadd
      59: iload         4
      61: invokespecial #43                 // Method constructTree:([Ljava/lang/Integer;III)I
      64: istore        7
      66: aload_0
      67: getfield      #39                 // Field segmentTree:[I
      70: iload_2
      71: iload         6
      73: iload         7
      75: iadd
      76: iastore
      77: aload_0
      78: getfield      #39                 // Field segmentTree:[I
      81: iload_2
      82: iaload
      83: ireturn

  public final int getSum(int, int);
    Code:
       0: iload_1
       1: iconst_0
       2: invokestatic  #79                 // Method java/lang/Math.max:(II)I
       5: istore_3
       6: iload_2
       7: aload_0
       8: getfield      #39                 // Field segmentTree:[I
      11: arraylength
      12: iconst_1
      13: isub
      14: invokestatic  #82                 // Method java/lang/Math.min:(II)I
      17: istore        4
      19: aload_0
      20: iload_3
      21: iload         4
      23: iconst_0
      24: aload_0
      25: getfield      #39                 // Field segmentTree:[I
      28: arraylength
      29: iconst_1
      30: isub
      31: invokespecial #86                 // Method _getSum:(IIII)I
      34: ireturn

  private final int _getSum(int, int, int, int);
    Code:
       0: iload_3
       1: iload         4
       3: if_icmpne     30
       6: iload_3
       7: iload_1
       8: if_icmple     26
      11: iload         4
      13: iload_2
      14: if_icmpgt     26
      17: aload_0
      18: getfield      #39                 // Field segmentTree:[I
      21: iload_3
      22: iaload
      23: goto          68
      26: iconst_0
      27: goto          68
      30: iload_3
      31: iload         4
      33: iadd
      34: iconst_2
      35: idiv
      36: istore        5
      38: aload_0
      39: iload_1
      40: iload_2
      41: iload_3
      42: iload         5
      44: invokespecial #86                 // Method _getSum:(IIII)I
      47: istore        6
      49: aload_0
      50: iload_1
      51: iload_2
      52: iload         5
      54: iconst_1
      55: iadd
      56: iload         4
      58: invokespecial #86                 // Method _getSum:(IIII)I
      61: istore        7
      63: iload         6
      65: iload         7
      67: iadd
      68: ireturn

  public static final void main(java.lang.String[]);
    Code:
       0: getstatic     #98                 // Field Companion:Ltree/segmentTree/SubsetSum$Companion;
       3: aload_0
       4: invokevirtual #102                // Method tree/segmentTree/SubsetSum$Companion.main:([Ljava/lang/String;)V
       7: return

  static {};
    Code:
       0: new           #100                // class tree/segmentTree/SubsetSum$Companion
       3: dup
       4: aconst_null
       5: invokespecial #108                // Method tree/segmentTree/SubsetSum$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #98                 // Field Companion:Ltree/segmentTree/SubsetSum$Companion;
      11: return
}

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

  public final void main(java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #16                 // String args
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #24                 // class tree/segmentTree/SubsetSum
       9: dup
      10: bipush        6
      12: anewarray     #26                 // class java/lang/Integer
      15: astore_3
      16: aload_3
      17: iconst_0
      18: iconst_1
      19: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      22: aastore
      23: aload_3
      24: iconst_1
      25: iconst_3
      26: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: aastore
      30: aload_3
      31: iconst_2
      32: iconst_5
      33: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      36: aastore
      37: aload_3
      38: iconst_3
      39: bipush        7
      41: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      44: aastore
      45: aload_3
      46: iconst_4
      47: bipush        9
      49: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      52: aastore
      53: aload_3
      54: iconst_5
      55: bipush        11
      57: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      60: aastore
      61: aload_3
      62: invokespecial #33                 // Method tree/segmentTree/SubsetSum."<init>":([Ljava/lang/Integer;)V
      65: astore_2
      66: aload_2
      67: invokevirtual #37                 // Method tree/segmentTree/SubsetSum.toString:()Ljava/lang/String;
      70: getstatic     #43                 // Field java/lang/System.out:Ljava/io/PrintStream;
      73: swap
      74: invokevirtual #49                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      77: return

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


package day1

import kotlin.math.floor

/**
 *
 * --- Day 1: The Tyranny of the Rocket Equation ---
 * Santa has become stranded at the edge of the Solar System while delivering presents to other planets! To accurately calculate his position in space, safely align his warp drive, and return to Earth in time to save Christmas, he needs you to bring him measurements from fifty stars.
 *
 * Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
 * The Elves quickly load you into a spacecraft and prepare to launch.
 * At the first Go / No Go poll, every Elf is Go until the Fuel Counter-Upper. They haven't determined the amount of fuel required yet.
 * Fuel required to launch a given module is based on its mass. Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.
 *
 * For example:
 *
 * For a mass of 12, divide by 3 and round down to get 4, then subtract 2 to get 2.
 * For a mass of 14, dividing by 3 and rounding down still yields 4, so the fuel required is also 2.
 * For a mass of 1969, the fuel required is 654.
 * For a mass of 100756, the fuel required is 33583.
 *
 * The Fuel Counter-Upper needs to know the total fuel requirement. To find it, individually calculate the fuel needed for the mass of each module (your puzzle input), then add together all the fuel values.
 * What is the sum of the fuel requirements for all of the modules on your spacecraft?
 *
 */
class RocketEquation {

    private val FUEL_INPUT_FILE = "/day1/input.txt"

    private val readInputFile = this::class.java.getResourceAsStream(FUEL_INPUT_FILE).bufferedReader().readLines()

    /**
     * Fuel required to launch a given module is based on its mass.
     * Specifically, to find the fuel required for a module,
     * take its mass, divide by three, round down, and subtract 2.
     */
    val calculateFuel = { mass : Int -> (floor(mass / 3.0).toInt()) - 2 }

    /**
     * The Fuel Counter-Upper needs to know the total fuel requirement. To find it, individually calculate
     * the fuel needed for the mass of each module (your puzzle input), then add together all the fuel values.
     * What is the sum of the fuel requirements for all of the modules on your spacecraft?
     */
    fun getTotalFuelRequeriment() : Int {

        return readInputFile
                .map { it.toInt() }
                .map { calculateFuel(it) }
                .sum()
    }
}

Compiled from "RocketEquation.kt"
public final class day1.RocketEquation {
  private final java.lang.String FUEL_INPUT_FILE;

  private final java.util.List<java.lang.String> readInputFile;

  private final kotlin.jvm.functions.Function1<java.lang.Integer, java.lang.Integer> calculateFuel;

  public day1.RocketEquation();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: ldc           #10                 // String /day1/input.txt
       7: putfield      #14                 // Field FUEL_INPUT_FILE:Ljava/lang/String;
      10: aload_0
      11: aload_0
      12: invokevirtual #18                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      15: aload_0
      16: getfield      #14                 // Field FUEL_INPUT_FILE:Ljava/lang/String;
      19: invokevirtual #24                 // Method java/lang/Class.getResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
      22: dup
      23: ldc           #26                 // String getResourceAsStream(...)
      25: invokestatic  #32                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      28: astore_1
      29: getstatic     #38                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      32: astore_2
      33: new           #40                 // class java/io/InputStreamReader
      36: dup
      37: aload_1
      38: aload_2
      39: invokespecial #43                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      42: checkcast     #45                 // class java/io/Reader
      45: astore_3
      46: sipush        8192
      49: istore        4
      51: aload_3
      52: instanceof    #47                 // class java/io/BufferedReader
      55: ifeq          65
      58: aload_3
      59: checkcast     #47                 // class java/io/BufferedReader
      62: goto          75
      65: new           #47                 // class java/io/BufferedReader
      68: dup
      69: aload_3
      70: iload         4
      72: invokespecial #50                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      75: checkcast     #45                 // class java/io/Reader
      78: invokestatic  #56                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      81: putfield      #60                 // Field readInputFile:Ljava/util/List;
      84: aload_0
      85: invokedynamic #80,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      90: putfield      #84                 // Field calculateFuel:Lkotlin/jvm/functions/Function1;
      93: return

  public final kotlin.jvm.functions.Function1<java.lang.Integer, java.lang.Integer> getCalculateFuel();
    Code:
       0: aload_0
       1: getfield      #84                 // Field calculateFuel:Lkotlin/jvm/functions/Function1;
       4: areturn

  public final int getTotalFuelRequeriment();
    Code:
       0: aload_0
       1: getfield      #60                 // Field readInputFile:Ljava/util/List;
       4: checkcast     #97                 // class java/lang/Iterable
       7: astore_1
       8: nop
       9: iconst_0
      10: istore_2
      11: aload_1
      12: astore_3
      13: new           #99                 // class java/util/ArrayList
      16: dup
      17: aload_1
      18: bipush        10
      20: invokestatic  #105                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      23: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
      26: checkcast     #110                // class java/util/Collection
      29: astore        4
      31: iconst_0
      32: istore        5
      34: aload_3
      35: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        6
      42: aload         6
      44: invokeinterface #120,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          96
      52: aload         6
      54: invokeinterface #124,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        7
      61: aload         4
      63: aload         7
      65: checkcast     #126                // class java/lang/String
      68: astore        8
      70: astore        10
      72: iconst_0
      73: istore        9
      75: aload         8
      77: invokestatic  #132                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      80: nop
      81: invokestatic  #136                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      84: aload         10
      86: swap
      87: invokeinterface #140,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      92: pop
      93: goto          42
      96: aload         4
      98: checkcast     #142                // class java/util/List
     101: nop
     102: checkcast     #97                 // class java/lang/Iterable
     105: astore_1
     106: nop
     107: iconst_0
     108: istore_2
     109: aload_1
     110: astore_3
     111: new           #99                 // class java/util/ArrayList
     114: dup
     115: aload_1
     116: bipush        10
     118: invokestatic  #105                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     121: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     124: checkcast     #110                // class java/util/Collection
     127: astore        4
     129: iconst_0
     130: istore        5
     132: aload_3
     133: invokeinterface #114,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     138: astore        6
     140: aload         6
     142: invokeinterface #120,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     147: ifeq          211
     150: aload         6
     152: invokeinterface #124,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     157: astore        7
     159: aload         4
     161: aload         7
     163: checkcast     #144                // class java/lang/Number
     166: invokevirtual #147                // Method java/lang/Number.intValue:()I
     169: istore        8
     171: astore        10
     173: iconst_0
     174: istore        9
     176: aload_0
     177: getfield      #84                 // Field calculateFuel:Lkotlin/jvm/functions/Function1;
     180: iload         8
     182: invokestatic  #136                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     185: invokeinterface #151,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     190: checkcast     #144                // class java/lang/Number
     193: invokevirtual #147                // Method java/lang/Number.intValue:()I
     196: invokestatic  #136                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     199: aload         10
     201: swap
     202: invokeinterface #140,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     207: pop
     208: goto          140
     211: aload         4
     213: checkcast     #142                // class java/util/List
     216: nop
     217: checkcast     #97                 // class java/lang/Iterable
     220: invokestatic  #155                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     223: ireturn

  private static final int calculateFuel$lambda$0(int);
    Code:
       0: iload_0
       1: i2d
       2: ldc2_w        #169                // double 3.0d
       5: ddiv
       6: invokestatic  #176                // Method java/lang/Math.floor:(D)D
       9: d2i
      10: iconst_2
      11: isub
      12: ireturn
}