package algorithms.old

fun main() {
    val text = "Hi, I'm Nicole. I've been diving deep into Software Development for about 2 years, particularly into " +
            "Android Development with Kotlin and Jetpack Compose. I'm proficient in mobile UI/UX and have worked on " +
            "projects related to productivity, fintech, and health. I'm genuinely passionate about tech and believe " +
            "that IT has a huge role to play in our future. I’m ready to bring my expertise to exciting new challenges" +
            " in Android development!"
    println(text.wordsCount { it !in listOf("a", "to", "the") })
    println(text.wordsCountWithDensity())
}

// Nice exercise. The exercise is under number 5. Nice.
private fun String.wordsCount(additionalWordFilter: ((String) -> Boolean)? = null): Map<String, Int> {
    val wordsCountMap = mutableMapOf<String, Int>()

    // Nice, exercise, The, exercise
    val words = this.filter {
        it != '.' && it != ',' && it != '!'
    }.lowercase().split(" ")

    val latest = if (additionalWordFilter != null) {
        words.filter {
            additionalWordFilter(it)
        }
    } else {
        words
    }

    for (word in latest) {
        val wordCount = wordsCountMap[word] ?: 0
        wordsCountMap[word] = wordCount + 1
    }

    return wordsCountMap.toList().sortedByDescending { it.second }.toMap()
}

data class SeoInfo(
    val wordCount: Int,
    val densityPercent: Double
)

// 10 words, 3 count -> 30%
private fun String.wordsCountWithDensity(): Map<String, SeoInfo> {
    val wordsCountMap = this.wordsCount()
    val totalWords = wordsCountMap.size

    val resMap = wordsCountMap.map {
        Pair(
            it.key, SeoInfo(
                wordCount = it.value,
                densityPercent = (it.value / totalWords.toDouble()) * 100
            )
        )
    }.toMap()

    return resMap
}

Compiled from "WordsCount.kt"
public final class algorithms.old.WordsCountKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Hi, I\'m Nicole. I\'ve been diving deep into Software Development for about 2 years, particularly into Android Development with Kotlin and Jetpack Compose. I\'m proficient in mobile UI/UX and have worked on projects related to productivity, fintech, and health. I\'m genuinely passionate about tech and believe that IT has a huge role to play in our future. I’m ready to bring my expertise to exciting new challenges in Android development!
       2: astore_0
       3: aload_0
       4: invokedynamic #28,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
       9: invokestatic  #32                 // Method wordsCount:(Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/util/Map;
      12: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      15: swap
      16: invokevirtual #44                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      19: aload_0
      20: invokestatic  #48                 // Method wordsCountWithDensity:(Ljava/lang/String;)Ljava/util/Map;
      23: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: swap
      27: invokevirtual #44                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: return

  private static final java.util.Map<java.lang.String, java.lang.Integer> wordsCount(java.lang.String, kotlin.jvm.functions.Function1<? super java.lang.String, java.lang.Boolean>);
    Code:
       0: new           #53                 // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #56                 // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #58                 // class java/util/Map
      10: astore_2
      11: aload_0
      12: astore        4
      14: iconst_0
      15: istore        5
      17: aload         4
      19: checkcast     #60                 // class java/lang/CharSequence
      22: astore        6
      24: new           #62                 // class java/lang/StringBuilder
      27: dup
      28: invokespecial #63                 // Method java/lang/StringBuilder."<init>":()V
      31: checkcast     #65                 // class java/lang/Appendable
      34: astore        7
      36: iconst_0
      37: istore        8
      39: iconst_0
      40: istore        9
      42: aload         6
      44: invokeinterface #69,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      49: istore        10
      51: iload         9
      53: iload         10
      55: if_icmpge     121
      58: aload         6
      60: iload         9
      62: invokeinterface #73,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      67: istore        11
      69: iload         11
      71: istore        12
      73: iconst_0
      74: istore        13
      76: iload         12
      78: bipush        46
      80: if_icmpeq     101
      83: iload         12
      85: bipush        44
      87: if_icmpeq     101
      90: iload         12
      92: bipush        33
      94: if_icmpeq     101
      97: iconst_1
      98: goto          102
     101: iconst_0
     102: ifeq          115
     105: aload         7
     107: iload         11
     109: invokeinterface #77,  2           // InterfaceMethod java/lang/Appendable.append:(C)Ljava/lang/Appendable;
     114: pop
     115: iinc          9, 1
     118: goto          51
     121: aload         7
     123: checkcast     #62                 // class java/lang/StringBuilder
     126: invokevirtual #81                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     129: getstatic     #87                 // Field java/util/Locale.ROOT:Ljava/util/Locale;
     132: invokevirtual #93                 // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
     135: dup
     136: ldc           #95                 // String toLowerCase(...)
     138: invokestatic  #101                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     141: checkcast     #60                 // class java/lang/CharSequence
     144: iconst_1
     145: anewarray     #89                 // class java/lang/String
     148: astore        4
     150: aload         4
     152: iconst_0
     153: ldc           #103                // String
     155: aastore
     156: aload         4
     158: iconst_0
     159: iconst_0
     160: bipush        6
     162: aconst_null
     163: invokestatic  #109                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     166: astore_3
     167: aload_1
     168: ifnull        276
     171: aload_3
     172: checkcast     #111                // class java/lang/Iterable
     175: astore        5
     177: iconst_0
     178: istore        6
     180: aload         5
     182: astore        7
     184: new           #113                // class java/util/ArrayList
     187: dup
     188: invokespecial #114                // Method java/util/ArrayList."<init>":()V
     191: checkcast     #116                // class java/util/Collection
     194: astore        8
     196: iconst_0
     197: istore        9
     199: aload         7
     201: invokeinterface #120,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     206: astore        10
     208: aload         10
     210: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     215: ifeq          267
     218: aload         10
     220: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     225: astore        11
     227: aload         11
     229: checkcast     #89                 // class java/lang/String
     232: astore        12
     234: iconst_0
     235: istore        13
     237: aload_1
     238: aload         12
     240: invokeinterface #134,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     245: checkcast     #136                // class java/lang/Boolean
     248: invokevirtual #139                // Method java/lang/Boolean.booleanValue:()Z
     251: ifeq          208
     254: aload         8
     256: aload         11
     258: invokeinterface #143,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     263: pop
     264: goto          208
     267: aload         8
     269: checkcast     #145                // class java/util/List
     272: nop
     273: goto          277
     276: aload_3
     277: astore        4
     279: aload         4
     281: invokeinterface #146,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     286: astore        5
     288: aload         5
     290: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     295: ifeq          354
     298: aload         5
     300: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     305: checkcast     #89                 // class java/lang/String
     308: astore        6
     310: aload_2
     311: aload         6
     313: invokeinterface #149,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     318: checkcast     #151                // class java/lang/Integer
     321: dup
     322: ifnull        331
     325: invokevirtual #154                // Method java/lang/Integer.intValue:()I
     328: goto          333
     331: pop
     332: iconst_0
     333: istore        7
     335: aload_2
     336: aload         6
     338: iload         7
     340: iconst_1
     341: iadd
     342: invokestatic  #158                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     345: invokeinterface #162,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     350: pop
     351: goto          288
     354: aload_2
     355: invokestatic  #168                // Method kotlin/collections/MapsKt.toList:(Ljava/util/Map;)Ljava/util/List;
     358: checkcast     #111                // class java/lang/Iterable
     361: astore        5
     363: iconst_0
     364: istore        6
     366: aload         5
     368: new           #170                // class algorithms/old/WordsCountKt$wordsCount$$inlined$sortedByDescending$1
     371: dup
     372: invokespecial #171                // Method algorithms/old/WordsCountKt$wordsCount$$inlined$sortedByDescending$1."<init>":()V
     375: checkcast     #173                // class java/util/Comparator
     378: invokestatic  #179                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     381: checkcast     #111                // class java/lang/Iterable
     384: invokestatic  #183                // Method kotlin/collections/MapsKt.toMap:(Ljava/lang/Iterable;)Ljava/util/Map;
     387: areturn

  static java.util.Map wordsCount$default(java.lang.String, kotlin.jvm.functions.Function1, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          8
       6: aconst_null
       7: astore_1
       8: aload_0
       9: aload_1
      10: invokestatic  #32                 // Method wordsCount:(Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/util/Map;
      13: areturn

  private static final java.util.Map<java.lang.String, algorithms.old.SeoInfo> wordsCountWithDensity(java.lang.String);
    Code:
       0: aload_0
       1: aconst_null
       2: iconst_1
       3: aconst_null
       4: invokestatic  #219                // Method wordsCount$default:(Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/util/Map;
       7: astore_1
       8: aload_1
       9: invokeinterface #222,  1          // InterfaceMethod java/util/Map.size:()I
      14: istore_2
      15: aload_1
      16: astore        4
      18: iconst_0
      19: istore        5
      21: aload         4
      23: astore        6
      25: new           #113                // class java/util/ArrayList
      28: dup
      29: aload         4
      31: invokeinterface #222,  1          // InterfaceMethod java/util/Map.size:()I
      36: invokespecial #225                // Method java/util/ArrayList."<init>":(I)V
      39: checkcast     #116                // class java/util/Collection
      42: astore        7
      44: iconst_0
      45: istore        8
      47: aload         6
      49: invokeinterface #229,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      54: invokeinterface #232,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      59: astore        9
      61: aload         9
      63: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      68: ifeq          161
      71: aload         9
      73: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      78: checkcast     #234                // class java/util/Map$Entry
      81: astore        10
      83: aload         7
      85: aload         10
      87: astore        11
      89: astore        13
      91: iconst_0
      92: istore        12
      94: new           #236                // class kotlin/Pair
      97: dup
      98: aload         11
     100: invokeinterface #239,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     105: new           #241                // class algorithms/old/SeoInfo
     108: dup
     109: aload         11
     111: invokeinterface #244,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     116: checkcast     #246                // class java/lang/Number
     119: invokevirtual #247                // Method java/lang/Number.intValue:()I
     122: aload         11
     124: invokeinterface #244,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     129: checkcast     #246                // class java/lang/Number
     132: invokevirtual #251                // Method java/lang/Number.doubleValue:()D
     135: iload_2
     136: i2d
     137: ddiv
     138: bipush        100
     140: i2d
     141: dmul
     142: invokespecial #254                // Method algorithms/old/SeoInfo."<init>":(ID)V
     145: invokespecial #257                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     148: nop
     149: aload         13
     151: swap
     152: invokeinterface #143,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     157: pop
     158: goto          61
     161: aload         7
     163: checkcast     #145                // class java/util/List
     166: nop
     167: checkcast     #111                // class java/lang/Iterable
     170: invokestatic  #183                // Method kotlin/collections/MapsKt.toMap:(Ljava/lang/Iterable;)Ljava/util/Map;
     173: astore_3
     174: aload_3
     175: areturn

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

  private static final boolean main$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #272                // String it
       4: invokestatic  #275                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: iconst_3
       8: anewarray     #89                 // class java/lang/String
      11: astore_1
      12: aload_1
      13: iconst_0
      14: ldc_w         #277                // String a
      17: aastore
      18: aload_1
      19: iconst_1
      20: ldc_w         #279                // String to
      23: aastore
      24: aload_1
      25: iconst_2
      26: ldc_w         #281                // String the
      29: aastore
      30: aload_1
      31: invokestatic  #285                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      34: aload_0
      35: invokeinterface #288,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
      40: ifne          47
      43: iconst_1
      44: goto          48
      47: iconst_0
      48: ireturn
}

Compiled from "Comparisons.kt"
public final class algorithms.old.WordsCountKt$wordsCount$$inlined$sortedByDescending$1<T> implements java.util.Comparator {
  public algorithms.old.WordsCountKt$wordsCount$$inlined$sortedByDescending$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_2
       1: checkcast     #23                 // class kotlin/Pair
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      12: checkcast     #29                 // class java/lang/Integer
      15: checkcast     #31                 // class java/lang/Comparable
      18: aload_1
      19: checkcast     #23                 // class kotlin/Pair
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      32: checkcast     #29                 // class java/lang/Integer
      35: aload         5
      37: swap
      38: checkcast     #31                 // class java/lang/Comparable
      41: invokestatic  #37                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}


package algorithms.new

import java.io.File

fun main() {
    val input = File("day1.txt").readText()
    val input2 = File("new.txt").readText()

    println(finalSum("www3two"))
    println(finalSum(input))
    println(finalSum(input2))
}

val numbers = mapOf(
    Pair("one", 1),
    Pair("two", 2),
    Pair("three", 3),
    Pair("four", 4),
    Pair("five", 5),
    Pair("six", 6),
    Pair("seven", 7),
    Pair("eight", 8),
    Pair("nine", 9)
)

val finalNums = numbers + numbers.map {
    val newKey = it.key.reversed()
    Pair(newKey, it.value)
}

private fun finalSum(input: String): Int {
    val words = getWords(input)

    val res = words.map {
        wordToTwoDigitNumber(it)
    }.sum()

    return res
}

private fun wordToTwoDigitNumber(word: String): Int {
    val first = extractFirstDigit(word) ?: throw Exception("Error!")
    val second = extractFirstDigit(word.reversed()) ?: first

    return "$first$second".toInt()
}

private fun getWords(input: String): List<String> {
    return input.split("\n")
}

private fun extractFirstDigit(word: String): Int? {
    var accumulated = ""
    var digit: Int? = null

    for (char in word) {
        if (char.isDigit()) {
            digit = char.digitToInt()
            break
        }

        accumulated += char

        val number = containsTextDigit(accumulated)
        if (number != null) {
            digit = number
            break
        }
    }

    return digit
}

// "wwwone" -> "one"
// "www" -> null
private fun containsTextDigit(accumulated: String): Int? {
    for (key in finalNums.keys) {
        if (key in accumulated) {
            return finalNums[key]
        }
    }

    return null
}

Compiled from "SumOfCalibrationValues.kt"
public final class algorithms.new.SumOfCalibrationValuesKt {
  private static final java.util.Map<java.lang.String, java.lang.Integer> numbers;

  private static final java.util.Map<java.lang.String, java.lang.Integer> finalNums;

  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String day1.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: astore_0
      16: new           #8                  // class java/io/File
      19: dup
      20: ldc           #22                 // String new.txt
      22: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      25: aconst_null
      26: iconst_1
      27: aconst_null
      28: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      31: astore_1
      32: ldc           #24                 // String www3two
      34: invokestatic  #28                 // Method finalSum:(Ljava/lang/String;)I
      37: istore_2
      38: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      41: iload_2
      42: invokevirtual #40                 // Method java/io/PrintStream.println:(I)V
      45: aload_0
      46: invokestatic  #28                 // Method finalSum:(Ljava/lang/String;)I
      49: istore_2
      50: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      53: iload_2
      54: invokevirtual #40                 // Method java/io/PrintStream.println:(I)V
      57: aload_1
      58: invokestatic  #28                 // Method finalSum:(Ljava/lang/String;)I
      61: istore_2
      62: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      65: iload_2
      66: invokevirtual #40                 // Method java/io/PrintStream.println:(I)V
      69: return

  public static final java.util.Map<java.lang.String, java.lang.Integer> getNumbers();
    Code:
       0: getstatic     #51                 // Field numbers:Ljava/util/Map;
       3: areturn

  public static final java.util.Map<java.lang.String, java.lang.Integer> getFinalNums();
    Code:
       0: getstatic     #55                 // Field finalNums:Ljava/util/Map;
       3: areturn

  private static final int finalSum(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #59                 // Method getWords:(Ljava/lang/String;)Ljava/util/List;
       4: astore_1
       5: aload_1
       6: checkcast     #61                 // class java/lang/Iterable
       9: astore_3
      10: iconst_0
      11: istore        4
      13: aload_3
      14: astore        5
      16: new           #63                 // class java/util/ArrayList
      19: dup
      20: aload_3
      21: bipush        10
      23: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #71                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #73                 // class java/util/Collection
      32: astore        6
      34: iconst_0
      35: istore        7
      37: aload         5
      39: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        8
      46: aload         8
      48: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          99
      56: aload         8
      58: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        9
      65: aload         6
      67: aload         9
      69: checkcast     #89                 // class java/lang/String
      72: astore        10
      74: astore        12
      76: iconst_0
      77: istore        11
      79: aload         10
      81: invokestatic  #92                 // Method wordToTwoDigitNumber:(Ljava/lang/String;)I
      84: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      87: aload         12
      89: swap
      90: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      95: pop
      96: goto          46
      99: aload         6
     101: checkcast     #104                // class java/util/List
     104: nop
     105: checkcast     #61                 // class java/lang/Iterable
     108: invokestatic  #108                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     111: istore_2
     112: iload_2
     113: ireturn

  private static final int wordToTwoDigitNumber(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #127                // Method extractFirstDigit:(Ljava/lang/String;)Ljava/lang/Integer;
       4: dup
       5: ifnull        14
       8: invokevirtual #131                // Method java/lang/Integer.intValue:()I
      11: goto          25
      14: pop
      15: new           #133                // class java/lang/Exception
      18: dup
      19: ldc           #135                // String Error!
      21: invokespecial #136                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
      24: athrow
      25: istore_1
      26: aload_0
      27: checkcast     #138                // class java/lang/CharSequence
      30: invokestatic  #144                // Method kotlin/text/StringsKt.reversed:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      33: invokevirtual #148                // Method java/lang/Object.toString:()Ljava/lang/String;
      36: invokestatic  #127                // Method extractFirstDigit:(Ljava/lang/String;)Ljava/lang/Integer;
      39: dup
      40: ifnull        49
      43: invokevirtual #131                // Method java/lang/Integer.intValue:()I
      46: goto          51
      49: pop
      50: iload_1
      51: istore_2
      52: new           #150                // class java/lang/StringBuilder
      55: dup
      56: invokespecial #152                // Method java/lang/StringBuilder."<init>":()V
      59: iload_1
      60: invokevirtual #156                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      63: iload_2
      64: invokevirtual #156                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      67: invokevirtual #157                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      70: invokestatic  #160                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      73: ireturn

  private static final java.util.List<java.lang.String> getWords(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #138                // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #89                 // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc           #166                // String \n
      13: aastore
      14: aload_1
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #170                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: areturn

  private static final java.lang.Integer extractFirstDigit(java.lang.String);
    Code:
       0: ldc           #172                // String
       2: astore_1
       3: aconst_null
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_0
       8: invokevirtual #175                // Method java/lang/String.length:()I
      11: istore        4
      13: iload_3
      14: iload         4
      16: if_icmpge     89
      19: aload_0
      20: iload_3
      21: invokevirtual #179                // Method java/lang/String.charAt:(I)C
      24: istore        5
      26: iload         5
      28: invokestatic  #185                // Method java/lang/Character.isDigit:(C)Z
      31: ifeq          46
      34: iload         5
      36: invokestatic  #191                // Method kotlin/text/CharsKt.digitToInt:(C)I
      39: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      42: astore_2
      43: goto          89
      46: new           #150                // class java/lang/StringBuilder
      49: dup
      50: invokespecial #152                // Method java/lang/StringBuilder."<init>":()V
      53: aload_1
      54: invokevirtual #194                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      57: iload         5
      59: invokevirtual #197                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      62: invokevirtual #157                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      65: astore_1
      66: aload_1
      67: invokestatic  #200                // Method containsTextDigit:(Ljava/lang/String;)Ljava/lang/Integer;
      70: astore        6
      72: aload         6
      74: ifnull        83
      77: aload         6
      79: astore_2
      80: goto          89
      83: iinc          3, 1
      86: goto          13
      89: aload_2
      90: areturn

  private static final java.lang.Integer containsTextDigit(java.lang.String);
    Code:
       0: getstatic     #55                 // Field finalNums:Ljava/util/Map;
       3: invokeinterface #212,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
       8: invokeinterface #215,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      13: astore_1
      14: aload_1
      15: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      20: ifeq          63
      23: aload_1
      24: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      29: checkcast     #89                 // class java/lang/String
      32: astore_2
      33: aload_0
      34: checkcast     #138                // class java/lang/CharSequence
      37: aload_2
      38: checkcast     #138                // class java/lang/CharSequence
      41: iconst_0
      42: iconst_2
      43: aconst_null
      44: invokestatic  #219                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
      47: ifeq          14
      50: getstatic     #55                 // Field finalNums:Ljava/util/Map;
      53: aload_2
      54: invokeinterface #223,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      59: checkcast     #94                 // class java/lang/Integer
      62: areturn
      63: aconst_null
      64: areturn

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

  static {};
    Code:
       0: bipush        9
       2: anewarray     #232                // class kotlin/Pair
       5: astore_0
       6: aload_0
       7: iconst_0
       8: new           #232                // class kotlin/Pair
      11: dup
      12: ldc           #234                // String one
      14: iconst_1
      15: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      21: aastore
      22: aload_0
      23: iconst_1
      24: new           #232                // class kotlin/Pair
      27: dup
      28: ldc           #239                // String two
      30: iconst_2
      31: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      34: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      37: aastore
      38: aload_0
      39: iconst_2
      40: new           #232                // class kotlin/Pair
      43: dup
      44: ldc           #241                // String three
      46: iconst_3
      47: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      50: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      53: aastore
      54: aload_0
      55: iconst_3
      56: new           #232                // class kotlin/Pair
      59: dup
      60: ldc           #243                // String four
      62: iconst_4
      63: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      69: aastore
      70: aload_0
      71: iconst_4
      72: new           #232                // class kotlin/Pair
      75: dup
      76: ldc           #245                // String five
      78: iconst_5
      79: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      82: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      85: aastore
      86: aload_0
      87: iconst_5
      88: new           #232                // class kotlin/Pair
      91: dup
      92: ldc           #247                // String six
      94: bipush        6
      96: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     102: aastore
     103: aload_0
     104: bipush        6
     106: new           #232                // class kotlin/Pair
     109: dup
     110: ldc           #249                // String seven
     112: bipush        7
     114: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     117: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     120: aastore
     121: aload_0
     122: bipush        7
     124: new           #232                // class kotlin/Pair
     127: dup
     128: ldc           #251                // String eight
     130: bipush        8
     132: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     135: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     138: aastore
     139: aload_0
     140: bipush        8
     142: new           #232                // class kotlin/Pair
     145: dup
     146: ldc           #253                // String nine
     148: bipush        9
     150: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     153: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     156: aastore
     157: aload_0
     158: invokestatic  #259                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     161: putstatic     #51                 // Field numbers:Ljava/util/Map;
     164: getstatic     #51                 // Field numbers:Ljava/util/Map;
     167: getstatic     #51                 // Field numbers:Ljava/util/Map;
     170: astore_0
     171: astore        10
     173: iconst_0
     174: istore_1
     175: aload_0
     176: astore_2
     177: new           #63                 // class java/util/ArrayList
     180: dup
     181: aload_0
     182: invokeinterface #262,  1          // InterfaceMethod java/util/Map.size:()I
     187: invokespecial #71                 // Method java/util/ArrayList."<init>":(I)V
     190: checkcast     #73                 // class java/util/Collection
     193: astore_3
     194: iconst_0
     195: istore        4
     197: aload_2
     198: invokeinterface #265,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     203: invokeinterface #215,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     208: astore        5
     210: aload         5
     212: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     217: ifeq          291
     220: aload         5
     222: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     227: checkcast     #267                // class java/util/Map$Entry
     230: astore        6
     232: aload_3
     233: aload         6
     235: astore        7
     237: astore        11
     239: iconst_0
     240: istore        8
     242: aload         7
     244: invokeinterface #270,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     249: checkcast     #89                 // class java/lang/String
     252: checkcast     #138                // class java/lang/CharSequence
     255: invokestatic  #144                // Method kotlin/text/StringsKt.reversed:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     258: invokevirtual #148                // Method java/lang/Object.toString:()Ljava/lang/String;
     261: astore        9
     263: new           #232                // class kotlin/Pair
     266: dup
     267: aload         9
     269: aload         7
     271: invokeinterface #273,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     276: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     279: aload         11
     281: swap
     282: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     287: pop
     288: goto          210
     291: aload_3
     292: checkcast     #104                // class java/util/List
     295: nop
     296: aload         10
     298: swap
     299: checkcast     #61                 // class java/lang/Iterable
     302: invokestatic  #277                // Method kotlin/collections/MapsKt.plus:(Ljava/util/Map;Ljava/lang/Iterable;)Ljava/util/Map;
     305: putstatic     #55                 // Field finalNums:Ljava/util/Map;
     308: return
}


package algorithms.new

import java.io.File

fun main() {
    val input = File("cubes.txt").readText()
    val sets =
        parseSets("Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green")

    println(sumOfGamePowers(input))
}

val bag = Set(
    redCubesCount = 12,
    greenCubesCount = 13,
    blueCubesCount = 14
)

data class Game(
    val id: Int,
    val sets: List<Set>
)

data class Set(
    val redCubesCount: Int,
    val greenCubesCount: Int,
    val blueCubesCount: Int
)

private fun validGamesSum(input: String): Int {
    return input.lines()
        .map(::parseAsGame)
        .filter(::validateGame)
        .sumOf { it.id }
}

private fun sumOfGamePowers(input: String): Int {
    val gamesList = input.lines()
        .map(::parseAsGame)

    var sum = 0

    for (game in gamesList) {
        val set = getFewestValidGameCubes(game.sets)
        sum += powerOfFewestValidGameCubes(set)
    }

    return sum
}

private fun powerOfFewestValidGameCubes(set: Set): Int {
    return set.redCubesCount * set.blueCubesCount * set.greenCubesCount
}

// Set(blue=2, red=3, red=1), Set(green=2, blue=3; green=4)
private fun getFewestValidGameCubes(gameSets: List<Set>): Set {
    val redCount = gameSets.maxOf { it.redCubesCount }
    val blueCount = gameSets.maxOf { it.blueCubesCount }
    val greenCount = gameSets.maxOf { it.greenCubesCount }

    return Set(redCubesCount = redCount, greenCubesCount = greenCount, blueCubesCount = blueCount)
}

// "Game 1: 4 blue, 16 green, 2 red; 5 red, 11 blue, 16 green; 9 green, 11 blue; 10 blue, 6 green, 4 red"
private fun parseAsGame(line: String): Game {
    val gameId = parseGameId(line)
    val gameSets = parseSets(line)

    return Game(id = gameId, sets = gameSets)
}

// Game 15
private fun parseGameId(line: String): Int {
    val gameTitleList = line
        .split(":")
        .first()
        .split(" ")
    return gameTitleList[1].toInt()
}

// "Game 1: 4 blue, 16 green, 2 red; 5 red, 11 blue, 16 green; 9 green, 11 blue; 10 blue, 6 green, 4 red"
private fun parseSets(line: String): List<Set> {
    val lineWithoutTitle = line.split(":").last()
    val sets = lineWithoutTitle.split(";")

    return sets.map {
        parseStringToSet(it)
    }
}

// 4 blue, 16 green, 2 red
private fun parseStringToSet(input: String): Set {
    var red = 0
    var green = 0
    var blue = 0

    val inputList = input.split(",")

    // 4 blue
    for (i in inputList.indices) {
        val current = inputList[i].filter {
            it != ','
        }.trim().split(" ")

        when (current[1]) {
            "red" -> red += current[0].toInt()
            "green" -> green += current[0].toInt()
            "blue" -> blue += current[0].toInt()
        }
    }

    return Set(
        redCubesCount = red,
        greenCubesCount = green,
        blueCubesCount = blue
    )
}

private fun validateGame(game: Game): Boolean {
    return game.sets.all {
        validateSet(it)
    }
}

// Set(redCubesCount=2, greenCubesCount=16, blueCubesCount=4)
private fun validateSet(set: Set): Boolean {
    return set.redCubesCount <= bag.redCubesCount &&
            set.greenCubesCount <= bag.greenCubesCount &&
            set.blueCubesCount <= bag.blueCubesCount
}

Compiled from "CubeConundrum.kt"
public final class algorithms.new.CubeConundrumKt {
  private static final algorithms.new.Set bag;

  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String cubes.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: astore_0
      16: ldc           #22                 // String Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
      18: invokestatic  #26                 // Method parseSets:(Ljava/lang/String;)Ljava/util/List;
      21: astore_1
      22: aload_0
      23: invokestatic  #30                 // Method sumOfGamePowers:(Ljava/lang/String;)I
      26: istore_2
      27: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
      30: iload_2
      31: invokevirtual #42                 // Method java/io/PrintStream.println:(I)V
      34: return

  public static final algorithms.new.Set getBag();
    Code:
       0: getstatic     #53                 // Field bag:Lalgorithms/new/Set;
       3: areturn

  private static final int validGamesSum(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #56                 // class java/lang/CharSequence
       4: invokestatic  #62                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
       7: checkcast     #64                 // class java/lang/Iterable
      10: astore_1
      11: nop
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #66                 // class java/util/ArrayList
      19: dup
      20: aload_1
      21: bipush        10
      23: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #74                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #76                 // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload_3
      38: invokeinterface #80,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        6
      45: aload         6
      47: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          95
      55: aload         6
      57: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        7
      64: aload         4
      66: aload         7
      68: checkcast     #92                 // class java/lang/String
      71: astore        8
      73: astore        10
      75: iconst_0
      76: istore        9
      78: aload         8
      80: invokestatic  #96                 // Method parseAsGame:(Ljava/lang/String;)Lalgorithms/new/Game;
      83: aload         10
      85: swap
      86: invokeinterface #100,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: goto          45
      95: aload         4
      97: checkcast     #102                // class java/util/List
     100: nop
     101: checkcast     #64                 // class java/lang/Iterable
     104: astore_1
     105: nop
     106: iconst_0
     107: istore_2
     108: aload_1
     109: astore_3
     110: new           #66                 // class java/util/ArrayList
     113: dup
     114: invokespecial #104                // Method java/util/ArrayList."<init>":()V
     117: checkcast     #76                 // class java/util/Collection
     120: astore        4
     122: iconst_0
     123: istore        5
     125: aload_3
     126: invokeinterface #80,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     131: astore        6
     133: aload         6
     135: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     140: ifeq          183
     143: aload         6
     145: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     150: astore        7
     152: aload         7
     154: checkcast     #106                // class algorithms/new/Game
     157: astore        8
     159: iconst_0
     160: istore        9
     162: aload         8
     164: invokestatic  #110                // Method validateGame:(Lalgorithms/new/Game;)Z
     167: ifeq          133
     170: aload         4
     172: aload         7
     174: invokeinterface #100,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     179: pop
     180: goto          133
     183: aload         4
     185: checkcast     #102                // class java/util/List
     188: nop
     189: checkcast     #64                 // class java/lang/Iterable
     192: astore_1
     193: iconst_0
     194: istore_2
     195: aload_1
     196: invokeinterface #80,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     201: astore_3
     202: aload_3
     203: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     208: ifeq          248
     211: aload_3
     212: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     217: astore        4
     219: iload_2
     220: aload         4
     222: checkcast     #106                // class algorithms/new/Game
     225: astore        5
     227: istore        10
     229: iconst_0
     230: istore        6
     232: aload         5
     234: invokevirtual #114                // Method algorithms/new/Game.getId:()I
     237: istore        11
     239: iload         10
     241: iload         11
     243: iadd
     244: istore_2
     245: goto          202
     248: iload_2
     249: ireturn

  private static final int sumOfGamePowers(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #56                 // class java/lang/CharSequence
       4: invokestatic  #62                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
       7: checkcast     #64                 // class java/lang/Iterable
      10: astore_2
      11: nop
      12: iconst_0
      13: istore_3
      14: aload_2
      15: astore        4
      17: new           #66                 // class java/util/ArrayList
      20: dup
      21: aload_2
      22: bipush        10
      24: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      27: invokespecial #74                 // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #76                 // class java/util/Collection
      33: astore        5
      35: iconst_0
      36: istore        6
      38: aload         4
      40: invokeinterface #80,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        7
      47: aload         7
      49: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          97
      57: aload         7
      59: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        8
      66: aload         5
      68: aload         8
      70: checkcast     #92                 // class java/lang/String
      73: astore        9
      75: astore        11
      77: iconst_0
      78: istore        10
      80: aload         9
      82: invokestatic  #96                 // Method parseAsGame:(Ljava/lang/String;)Lalgorithms/new/Game;
      85: aload         11
      87: swap
      88: invokeinterface #100,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      93: pop
      94: goto          47
      97: aload         5
      99: checkcast     #102                // class java/util/List
     102: nop
     103: astore_1
     104: iconst_0
     105: istore_2
     106: aload_1
     107: invokeinterface #136,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     112: astore_3
     113: aload_3
     114: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     119: ifeq          154
     122: aload_3
     123: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     128: checkcast     #106                // class algorithms/new/Game
     131: astore        4
     133: aload         4
     135: invokevirtual #140                // Method algorithms/new/Game.getSets:()Ljava/util/List;
     138: invokestatic  #144                // Method getFewestValidGameCubes:(Ljava/util/List;)Lalgorithms/new/Set;
     141: astore        5
     143: iload_2
     144: aload         5
     146: invokestatic  #148                // Method powerOfFewestValidGameCubes:(Lalgorithms/new/Set;)I
     149: iadd
     150: istore_2
     151: goto          113
     154: iload_2
     155: ireturn

  private static final int powerOfFewestValidGameCubes(algorithms.new.Set);
    Code:
       0: aload_0
       1: invokevirtual #158                // Method algorithms/new/Set.getRedCubesCount:()I
       4: aload_0
       5: invokevirtual #161                // Method algorithms/new/Set.getBlueCubesCount:()I
       8: imul
       9: aload_0
      10: invokevirtual #164                // Method algorithms/new/Set.getGreenCubesCount:()I
      13: imul
      14: ireturn

  private static final algorithms.new.Set getFewestValidGameCubes(java.util.List<algorithms.new.Set>);
    Code:
       0: aload_0
       1: checkcast     #64                 // class java/lang/Iterable
       4: invokeinterface #80,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: astore_3
      10: aload_3
      11: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      16: ifne          27
      19: new           #167                // class java/util/NoSuchElementException
      22: dup
      23: invokespecial #168                // Method java/util/NoSuchElementException."<init>":()V
      26: athrow
      27: aload_3
      28: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #155                // class algorithms/new/Set
      36: astore        4
      38: iconst_0
      39: istore        5
      41: aload         4
      43: invokevirtual #158                // Method algorithms/new/Set.getRedCubesCount:()I
      46: istore        4
      48: aload_3
      49: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          92
      57: aload_3
      58: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: checkcast     #155                // class algorithms/new/Set
      66: astore        5
      68: iconst_0
      69: istore        6
      71: aload         5
      73: invokevirtual #158                // Method algorithms/new/Set.getRedCubesCount:()I
      76: istore        5
      78: iload         4
      80: iload         5
      82: if_icmpge     48
      85: iload         5
      87: istore        4
      89: goto          48
      92: iload         4
      94: istore_1
      95: aload_0
      96: checkcast     #64                 // class java/lang/Iterable
      99: invokeinterface #80,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     104: astore        4
     106: aload         4
     108: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     113: ifne          124
     116: new           #167                // class java/util/NoSuchElementException
     119: dup
     120: invokespecial #168                // Method java/util/NoSuchElementException."<init>":()V
     123: athrow
     124: aload         4
     126: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     131: checkcast     #155                // class algorithms/new/Set
     134: astore        5
     136: iconst_0
     137: istore        6
     139: aload         5
     141: invokevirtual #161                // Method algorithms/new/Set.getBlueCubesCount:()I
     144: istore        5
     146: aload         4
     148: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     153: ifeq          192
     156: aload         4
     158: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     163: checkcast     #155                // class algorithms/new/Set
     166: astore        6
     168: iconst_0
     169: istore        7
     171: aload         6
     173: invokevirtual #161                // Method algorithms/new/Set.getBlueCubesCount:()I
     176: istore        6
     178: iload         5
     180: iload         6
     182: if_icmpge     146
     185: iload         6
     187: istore        5
     189: goto          146
     192: iload         5
     194: istore_2
     195: aload_0
     196: checkcast     #64                 // class java/lang/Iterable
     199: invokeinterface #80,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     204: astore        5
     206: aload         5
     208: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     213: ifne          224
     216: new           #167                // class java/util/NoSuchElementException
     219: dup
     220: invokespecial #168                // Method java/util/NoSuchElementException."<init>":()V
     223: athrow
     224: aload         5
     226: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     231: checkcast     #155                // class algorithms/new/Set
     234: astore        6
     236: iconst_0
     237: istore        7
     239: aload         6
     241: invokevirtual #164                // Method algorithms/new/Set.getGreenCubesCount:()I
     244: istore        6
     246: aload         5
     248: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     253: ifeq          292
     256: aload         5
     258: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     263: checkcast     #155                // class algorithms/new/Set
     266: astore        7
     268: iconst_0
     269: istore        8
     271: aload         7
     273: invokevirtual #164                // Method algorithms/new/Set.getGreenCubesCount:()I
     276: istore        7
     278: iload         6
     280: iload         7
     282: if_icmpge     246
     285: iload         7
     287: istore        6
     289: goto          246
     292: iload         6
     294: istore_3
     295: new           #155                // class algorithms/new/Set
     298: dup
     299: iload_1
     300: iload_3
     301: iload_2
     302: invokespecial #171                // Method algorithms/new/Set."<init>":(III)V
     305: areturn

  private static final algorithms.new.Game parseAsGame(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #181                // Method parseGameId:(Ljava/lang/String;)I
       4: istore_1
       5: aload_0
       6: invokestatic  #26                 // Method parseSets:(Ljava/lang/String;)Ljava/util/List;
       9: astore_2
      10: new           #106                // class algorithms/new/Game
      13: dup
      14: iload_1
      15: aload_2
      16: invokespecial #184                // Method algorithms/new/Game."<init>":(ILjava/util/List;)V
      19: areturn

  private static final int parseGameId(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #56                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #92                 // class java/lang/String
       8: astore_2
       9: aload_2
      10: iconst_0
      11: ldc           #188                // String :
      13: aastore
      14: aload_2
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #192                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: invokestatic  #196                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      26: checkcast     #56                 // class java/lang/CharSequence
      29: iconst_1
      30: anewarray     #92                 // class java/lang/String
      33: astore_2
      34: aload_2
      35: iconst_0
      36: ldc           #198                // String
      38: aastore
      39: aload_2
      40: iconst_0
      41: iconst_0
      42: bipush        6
      44: aconst_null
      45: invokestatic  #192                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      48: astore_1
      49: aload_1
      50: iconst_1
      51: invokeinterface #202,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      56: checkcast     #92                 // class java/lang/String
      59: invokestatic  #207                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      62: ireturn

  private static final java.util.List<algorithms.new.Set> parseSets(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #56                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #92                 // class java/lang/String
       8: astore_2
       9: aload_2
      10: iconst_0
      11: ldc           #188                // String :
      13: aastore
      14: aload_2
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #192                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: invokestatic  #212                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      26: checkcast     #92                 // class java/lang/String
      29: astore_1
      30: aload_1
      31: checkcast     #56                 // class java/lang/CharSequence
      34: iconst_1
      35: anewarray     #92                 // class java/lang/String
      38: astore_3
      39: aload_3
      40: iconst_0
      41: ldc           #214                // String ;
      43: aastore
      44: aload_3
      45: iconst_0
      46: iconst_0
      47: bipush        6
      49: aconst_null
      50: invokestatic  #192                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      53: astore_2
      54: aload_2
      55: checkcast     #64                 // class java/lang/Iterable
      58: astore_3
      59: iconst_0
      60: istore        4
      62: aload_3
      63: astore        5
      65: new           #66                 // class java/util/ArrayList
      68: dup
      69: aload_3
      70: bipush        10
      72: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      75: invokespecial #74                 // Method java/util/ArrayList."<init>":(I)V
      78: checkcast     #76                 // class java/util/Collection
      81: astore        6
      83: iconst_0
      84: istore        7
      86: aload         5
      88: invokeinterface #80,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      93: astore        8
      95: aload         8
      97: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     102: ifeq          145
     105: aload         8
     107: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     112: astore        9
     114: aload         6
     116: aload         9
     118: checkcast     #92                 // class java/lang/String
     121: astore        10
     123: astore        12
     125: iconst_0
     126: istore        11
     128: aload         10
     130: invokestatic  #218                // Method parseStringToSet:(Ljava/lang/String;)Lalgorithms/new/Set;
     133: aload         12
     135: swap
     136: invokeinterface #100,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     141: pop
     142: goto          95
     145: aload         6
     147: checkcast     #102                // class java/util/List
     150: nop
     151: areturn

  private static final algorithms.new.Set parseStringToSet(java.lang.String);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_0
       3: istore_2
       4: iconst_0
       5: istore_3
       6: aload_0
       7: checkcast     #56                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #92                 // class java/lang/String
      14: astore        5
      16: aload         5
      18: iconst_0
      19: ldc           #222                // String ,
      21: aastore
      22: aload         5
      24: iconst_0
      25: iconst_0
      26: bipush        6
      28: aconst_null
      29: invokestatic  #192                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload         4
      39: checkcast     #76                 // class java/util/Collection
      42: invokeinterface #225,  1          // InterfaceMethod java/util/Collection.size:()I
      47: istore        6
      49: iload         5
      51: iload         6
      53: if_icmpge     364
      56: aload         4
      58: iload         5
      60: invokeinterface #202,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      65: checkcast     #92                 // class java/lang/String
      68: astore        8
      70: iconst_0
      71: istore        9
      73: aload         8
      75: checkcast     #56                 // class java/lang/CharSequence
      78: astore        10
      80: new           #227                // class java/lang/StringBuilder
      83: dup
      84: invokespecial #228                // Method java/lang/StringBuilder."<init>":()V
      87: checkcast     #230                // class java/lang/Appendable
      90: astore        11
      92: iconst_0
      93: istore        12
      95: iconst_0
      96: istore        13
      98: aload         10
     100: invokeinterface #233,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     105: istore        14
     107: iload         13
     109: iload         14
     111: if_icmpge     163
     114: aload         10
     116: iload         13
     118: invokeinterface #237,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     123: istore        15
     125: iload         15
     127: istore        16
     129: iconst_0
     130: istore        17
     132: iload         16
     134: bipush        44
     136: if_icmpeq     143
     139: iconst_1
     140: goto          144
     143: iconst_0
     144: ifeq          157
     147: aload         11
     149: iload         15
     151: invokeinterface #241,  2          // InterfaceMethod java/lang/Appendable.append:(C)Ljava/lang/Appendable;
     156: pop
     157: iinc          13, 1
     160: goto          107
     163: aload         11
     165: checkcast     #227                // class java/lang/StringBuilder
     168: invokevirtual #245                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     171: checkcast     #56                 // class java/lang/CharSequence
     174: invokestatic  #249                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     177: invokevirtual #250                // Method java/lang/Object.toString:()Ljava/lang/String;
     180: checkcast     #56                 // class java/lang/CharSequence
     183: iconst_1
     184: anewarray     #92                 // class java/lang/String
     187: astore        8
     189: aload         8
     191: iconst_0
     192: ldc           #198                // String
     194: aastore
     195: aload         8
     197: iconst_0
     198: iconst_0
     199: bipush        6
     201: aconst_null
     202: invokestatic  #192                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     205: astore        7
     207: aload         7
     209: iconst_1
     210: invokeinterface #202,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     215: checkcast     #92                 // class java/lang/String
     218: astore        8
     220: aload         8
     222: invokevirtual #253                // Method java/lang/String.hashCode:()I
     225: lookupswitch  { // 3
                112785: 260
               3027034: 287
              98619139: 273
               default: 358
          }
     260: aload         8
     262: ldc           #255                // String red
     264: invokevirtual #258                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     267: ifne          301
     270: goto          358
     273: aload         8
     275: ldc_w         #260                // String green
     278: invokevirtual #258                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     281: ifne          321
     284: goto          358
     287: aload         8
     289: ldc_w         #262                // String blue
     292: invokevirtual #258                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     295: ifne          341
     298: goto          358
     301: iload_1
     302: aload         7
     304: iconst_0
     305: invokeinterface #202,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     310: checkcast     #92                 // class java/lang/String
     313: invokestatic  #207                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     316: iadd
     317: istore_1
     318: goto          358
     321: iload_2
     322: aload         7
     324: iconst_0
     325: invokeinterface #202,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     330: checkcast     #92                 // class java/lang/String
     333: invokestatic  #207                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     336: iadd
     337: istore_2
     338: goto          358
     341: iload_3
     342: aload         7
     344: iconst_0
     345: invokeinterface #202,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     350: checkcast     #92                 // class java/lang/String
     353: invokestatic  #207                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     356: iadd
     357: istore_3
     358: iinc          5, 1
     361: goto          49
     364: new           #155                // class algorithms/new/Set
     367: dup
     368: iload_1
     369: iload_2
     370: iload_3
     371: invokespecial #171                // Method algorithms/new/Set."<init>":(III)V
     374: areturn

  private static final boolean validateGame(algorithms.new.Game);
    Code:
       0: aload_0
       1: invokevirtual #140                // Method algorithms/new/Game.getSets:()Ljava/util/List;
       4: checkcast     #64                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: instanceof    #76                 // class java/util/Collection
      14: ifeq          33
      17: aload_1
      18: checkcast     #76                 // class java/util/Collection
      21: invokeinterface #273,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      26: ifeq          33
      29: iconst_1
      30: goto          80
      33: aload_1
      34: invokeinterface #80,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore_3
      40: aload_3
      41: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          79
      49: aload_3
      50: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        4
      57: aload         4
      59: checkcast     #155                // class algorithms/new/Set
      62: astore        5
      64: iconst_0
      65: istore        6
      67: aload         5
      69: invokestatic  #277                // Method validateSet:(Lalgorithms/new/Set;)Z
      72: ifne          40
      75: iconst_0
      76: goto          80
      79: iconst_1
      80: ireturn

  private static final boolean validateSet(algorithms.new.Set);
    Code:
       0: aload_0
       1: invokevirtual #158                // Method algorithms/new/Set.getRedCubesCount:()I
       4: getstatic     #53                 // Field bag:Lalgorithms/new/Set;
       7: invokevirtual #158                // Method algorithms/new/Set.getRedCubesCount:()I
      10: if_icmpgt     43
      13: aload_0
      14: invokevirtual #164                // Method algorithms/new/Set.getGreenCubesCount:()I
      17: getstatic     #53                 // Field bag:Lalgorithms/new/Set;
      20: invokevirtual #164                // Method algorithms/new/Set.getGreenCubesCount:()I
      23: if_icmpgt     43
      26: aload_0
      27: invokevirtual #161                // Method algorithms/new/Set.getBlueCubesCount:()I
      30: getstatic     #53                 // Field bag:Lalgorithms/new/Set;
      33: invokevirtual #161                // Method algorithms/new/Set.getBlueCubesCount:()I
      36: if_icmpgt     43
      39: iconst_1
      40: goto          44
      43: iconst_0
      44: ireturn

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

  static {};
    Code:
       0: new           #155                // class algorithms/new/Set
       3: dup
       4: bipush        12
       6: bipush        13
       8: bipush        14
      10: invokespecial #171                // Method algorithms/new/Set."<init>":(III)V
      13: putstatic     #53                 // Field bag:Lalgorithms/new/Set;
      16: return
}