/*
 * Copyright 2023 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

private const val INPUT =
    """
    """

private val lines
    get() = INPUT.lines()
        .map { it.trim() }
        .filter { it.isNotEmpty() }

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

fun day1() {
    println("Running AoC Day 1 (1st part)...")
    firstPart()

    println()

    println("Running AoC Day 1 (2nd part)...")
    secondPart()
}

private fun firstPart() {
    val res = lines.sumOfDigits()

    println("res: $res")
}

private fun secondPart() {
    val res = lines.transformWords().sumOfDigits()

    println("res: $res")
}

private fun List<String>.sumOfDigits() =
    sumOf { line ->
        val digits = line.filter {
            it.isDigit()
        }

        digits.singleOrNull()?.let {
            numberOf(it, it)
        } ?: numberOf(digits.first(), digits.last())
    }

private fun List<String>.transformWords() =
    map { line ->
        var transformedLine = line

        var limit = 0
        var reverse = false

        while (limit <= line.length) {
            val batch = if (reverse) transformedLine.takeLast(limit) else transformedLine.take(limit)
            var transformedBatch = batch

            digitMap.forEach { (word, digit) ->
                transformedBatch = transformedBatch.replace(word, digit)
            }

            val newTransformedLine = transformedLine.replace(batch, transformedBatch)
            val transformed = transformedLine != newTransformedLine

            if ((transformed || batch.contains("\\d".toRegex())) && !reverse) {
                reverse = true
                limit = 0
            } else {
                limit += 1
            }

            transformedLine = newTransformedLine
        }

        transformedLine
    }

private fun numberOf(first: Char, second: Char) =
    String(charArrayOf(first, second)).toInt()

Compiled from "Day1.kt"
public final class Day1Kt {
  private static final java.lang.String INPUT;

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

  private static final java.util.List<java.lang.String> getLines();
    Code:
       0: ldc           #9                  // String \n
       2: checkcast     #11                 // class java/lang/CharSequence
       5: invokestatic  #17                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
       8: checkcast     #19                 // class java/lang/Iterable
      11: astore_0
      12: nop
      13: iconst_0
      14: istore_1
      15: aload_0
      16: astore_2
      17: new           #21                 // class java/util/ArrayList
      20: dup
      21: aload_0
      22: bipush        10
      24: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      27: invokespecial #31                 // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #33                 // class java/util/Collection
      33: astore_3
      34: iconst_0
      35: istore        4
      37: aload_2
      38: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        5
      45: aload         5
      47: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          101
      55: aload         5
      57: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        6
      64: aload_3
      65: aload         6
      67: checkcast     #49                 // class java/lang/String
      70: astore        7
      72: astore        9
      74: iconst_0
      75: istore        8
      77: aload         7
      79: checkcast     #11                 // class java/lang/CharSequence
      82: invokestatic  #53                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      85: invokevirtual #57                 // Method java/lang/Object.toString:()Ljava/lang/String;
      88: nop
      89: aload         9
      91: swap
      92: invokeinterface #61,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      97: pop
      98: goto          45
     101: aload_3
     102: checkcast     #63                 // class java/util/List
     105: nop
     106: checkcast     #19                 // class java/lang/Iterable
     109: astore_0
     110: nop
     111: iconst_0
     112: istore_1
     113: aload_0
     114: astore_2
     115: new           #21                 // class java/util/ArrayList
     118: dup
     119: invokespecial #66                 // Method java/util/ArrayList."<init>":()V
     122: checkcast     #33                 // class java/util/Collection
     125: astore_3
     126: iconst_0
     127: istore        4
     129: aload_2
     130: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     135: astore        5
     137: aload         5
     139: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     144: ifeq          200
     147: aload         5
     149: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     154: astore        6
     156: aload         6
     158: checkcast     #49                 // class java/lang/String
     161: astore        7
     163: iconst_0
     164: istore        8
     166: aload         7
     168: checkcast     #11                 // class java/lang/CharSequence
     171: invokeinterface #70,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     176: ifle          183
     179: iconst_1
     180: goto          184
     183: iconst_0
     184: nop
     185: ifeq          137
     188: aload_3
     189: aload         6
     191: invokeinterface #61,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     196: pop
     197: goto          137
     200: aload_3
     201: checkcast     #63                 // class java/util/List
     204: nop
     205: areturn

  public static final void day1();
    Code:
       0: ldc           #92                 // String Running AoC Day 1 (1st part)...
       2: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: invokestatic  #107                // Method firstPart:()V
      12: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
      15: invokevirtual #109                // Method java/io/PrintStream.println:()V
      18: ldc           #111                // String Running AoC Day 1 (2nd part)...
      20: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
      23: swap
      24: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      27: invokestatic  #114                // Method secondPart:()V
      30: return

  private static final void firstPart();
    Code:
       0: invokestatic  #116                // Method getLines:()Ljava/util/List;
       3: invokestatic  #120                // Method sumOfDigits:(Ljava/util/List;)I
       6: istore_0
       7: new           #122                // class java/lang/StringBuilder
      10: dup
      11: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
      14: ldc           #125                // String res:
      16: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      19: iload_0
      20: invokevirtual #132                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      23: invokevirtual #133                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      26: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
      29: swap
      30: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      33: return

  private static final void secondPart();
    Code:
       0: invokestatic  #116                // Method getLines:()Ljava/util/List;
       3: invokestatic  #138                // Method transformWords:(Ljava/util/List;)Ljava/util/List;
       6: invokestatic  #120                // Method sumOfDigits:(Ljava/util/List;)I
       9: istore_0
      10: new           #122                // class java/lang/StringBuilder
      13: dup
      14: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
      17: ldc           #125                // String res:
      19: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: iload_0
      23: invokevirtual #132                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      26: invokevirtual #133                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      29: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
      32: swap
      33: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      36: return

  private static final int sumOfDigits(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #19                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      13: astore_3
      14: aload_3
      15: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      20: ifeq          207
      23: aload_3
      24: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      29: astore        4
      31: iload_2
      32: aload         4
      34: checkcast     #49                 // class java/lang/String
      37: astore        5
      39: istore        18
      41: iconst_0
      42: istore        6
      44: aload         5
      46: astore        7
      48: iconst_0
      49: istore        8
      51: aload         7
      53: checkcast     #11                 // class java/lang/CharSequence
      56: astore        9
      58: new           #122                // class java/lang/StringBuilder
      61: dup
      62: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
      65: checkcast     #141                // class java/lang/Appendable
      68: astore        10
      70: iconst_0
      71: istore        11
      73: iconst_0
      74: istore        12
      76: aload         9
      78: invokeinterface #70,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      83: istore        13
      85: iload         12
      87: iload         13
      89: if_icmpge     135
      92: aload         9
      94: iload         12
      96: invokeinterface #145,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     101: istore        14
     103: iload         14
     105: istore        15
     107: iconst_0
     108: istore        16
     110: iload         15
     112: invokestatic  #151                // Method java/lang/Character.isDigit:(C)Z
     115: nop
     116: ifeq          129
     119: aload         10
     121: iload         14
     123: invokeinterface #154,  2          // InterfaceMethod java/lang/Appendable.append:(C)Ljava/lang/Appendable;
     128: pop
     129: iinc          12, 1
     132: goto          85
     135: aload         10
     137: checkcast     #122                // class java/lang/StringBuilder
     140: invokevirtual #133                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     143: astore        17
     145: aload         17
     147: checkcast     #11                 // class java/lang/CharSequence
     150: invokestatic  #158                // Method kotlin/text/StringsKt.singleOrNull:(Ljava/lang/CharSequence;)Ljava/lang/Character;
     153: dup
     154: ifnull        176
     157: invokevirtual #162                // Method java/lang/Character.charValue:()C
     160: istore        10
     162: iconst_0
     163: istore        11
     165: iload         10
     167: iload         10
     169: invokestatic  #166                // Method numberOf:(CC)I
     172: nop
     173: goto          196
     176: pop
     177: aload         17
     179: checkcast     #11                 // class java/lang/CharSequence
     182: invokestatic  #170                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     185: aload         17
     187: checkcast     #11                 // class java/lang/CharSequence
     190: invokestatic  #173                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     193: invokestatic  #166                // Method numberOf:(CC)I
     196: istore        19
     198: iload         18
     200: iload         19
     202: iadd
     203: istore_2
     204: goto          14
     207: iload_2
     208: ireturn

  private static final java.util.List<java.lang.String> transformWords(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #19                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #21                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #31                 // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #33                 // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          315
      48: aload         6
      50: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #49                 // class java/lang/String
      64: astore        8
      66: astore        23
      68: iconst_0
      69: istore        9
      71: aload         8
      73: astore        10
      75: iconst_0
      76: istore        11
      78: iconst_0
      79: istore        12
      81: iload         11
      83: aload         8
      85: invokevirtual #186                // Method java/lang/String.length:()I
      88: if_icmpgt     301
      91: iload         12
      93: ifeq          106
      96: aload         10
      98: iload         11
     100: invokestatic  #190                // Method kotlin/text/StringsKt.takeLast:(Ljava/lang/String;I)Ljava/lang/String;
     103: goto          113
     106: aload         10
     108: iload         11
     110: invokestatic  #193                // Method kotlin/text/StringsKt.take:(Ljava/lang/String;I)Ljava/lang/String;
     113: astore        13
     115: aconst_null
     116: astore        14
     118: aload         13
     120: astore        14
     122: getstatic     #197                // Field digitMap:Ljava/util/Map;
     125: astore        15
     127: iconst_0
     128: istore        16
     130: aload         15
     132: invokeinterface #203,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     137: invokeinterface #206,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     142: astore        17
     144: aload         17
     146: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     151: ifeq          216
     154: aload         17
     156: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     161: checkcast     #208                // class java/util/Map$Entry
     164: astore        18
     166: aload         18
     168: astore        19
     170: iconst_0
     171: istore        20
     173: aload         19
     175: invokeinterface #211,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     180: checkcast     #49                 // class java/lang/String
     183: astore        21
     185: aload         19
     187: invokeinterface #214,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     192: checkcast     #49                 // class java/lang/String
     195: astore        22
     197: aload         14
     199: aload         21
     201: aload         22
     203: iconst_0
     204: iconst_4
     205: aconst_null
     206: invokestatic  #218                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
     209: astore        14
     211: nop
     212: nop
     213: goto          144
     216: nop
     217: aload         10
     219: aload         13
     221: aload         14
     223: iconst_0
     224: iconst_4
     225: aconst_null
     226: invokestatic  #218                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
     229: astore        15
     231: aload         10
     233: aload         15
     235: invokestatic  #224                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     238: ifne          245
     241: iconst_1
     242: goto          246
     245: iconst_0
     246: istore        16
     248: iload         16
     250: ifne          277
     253: aload         13
     255: checkcast     #11                 // class java/lang/CharSequence
     258: astore        17
     260: new           #226                // class kotlin/text/Regex
     263: dup
     264: ldc           #228                // String \\d
     266: invokespecial #231                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     269: aload         17
     271: invokevirtual #235                // Method kotlin/text/Regex.containsMatchIn:(Ljava/lang/CharSequence;)Z
     274: ifeq          291
     277: iload         12
     279: ifne          291
     282: iconst_1
     283: istore        12
     285: iconst_0
     286: istore        11
     288: goto          294
     291: iinc          11, 1
     294: aload         15
     296: astore        10
     298: goto          81
     301: aload         10
     303: aload         23
     305: swap
     306: invokeinterface #61,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     311: pop
     312: goto          38
     315: aload         4
     317: checkcast     #63                 // class java/util/List
     320: nop
     321: areturn

  private static final int numberOf(char, char);
    Code:
       0: iconst_2
       1: newarray       char
       3: astore_2
       4: aload_2
       5: iconst_0
       6: iload_0
       7: castore
       8: aload_2
       9: iconst_1
      10: iload_1
      11: castore
      12: aload_2
      13: astore_2
      14: new           #49                 // class java/lang/String
      17: dup
      18: aload_2
      19: invokespecial #255                // Method java/lang/String."<init>":([C)V
      22: invokestatic  #261                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      25: ireturn

  static {};
    Code:
       0: bipush        9
       2: anewarray     #265                // class kotlin/Pair
       5: astore_0
       6: aload_0
       7: iconst_0
       8: ldc_w         #267                // String one
      11: ldc_w         #269                // String 1
      14: invokestatic  #275                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      17: aastore
      18: aload_0
      19: iconst_1
      20: ldc_w         #277                // String two
      23: ldc_w         #279                // String 2
      26: invokestatic  #275                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      29: aastore
      30: aload_0
      31: iconst_2
      32: ldc_w         #281                // String three
      35: ldc_w         #283                // String 3
      38: invokestatic  #275                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      41: aastore
      42: aload_0
      43: iconst_3
      44: ldc_w         #285                // String four
      47: ldc_w         #287                // String 4
      50: invokestatic  #275                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      53: aastore
      54: aload_0
      55: iconst_4
      56: ldc_w         #289                // String five
      59: ldc_w         #291                // String 5
      62: invokestatic  #275                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      65: aastore
      66: aload_0
      67: iconst_5
      68: ldc_w         #293                // String six
      71: ldc_w         #295                // String 6
      74: invokestatic  #275                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      77: aastore
      78: aload_0
      79: bipush        6
      81: ldc_w         #297                // String seven
      84: ldc_w         #299                // String 7
      87: invokestatic  #275                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      90: aastore
      91: aload_0
      92: bipush        7
      94: ldc_w         #301                // String eight
      97: ldc_w         #303                // String 8
     100: invokestatic  #275                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     103: aastore
     104: aload_0
     105: bipush        8
     107: ldc_w         #305                // String nine
     110: ldc_w         #307                // String 9
     113: invokestatic  #275                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     116: aastore
     117: aload_0
     118: invokestatic  #313                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     121: putstatic     #197                // Field digitMap:Ljava/util/Map;
     124: return
}


/*
 * Copyright 2023 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

private const val INPUT =
    """
    """

private data class Num(
    val line: String,
    val lineIndex: Int,
    val at: Int,
    val data: Int
)

private data class Boundary(
    val line: String,
    val lineIndex: Int,
    val start: Int,
    val end: Int,
    val data: String
)

private data class Gear(
    val at: Pair<Int, Int>,
    val first: Num,
    var second: Num? = null
)

private val lines =
    INPUT.lines()
        .map { it.trim() }
        .filter { it.isNotEmpty() }

private val gears = mutableListOf<Gear>()

fun day3() {
    println("Running AoC Day 3 (1st part)...")
    firstPart()

    println()

    println("Running AoC Day 3 (2nd part)...")
    secondPart()
}

private fun firstPart() {
    val res = lines.numbers().sumOf {
        if (it.isAdjacentToSymbol()) it.data else 0
    }

    println("res: $res")
}

private fun secondPart() {
    lines.numbers().forEach {
        it.gears()
    }

    val res = gears
        .filter {
            it.second != null
        }
        .sumOf {
            it.first.data * requireNotNull(it.second?.data)
        }

    println("res: $res")
}

private fun List<String>.numbers() =
    flatMapIndexed { lineIndex, line ->
        line.numbers(lineIndex)
    }

private fun String.numbers(lineIndex: Int): List<Num> =
    buildList {
        var numString: String? = null
        var at: Int? = null

        this@numbers.forEachIndexed { index, char ->
            val isDigit = char.isDigit()

            if (isDigit) {
                numString = (numString ?: "") + char
                at = at ?: index
            }

            if (!isDigit || index == (length - 1)) {
                numString?.let { numStringNotNull ->
                    at?.let { atNotNull ->
                        val number = numStringNotNull.toInt()
                        val num = Num(
                            line = this@numbers,
                            lineIndex = lineIndex,
                            at = atNotNull,
                            data = number
                        )

                        add(num)

                        numString = null
                        at = null
                    }
                }
            }
        }
    }

private fun Num.isAdjacentToSymbol() =
    getBoundaries().any { boundary ->
        boundary.data.containsSymbol()
    }

private fun Num.gears() {
    getBoundaries(excludeInt = false).forEach { boundary ->
        boundary.data.forEachIndexed { index, char ->
            if (char == '*') {
                val coords = boundary.lineIndex to (boundary.start + index)
                getOrPutGear(coords, this@gears)
            }
        }
    }
}

private fun Num.getBoundaries(excludeInt: Boolean = true): List<Boundary> {
    val length = data.toString().length

    val range = getBoundaryRange(length)

    fun String.substring(excludeInt: Boolean = false) =
        substring(range).let { substring ->
            if (excludeInt) substring.filterNot { it.isDigit() } else substring
        }

    val topLineIndex = lineIndex - 1
    val topLineSub = lines.getOrNull(topLineIndex)?.substring()

    val currentLineSub = line.substring(excludeInt = excludeInt)

    val bottomLineIndex = lineIndex + 1
    val bottomLineSub = lines.getOrNull(bottomLineIndex)?.substring()

    return listOfNotNull(
        topLineSub?.to(topLineIndex),
        currentLineSub to lineIndex,
        bottomLineSub?.to(bottomLineIndex)
    ).map { (data, dataLineIndex) ->
        Boundary(
            line = line,
            lineIndex = dataLineIndex,
            start = range.first,
            end = range.last,
            data = data
        )
    }
}

private fun Num.getBoundaryRange(length: Int): IntRange {
    val start = if (at < 1) 0 else at - 1

    val endCandidate = at + length
    val end = if (line.length <= endCandidate) endCandidate - 1 else endCandidate

    return start..end
}

private fun String.containsSymbol() =
    this.contains("[^\\d.]".toRegex())

private fun getOrPutGear(at: Pair<Int, Int>, num: Num): Gear {
    val foundGear = gears.find {
        it.at == at
    }

    foundGear?.second = num

    return foundGear ?: Gear(at, first = num).also {
        gears.add(it)
    }
}

Compiled from "Day3.kt"
public final class Day3Kt {
  private static final java.lang.String INPUT;

  private static final java.util.List<java.lang.String> lines;

  private static final java.util.List<Gear> gears;

  public static final void day3();
    Code:
       0: ldc           #8                  // String Running AoC Day 3 (1st part)...
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: invokestatic  #23                 // Method firstPart:()V
      12: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      15: invokevirtual #25                 // Method java/io/PrintStream.println:()V
      18: ldc           #27                 // String Running AoC Day 3 (2nd part)...
      20: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      23: swap
      24: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      27: invokestatic  #30                 // Method secondPart:()V
      30: return

  private static final void firstPart();
    Code:
       0: getstatic     #34                 // Field lines:Ljava/util/List;
       3: invokestatic  #38                 // Method numbers:(Ljava/util/List;)Ljava/util/List;
       6: checkcast     #40                 // class java/lang/Iterable
       9: astore_1
      10: iconst_0
      11: istore_2
      12: aload_1
      13: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      18: astore_3
      19: aload_3
      20: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      25: ifeq          77
      28: aload_3
      29: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: astore        4
      36: iload_2
      37: aload         4
      39: checkcast     #56                 // class Num
      42: astore        5
      44: istore        7
      46: iconst_0
      47: istore        6
      49: aload         5
      51: invokestatic  #60                 // Method isAdjacentToSymbol:(LNum;)Z
      54: ifeq          65
      57: aload         5
      59: invokevirtual #64                 // Method Num.getData:()I
      62: goto          66
      65: iconst_0
      66: istore        8
      68: iload         7
      70: iload         8
      72: iadd
      73: istore_2
      74: goto          19
      77: iload_2
      78: istore_0
      79: new           #66                 // class java/lang/StringBuilder
      82: dup
      83: invokespecial #69                 // Method java/lang/StringBuilder."<init>":()V
      86: ldc           #71                 // String res:
      88: invokevirtual #75                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      91: iload_0
      92: invokevirtual #78                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      95: invokevirtual #82                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      98: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     101: swap
     102: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     105: return

  private static final void secondPart();
    Code:
       0: getstatic     #34                 // Field lines:Ljava/util/List;
       3: invokestatic  #38                 // Method numbers:(Ljava/util/List;)Ljava/util/List;
       6: checkcast     #40                 // class java/lang/Iterable
       9: astore_0
      10: iconst_0
      11: istore_1
      12: aload_0
      13: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      18: astore_2
      19: aload_2
      20: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      25: ifeq          54
      28: aload_2
      29: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: astore_3
      35: aload_3
      36: checkcast     #56                 // class Num
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload         4
      46: invokestatic  #91                 // Method gears:(LNum;)V
      49: nop
      50: nop
      51: goto          19
      54: nop
      55: getstatic     #93                 // Field gears:Ljava/util/List;
      58: checkcast     #40                 // class java/lang/Iterable
      61: astore_1
      62: nop
      63: iconst_0
      64: istore_2
      65: aload_1
      66: astore_3
      67: new           #95                 // class java/util/ArrayList
      70: dup
      71: invokespecial #96                 // Method java/util/ArrayList."<init>":()V
      74: checkcast     #98                 // class java/util/Collection
      77: astore        4
      79: iconst_0
      80: istore        5
      82: aload_3
      83: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      88: astore        6
      90: aload         6
      92: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      97: ifeq          148
     100: aload         6
     102: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     107: astore        7
     109: aload         7
     111: checkcast     #100                // class Gear
     114: astore        8
     116: iconst_0
     117: istore        9
     119: aload         8
     121: invokevirtual #104                // Method Gear.getSecond:()LNum;
     124: ifnull        131
     127: iconst_1
     128: goto          132
     131: iconst_0
     132: ifeq          90
     135: aload         4
     137: aload         7
     139: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     144: pop
     145: goto          90
     148: aload         4
     150: checkcast     #110                // class java/util/List
     153: nop
     154: checkcast     #40                 // class java/lang/Iterable
     157: astore_1
     158: iconst_0
     159: istore_2
     160: aload_1
     161: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     166: astore_3
     167: aload_3
     168: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     173: ifeq          265
     176: aload_3
     177: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     182: astore        4
     184: iload_2
     185: aload         4
     187: checkcast     #100                // class Gear
     190: astore        5
     192: istore        10
     194: iconst_0
     195: istore        6
     197: aload         5
     199: invokevirtual #113                // Method Gear.getFirst:()LNum;
     202: invokevirtual #64                 // Method Num.getData:()I
     205: aload         5
     207: invokevirtual #104                // Method Gear.getSecond:()LNum;
     210: dup
     211: ifnull        223
     214: invokevirtual #64                 // Method Num.getData:()I
     217: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     220: goto          225
     223: pop
     224: aconst_null
     225: dup
     226: ifnonnull     247
     229: pop
     230: ldc           #121                // String Required value was null.
     232: astore        7
     234: new           #123                // class java/lang/IllegalArgumentException
     237: dup
     238: aload         7
     240: invokevirtual #124                // Method java/lang/Object.toString:()Ljava/lang/String;
     243: invokespecial #127                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     246: athrow
     247: checkcast     #129                // class java/lang/Number
     250: invokevirtual #132                // Method java/lang/Number.intValue:()I
     253: imul
     254: istore        11
     256: iload         10
     258: iload         11
     260: iadd
     261: istore_2
     262: goto          167
     265: iload_2
     266: istore_0
     267: new           #66                 // class java/lang/StringBuilder
     270: dup
     271: invokespecial #69                 // Method java/lang/StringBuilder."<init>":()V
     274: ldc           #71                 // String res:
     276: invokevirtual #75                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     279: iload_0
     280: invokevirtual #78                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     283: invokevirtual #82                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     286: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     289: swap
     290: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     293: return

  private static final java.util.List<Num> numbers(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #40                 // class java/lang/Iterable
       4: astore_1
       5: new           #95                 // class java/util/ArrayList
       8: dup
       9: invokespecial #96                 // Method java/util/ArrayList."<init>":()V
      12: checkcast     #98                 // class java/util/Collection
      15: astore_2
      16: iconst_0
      17: istore_3
      18: aload_1
      19: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      24: astore        4
      26: aload         4
      28: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      33: ifeq          92
      36: aload         4
      38: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      43: astore        5
      45: iload_3
      46: iinc          3, 1
      49: istore        6
      51: iload         6
      53: ifge          59
      56: invokestatic  #154                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      59: iload         6
      61: aload         5
      63: checkcast     #156                // class java/lang/String
      66: astore        7
      68: istore        8
      70: iconst_0
      71: istore        9
      73: aload         7
      75: iload         8
      77: invokestatic  #159                // Method numbers:(Ljava/lang/String;I)Ljava/util/List;
      80: checkcast     #40                 // class java/lang/Iterable
      83: aload_2
      84: swap
      85: invokestatic  #163                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
      88: pop
      89: goto          26
      92: aload_2
      93: checkcast     #110                // class java/util/List
      96: areturn

  private static final java.util.List<Num> numbers(java.lang.String, int);
    Code:
       0: invokestatic  #173                // Method kotlin/collections/CollectionsKt.createListBuilder:()Ljava/util/List;
       3: astore_2
       4: aload_2
       5: astore_3
       6: iconst_0
       7: istore        4
       9: aconst_null
      10: astore        5
      12: aconst_null
      13: astore        6
      15: aload_0
      16: checkcast     #175                // class java/lang/CharSequence
      19: astore        7
      21: iconst_0
      22: istore        8
      24: iconst_0
      25: istore        9
      27: iconst_0
      28: istore        10
      30: iload         10
      32: aload         7
      34: invokeinterface #178,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      39: if_icmpge     223
      42: aload         7
      44: iload         10
      46: invokeinterface #182,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      51: istore        11
      53: iload         9
      55: iinc          9, 1
      58: iload         11
      60: istore        12
      62: istore        13
      64: iconst_0
      65: istore        14
      67: iload         12
      69: invokestatic  #188                // Method java/lang/Character.isDigit:(C)Z
      72: istore        15
      74: iload         15
      76: ifeq          122
      79: new           #66                 // class java/lang/StringBuilder
      82: dup
      83: invokespecial #69                 // Method java/lang/StringBuilder."<init>":()V
      86: aload         5
      88: dup
      89: ifnonnull     95
      92: pop
      93: ldc           #190                // String
      95: invokevirtual #75                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      98: iload         12
     100: invokevirtual #193                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     103: invokevirtual #82                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     106: astore        5
     108: aload         6
     110: dup
     111: ifnonnull     120
     114: pop
     115: iload         13
     117: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     120: astore        6
     122: iload         15
     124: ifeq          138
     127: iload         13
     129: aload_0
     130: invokevirtual #194                // Method java/lang/String.length:()I
     133: iconst_1
     134: isub
     135: if_icmpne     215
     138: aload         5
     140: dup
     141: ifnull        213
     144: astore        16
     146: iconst_0
     147: istore        17
     149: aload         6
     151: dup
     152: ifnull        207
     155: checkcast     #129                // class java/lang/Number
     158: invokevirtual #132                // Method java/lang/Number.intValue:()I
     161: istore        18
     163: iconst_0
     164: istore        19
     166: aload         16
     168: invokestatic  #198                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     171: istore        20
     173: new           #56                 // class Num
     176: dup
     177: aload_0
     178: iload_1
     179: iload         18
     181: iload         20
     183: invokespecial #201                // Method Num."<init>":(Ljava/lang/String;III)V
     186: astore        21
     188: aload_3
     189: aload         21
     191: invokeinterface #202,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     196: pop
     197: aconst_null
     198: astore        5
     200: aconst_null
     201: astore        6
     203: nop
     204: goto          209
     207: pop
     208: nop
     209: nop
     210: goto          215
     213: pop
     214: nop
     215: nop
     216: nop
     217: iinc          10, 1
     220: goto          30
     223: nop
     224: nop
     225: aload_2
     226: invokestatic  #205                // Method kotlin/collections/CollectionsKt.build:(Ljava/util/List;)Ljava/util/List;
     229: areturn

  private static final boolean isAdjacentToSymbol(Num);
    Code:
       0: aload_0
       1: iconst_0
       2: iconst_1
       3: aconst_null
       4: invokestatic  #229                // Method getBoundaries$default:(LNum;ZILjava/lang/Object;)Ljava/util/List;
       7: checkcast     #40                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: instanceof    #98                 // class java/util/Collection
      17: ifeq          36
      20: aload_1
      21: checkcast     #98                 // class java/util/Collection
      24: invokeinterface #232,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      29: ifeq          36
      32: iconst_0
      33: goto          86
      36: aload_1
      37: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore_3
      43: aload_3
      44: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          85
      52: aload_3
      53: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        4
      60: aload         4
      62: checkcast     #234                // class Boundary
      65: astore        5
      67: iconst_0
      68: istore        6
      70: aload         5
      72: invokevirtual #236                // Method Boundary.getData:()Ljava/lang/String;
      75: invokestatic  #240                // Method containsSymbol:(Ljava/lang/String;)Z
      78: ifeq          43
      81: iconst_1
      82: goto          86
      85: iconst_0
      86: ireturn

  private static final void gears(Num);
    Code:
       0: aload_0
       1: iconst_0
       2: invokestatic  #250                // Method getBoundaries:(LNum;Z)Ljava/util/List;
       5: checkcast     #40                 // class java/lang/Iterable
       8: astore_1
       9: iconst_0
      10: istore_2
      11: aload_1
      12: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      17: astore_3
      18: aload_3
      19: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          153
      27: aload_3
      28: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: astore        4
      35: aload         4
      37: checkcast     #234                // class Boundary
      40: astore        5
      42: iconst_0
      43: istore        6
      45: aload         5
      47: invokevirtual #236                // Method Boundary.getData:()Ljava/lang/String;
      50: checkcast     #175                // class java/lang/CharSequence
      53: astore        7
      55: iconst_0
      56: istore        8
      58: iconst_0
      59: istore        9
      61: iconst_0
      62: istore        10
      64: iload         10
      66: aload         7
      68: invokeinterface #178,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      73: if_icmpge     147
      76: aload         7
      78: iload         10
      80: invokeinterface #182,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      85: istore        11
      87: iload         9
      89: iinc          9, 1
      92: iload         11
      94: istore        12
      96: istore        13
      98: iconst_0
      99: istore        14
     101: iload         12
     103: bipush        42
     105: if_icmpne     139
     108: aload         5
     110: invokevirtual #253                // Method Boundary.getLineIndex:()I
     113: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     116: aload         5
     118: invokevirtual #256                // Method Boundary.getStart:()I
     121: iload         13
     123: iadd
     124: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     127: invokestatic  #262                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     130: astore        15
     132: aload         15
     134: aload_0
     135: invokestatic  #266                // Method getOrPutGear:(Lkotlin/Pair;LNum;)LGear;
     138: pop
     139: nop
     140: nop
     141: iinc          10, 1
     144: goto          64
     147: nop
     148: nop
     149: nop
     150: goto          18
     153: nop
     154: return

  private static final java.util.List<Boundary> getBoundaries(Num, boolean);
    Code:
       0: aload_0
       1: invokevirtual #64                 // Method Num.getData:()I
       4: invokestatic  #275                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
       7: invokevirtual #194                // Method java/lang/String.length:()I
      10: istore_2
      11: aload_0
      12: iload_2
      13: invokestatic  #279                // Method getBoundaryRange:(LNum;I)Lkotlin/ranges/IntRange;
      16: astore_3
      17: aload_0
      18: invokevirtual #280                // Method Num.getLineIndex:()I
      21: iconst_1
      22: isub
      23: istore        4
      25: getstatic     #34                 // Field lines:Ljava/util/List;
      28: iload         4
      30: invokestatic  #284                // Method kotlin/collections/CollectionsKt.getOrNull:(Ljava/util/List;I)Ljava/lang/Object;
      33: checkcast     #156                // class java/lang/String
      36: dup
      37: ifnull        50
      40: aload_3
      41: iconst_0
      42: iconst_2
      43: aconst_null
      44: invokestatic  #288                // Method getBoundaries$substring$default:(Ljava/lang/String;Lkotlin/ranges/IntRange;ZILjava/lang/Object;)Ljava/lang/String;
      47: goto          52
      50: pop
      51: aconst_null
      52: astore        5
      54: aload_0
      55: invokevirtual #291                // Method Num.getLine:()Ljava/lang/String;
      58: aload_3
      59: iload_1
      60: invokestatic  #295                // Method getBoundaries$substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;Z)Ljava/lang/String;
      63: astore        6
      65: aload_0
      66: invokevirtual #280                // Method Num.getLineIndex:()I
      69: iconst_1
      70: iadd
      71: istore        7
      73: getstatic     #34                 // Field lines:Ljava/util/List;
      76: iload         7
      78: invokestatic  #284                // Method kotlin/collections/CollectionsKt.getOrNull:(Ljava/util/List;I)Ljava/lang/Object;
      81: checkcast     #156                // class java/lang/String
      84: dup
      85: ifnull        98
      88: aload_3
      89: iconst_0
      90: iconst_2
      91: aconst_null
      92: invokestatic  #288                // Method getBoundaries$substring$default:(Ljava/lang/String;Lkotlin/ranges/IntRange;ZILjava/lang/Object;)Ljava/lang/String;
      95: goto          100
      98: pop
      99: aconst_null
     100: astore        8
     102: iconst_3
     103: anewarray     #297                // class kotlin/Pair
     106: astore        9
     108: aload         9
     110: iconst_0
     111: aload         5
     113: dup
     114: ifnull        128
     117: iload         4
     119: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     122: invokestatic  #262                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     125: goto          130
     128: pop
     129: aconst_null
     130: aastore
     131: aload         9
     133: iconst_1
     134: aload         6
     136: aload_0
     137: invokevirtual #280                // Method Num.getLineIndex:()I
     140: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: invokestatic  #262                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     146: aastore
     147: aload         9
     149: iconst_2
     150: aload         8
     152: dup
     153: ifnull        167
     156: iload         7
     158: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     161: invokestatic  #262                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     164: goto          169
     167: pop
     168: aconst_null
     169: aastore
     170: aload         9
     172: invokestatic  #301                // Method kotlin/collections/CollectionsKt.listOfNotNull:([Ljava/lang/Object;)Ljava/util/List;
     175: checkcast     #40                 // class java/lang/Iterable
     178: astore        9
     180: nop
     181: iconst_0
     182: istore        10
     184: aload         9
     186: astore        11
     188: new           #95                 // class java/util/ArrayList
     191: dup
     192: aload         9
     194: bipush        10
     196: invokestatic  #305                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     199: invokespecial #308                // Method java/util/ArrayList."<init>":(I)V
     202: checkcast     #98                 // class java/util/Collection
     205: astore        12
     207: iconst_0
     208: istore        13
     210: aload         11
     212: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     217: astore        14
     219: aload         14
     221: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     226: ifeq          311
     229: aload         14
     231: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     236: astore        15
     238: aload         12
     240: aload         15
     242: checkcast     #297                // class kotlin/Pair
     245: astore        16
     247: astore        20
     249: iconst_0
     250: istore        17
     252: aload         16
     254: invokevirtual #311                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     257: checkcast     #156                // class java/lang/String
     260: astore        18
     262: aload         16
     264: invokevirtual #314                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     267: checkcast     #129                // class java/lang/Number
     270: invokevirtual #132                // Method java/lang/Number.intValue:()I
     273: istore        19
     275: new           #234                // class Boundary
     278: dup
     279: aload_0
     280: invokevirtual #291                // Method Num.getLine:()Ljava/lang/String;
     283: iload         19
     285: aload_3
     286: invokevirtual #318                // Method kotlin/ranges/IntRange.getFirst:()I
     289: aload_3
     290: invokevirtual #321                // Method kotlin/ranges/IntRange.getLast:()I
     293: aload         18
     295: invokespecial #324                // Method Boundary."<init>":(Ljava/lang/String;IIILjava/lang/String;)V
     298: nop
     299: aload         20
     301: swap
     302: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     307: pop
     308: goto          219
     311: aload         12
     313: checkcast     #110                // class java/util/List
     316: nop
     317: areturn

  static java.util.List getBoundaries$default(Num, boolean, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          8
       6: iconst_1
       7: istore_1
       8: aload_0
       9: iload_1
      10: invokestatic  #250                // Method getBoundaries:(LNum;Z)Ljava/util/List;
      13: areturn

  private static final kotlin.ranges.IntRange getBoundaryRange(Num, int);
    Code:
       0: aload_0
       1: invokevirtual #346                // Method Num.getAt:()I
       4: iconst_1
       5: if_icmpge     12
       8: iconst_0
       9: goto          18
      12: aload_0
      13: invokevirtual #346                // Method Num.getAt:()I
      16: iconst_1
      17: isub
      18: istore_2
      19: aload_0
      20: invokevirtual #346                // Method Num.getAt:()I
      23: iload_1
      24: iadd
      25: istore_3
      26: aload_0
      27: invokevirtual #291                // Method Num.getLine:()Ljava/lang/String;
      30: invokevirtual #194                // Method java/lang/String.length:()I
      33: iload_3
      34: if_icmpgt     43
      37: iload_3
      38: iconst_1
      39: isub
      40: goto          44
      43: iload_3
      44: istore        4
      46: new           #316                // class kotlin/ranges/IntRange
      49: dup
      50: iload_2
      51: iload         4
      53: invokespecial #349                // Method kotlin/ranges/IntRange."<init>":(II)V
      56: areturn

  private static final boolean containsSymbol(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #175                // class java/lang/CharSequence
       4: astore_1
       5: new           #355                // class kotlin/text/Regex
       8: dup
       9: ldc_w         #357                // String [^\\d.]
      12: invokespecial #358                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: aload_1
      16: invokevirtual #362                // Method kotlin/text/Regex.containsMatchIn:(Ljava/lang/CharSequence;)Z
      19: ireturn

  private static final Gear getOrPutGear(kotlin.Pair<java.lang.Integer, java.lang.Integer>, Num);
    Code:
       0: getstatic     #93                 // Field gears:Ljava/util/List;
       3: checkcast     #40                 // class java/lang/Iterable
       6: astore        4
       8: aload         4
      10: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      15: astore        5
      17: aload         5
      19: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          63
      27: aload         5
      29: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: astore        6
      36: aload         6
      38: checkcast     #100                // class Gear
      41: astore        7
      43: iconst_0
      44: istore        8
      46: aload         7
      48: invokevirtual #367                // Method Gear.getAt:()Lkotlin/Pair;
      51: aload_0
      52: invokestatic  #373                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      55: ifeq          17
      58: aload         6
      60: goto          64
      63: aconst_null
      64: checkcast     #100                // class Gear
      67: astore_2
      68: aload_2
      69: dup
      70: ifnull        80
      73: aload_1
      74: invokevirtual #376                // Method Gear.setSecond:(LNum;)V
      77: goto          81
      80: pop
      81: aload_2
      82: dup
      83: ifnonnull     119
      86: pop
      87: new           #100                // class Gear
      90: dup
      91: aload_0
      92: aload_1
      93: aconst_null
      94: iconst_4
      95: aconst_null
      96: invokespecial #379                // Method Gear."<init>":(Lkotlin/Pair;LNum;LNum;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      99: astore_3
     100: aload_3
     101: astore        4
     103: iconst_0
     104: istore        5
     106: getstatic     #93                 // Field gears:Ljava/util/List;
     109: aload         4
     111: invokeinterface #202,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     116: pop
     117: nop
     118: aload_3
     119: areturn

  private static final java.lang.String getBoundaries$substring(java.lang.String, kotlin.ranges.IntRange, boolean);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #388                // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
       5: astore_3
       6: iconst_0
       7: istore        4
       9: iload_2
      10: ifeq          110
      13: aload_3
      14: astore        5
      16: iconst_0
      17: istore        6
      19: aload         5
      21: checkcast     #175                // class java/lang/CharSequence
      24: astore        7
      26: new           #66                 // class java/lang/StringBuilder
      29: dup
      30: invokespecial #69                 // Method java/lang/StringBuilder."<init>":()V
      33: checkcast     #390                // class java/lang/Appendable
      36: astore        8
      38: iconst_0
      39: istore        9
      41: iconst_0
      42: istore        10
      44: iload         10
      46: aload         7
      48: invokeinterface #178,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      53: if_icmpge     99
      56: aload         7
      58: iload         10
      60: invokeinterface #182,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      65: istore        11
      67: iload         11
      69: istore        12
      71: iconst_0
      72: istore        13
      74: iload         12
      76: invokestatic  #188                // Method java/lang/Character.isDigit:(C)Z
      79: nop
      80: ifne          93
      83: aload         8
      85: iload         11
      87: invokeinterface #393,  2          // InterfaceMethod java/lang/Appendable.append:(C)Ljava/lang/Appendable;
      92: pop
      93: iinc          10, 1
      96: goto          44
      99: aload         8
     101: checkcast     #66                 // class java/lang/StringBuilder
     104: invokevirtual #82                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     107: goto          111
     110: aload_3
     111: nop
     112: areturn

  static java.lang.String getBoundaries$substring$default(java.lang.String, kotlin.ranges.IntRange, boolean, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_2
       8: aload_0
       9: aload_1
      10: iload_2
      11: invokestatic  #295                // Method getBoundaries$substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;Z)Ljava/lang/String;
      14: areturn

  static {};
    Code:
       0: ldc_w         #404                // String \n
       3: checkcast     #175                // class java/lang/CharSequence
       6: invokestatic  #407                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
       9: checkcast     #40                 // class java/lang/Iterable
      12: astore_0
      13: nop
      14: iconst_0
      15: istore_1
      16: aload_0
      17: astore_2
      18: new           #95                 // class java/util/ArrayList
      21: dup
      22: aload_0
      23: bipush        10
      25: invokestatic  #305                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      28: invokespecial #308                // Method java/util/ArrayList."<init>":(I)V
      31: checkcast     #98                 // class java/util/Collection
      34: astore_3
      35: iconst_0
      36: istore        4
      38: aload_2
      39: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        5
      46: aload         5
      48: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          102
      56: aload         5
      58: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        6
      65: aload_3
      66: aload         6
      68: checkcast     #156                // class java/lang/String
      71: astore        7
      73: astore        9
      75: iconst_0
      76: istore        8
      78: aload         7
      80: checkcast     #175                // class java/lang/CharSequence
      83: invokestatic  #411                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      86: invokevirtual #124                // Method java/lang/Object.toString:()Ljava/lang/String;
      89: nop
      90: aload         9
      92: swap
      93: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      98: pop
      99: goto          46
     102: aload_3
     103: checkcast     #110                // class java/util/List
     106: nop
     107: checkcast     #40                 // class java/lang/Iterable
     110: astore_0
     111: nop
     112: iconst_0
     113: istore_1
     114: aload_0
     115: astore_2
     116: new           #95                 // class java/util/ArrayList
     119: dup
     120: invokespecial #96                 // Method java/util/ArrayList."<init>":()V
     123: checkcast     #98                 // class java/util/Collection
     126: astore_3
     127: iconst_0
     128: istore        4
     130: aload_2
     131: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     136: astore        5
     138: aload         5
     140: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     145: ifeq          201
     148: aload         5
     150: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     155: astore        6
     157: aload         6
     159: checkcast     #156                // class java/lang/String
     162: astore        7
     164: iconst_0
     165: istore        8
     167: aload         7
     169: checkcast     #175                // class java/lang/CharSequence
     172: invokeinterface #178,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     177: ifle          184
     180: iconst_1
     181: goto          185
     184: iconst_0
     185: nop
     186: ifeq          138
     189: aload_3
     190: aload         6
     192: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     197: pop
     198: goto          138
     201: aload_3
     202: checkcast     #110                // class java/util/List
     205: nop
     206: putstatic     #34                 // Field lines:Ljava/util/List;
     209: new           #95                 // class java/util/ArrayList
     212: dup
     213: invokespecial #96                 // Method java/util/ArrayList."<init>":()V
     216: checkcast     #110                // class java/util/List
     219: putstatic     #93                 // Field gears:Ljava/util/List;
     222: return
}


/*
 * Copyright 2023 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

private const val INPUT =
    """
    """

private const val RED_LIMIT = 12
private const val GREEN_LIMIT = 13
private const val BLUE_LIMIT = 14

private data class Game(
    val id: Int,
    val handfuls: List<Handful>
)

private data class Handful(
    val red: Int,
    val green: Int,
    val blue: Int
)

private val lines
    get() = INPUT.lines()
        .map { it.trim() }
        .filter { it.isNotEmpty() }

fun day2() {
    println("Running AoC Day 2 (1st part)...")
    firstPart()

    println()

    println("Running AoC Day 2 (2nd part)...")
    secondPart()
}

private fun firstPart() {
    val games = lines.parseGames()

    val res = games.sumOf { game ->
        val beyondLimit = game.handfuls.any {
            it.isBeyondLimit()
        }

        if (beyondLimit) 0 else game.id
    }

    println("res: $res")
}

private fun secondPart() {
    val games = lines.parseGames()

    val res = games.sumOf { game ->
        val handfuls = game.handfuls

        val minRed = handfuls.maxOf {
            it.red
        }

        val minGreen = handfuls.maxOf {
            it.green
        }

        val minBlue = handfuls.maxOf {
            it.blue
        }

        minRed * minGreen * minBlue
    }

    println("res: $res")
}

private fun List<String>.parseGames() =
    map {
        it.parseGame()
    }

private fun String.parseGame(): Game {
    val id = findId()

    val handfuls = findHandfulsString()
        .findHandfulDeclarations()
        .map { handfulString ->
            var red = 0
            var green = 0
            var blue = 0

            handfulString.findCubeStrings().forEach { cubeString ->
                val countAndColor = cubeString.split(" ")
                val count = countAndColor.first().toInt()
                val color = countAndColor.last()

                when (color) {
                    "red" -> red += count
                    "green" -> green += count
                    "blue" -> blue += count
                }
            }

            Handful(red, green, blue)
        }

    return Game(id, handfuls)
}

private fun String.findId() =
    requireNotNull("(?<=Game\\s)\\d+".toRegex().find(this)).value.toInt()

private fun String.findHandfulsString() =
    replace("Game\\s\\d+:\\s".toRegex(), "")

private fun String.findHandfulDeclarations() =
    split("; ")

private fun String.findCubeStrings() =
    split(", ")

private fun Handful.isBeyondLimit() =
    red > RED_LIMIT || green > GREEN_LIMIT || blue > BLUE_LIMIT

Compiled from "Day2.kt"
public final class Day2Kt {
  private static final java.lang.String INPUT;

  private static final int RED_LIMIT;

  private static final int GREEN_LIMIT;

  private static final int BLUE_LIMIT;

  private static final java.util.List<java.lang.String> getLines();
    Code:
       0: ldc           #9                  // String \n
       2: checkcast     #11                 // class java/lang/CharSequence
       5: invokestatic  #17                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
       8: checkcast     #19                 // class java/lang/Iterable
      11: astore_0
      12: nop
      13: iconst_0
      14: istore_1
      15: aload_0
      16: astore_2
      17: new           #21                 // class java/util/ArrayList
      20: dup
      21: aload_0
      22: bipush        10
      24: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      27: invokespecial #31                 // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #33                 // class java/util/Collection
      33: astore_3
      34: iconst_0
      35: istore        4
      37: aload_2
      38: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        5
      45: aload         5
      47: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          101
      55: aload         5
      57: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        6
      64: aload_3
      65: aload         6
      67: checkcast     #49                 // class java/lang/String
      70: astore        7
      72: astore        9
      74: iconst_0
      75: istore        8
      77: aload         7
      79: checkcast     #11                 // class java/lang/CharSequence
      82: invokestatic  #53                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      85: invokevirtual #57                 // Method java/lang/Object.toString:()Ljava/lang/String;
      88: nop
      89: aload         9
      91: swap
      92: invokeinterface #61,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      97: pop
      98: goto          45
     101: aload_3
     102: checkcast     #63                 // class java/util/List
     105: nop
     106: checkcast     #19                 // class java/lang/Iterable
     109: astore_0
     110: nop
     111: iconst_0
     112: istore_1
     113: aload_0
     114: astore_2
     115: new           #21                 // class java/util/ArrayList
     118: dup
     119: invokespecial #66                 // Method java/util/ArrayList."<init>":()V
     122: checkcast     #33                 // class java/util/Collection
     125: astore_3
     126: iconst_0
     127: istore        4
     129: aload_2
     130: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     135: astore        5
     137: aload         5
     139: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     144: ifeq          200
     147: aload         5
     149: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     154: astore        6
     156: aload         6
     158: checkcast     #49                 // class java/lang/String
     161: astore        7
     163: iconst_0
     164: istore        8
     166: aload         7
     168: checkcast     #11                 // class java/lang/CharSequence
     171: invokeinterface #70,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     176: ifle          183
     179: iconst_1
     180: goto          184
     183: iconst_0
     184: nop
     185: ifeq          137
     188: aload_3
     189: aload         6
     191: invokeinterface #61,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     196: pop
     197: goto          137
     200: aload_3
     201: checkcast     #63                 // class java/util/List
     204: nop
     205: areturn

  public static final void day2();
    Code:
       0: ldc           #92                 // String Running AoC Day 2 (1st part)...
       2: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: invokestatic  #107                // Method firstPart:()V
      12: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
      15: invokevirtual #109                // Method java/io/PrintStream.println:()V
      18: ldc           #111                // String Running AoC Day 2 (2nd part)...
      20: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
      23: swap
      24: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      27: invokestatic  #114                // Method secondPart:()V
      30: return

  private static final void firstPart();
    Code:
       0: invokestatic  #116                // Method getLines:()Ljava/util/List;
       3: invokestatic  #120                // Method parseGames:(Ljava/util/List;)Ljava/util/List;
       6: astore_0
       7: aload_0
       8: checkcast     #19                 // class java/lang/Iterable
      11: astore_2
      12: iconst_0
      13: istore_3
      14: aload_2
      15: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      20: astore        4
      22: aload         4
      24: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifeq          170
      32: aload         4
      34: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: astore        5
      41: iload_3
      42: aload         5
      44: checkcast     #122                // class Game
      47: astore        6
      49: istore        15
      51: iconst_0
      52: istore        7
      54: aload         6
      56: invokevirtual #125                // Method Game.getHandfuls:()Ljava/util/List;
      59: checkcast     #19                 // class java/lang/Iterable
      62: astore        8
      64: iconst_0
      65: istore        9
      67: aload         8
      69: instanceof    #33                 // class java/util/Collection
      72: ifeq          92
      75: aload         8
      77: checkcast     #33                 // class java/util/Collection
      80: invokeinterface #128,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      85: ifeq          92
      88: iconst_0
      89: goto          143
      92: aload         8
      94: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      99: astore        10
     101: aload         10
     103: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     108: ifeq          142
     111: aload         10
     113: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     118: astore        11
     120: aload         11
     122: checkcast     #130                // class Handful
     125: astore        12
     127: iconst_0
     128: istore        13
     130: aload         12
     132: invokestatic  #134                // Method isBeyondLimit:(LHandful;)Z
     135: ifeq          101
     138: iconst_1
     139: goto          143
     142: iconst_0
     143: istore        14
     145: iload         14
     147: ifeq          154
     150: iconst_0
     151: goto          159
     154: aload         6
     156: invokevirtual #137                // Method Game.getId:()I
     159: istore        16
     161: iload         15
     163: iload         16
     165: iadd
     166: istore_3
     167: goto          22
     170: iload_3
     171: istore_1
     172: new           #139                // class java/lang/StringBuilder
     175: dup
     176: invokespecial #140                // Method java/lang/StringBuilder."<init>":()V
     179: ldc           #142                // String res:
     181: invokevirtual #146                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     184: iload_1
     185: invokevirtual #149                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     188: invokevirtual #150                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     191: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
     194: swap
     195: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     198: return

  private static final void secondPart();
    Code:
       0: invokestatic  #116                // Method getLines:()Ljava/util/List;
       3: invokestatic  #120                // Method parseGames:(Ljava/util/List;)Ljava/util/List;
       6: astore_0
       7: aload_0
       8: checkcast     #19                 // class java/lang/Iterable
      11: astore_2
      12: iconst_0
      13: istore_3
      14: aload_2
      15: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      20: astore        4
      22: aload         4
      24: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifeq          386
      32: aload         4
      34: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: astore        5
      41: iload_3
      42: aload         5
      44: checkcast     #122                // class Game
      47: astore        6
      49: istore        17
      51: iconst_0
      52: istore        7
      54: aload         6
      56: invokevirtual #125                // Method Game.getHandfuls:()Ljava/util/List;
      59: astore        8
      61: aload         8
      63: checkcast     #19                 // class java/lang/Iterable
      66: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      71: astore        9
      73: aload         9
      75: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      80: ifne          91
      83: new           #165                // class java/util/NoSuchElementException
      86: dup
      87: invokespecial #166                // Method java/util/NoSuchElementException."<init>":()V
      90: athrow
      91: aload         9
      93: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      98: checkcast     #130                // class Handful
     101: astore        10
     103: iconst_0
     104: istore        11
     106: aload         10
     108: invokevirtual #169                // Method Handful.getRed:()I
     111: istore        10
     113: aload         9
     115: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     120: ifeq          159
     123: aload         9
     125: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     130: checkcast     #130                // class Handful
     133: astore        11
     135: iconst_0
     136: istore        12
     138: aload         11
     140: invokevirtual #169                // Method Handful.getRed:()I
     143: istore        11
     145: iload         10
     147: iload         11
     149: if_icmpge     113
     152: iload         11
     154: istore        10
     156: goto          113
     159: iload         10
     161: istore        13
     163: aload         8
     165: checkcast     #19                 // class java/lang/Iterable
     168: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     173: astore        10
     175: aload         10
     177: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     182: ifne          193
     185: new           #165                // class java/util/NoSuchElementException
     188: dup
     189: invokespecial #166                // Method java/util/NoSuchElementException."<init>":()V
     192: athrow
     193: aload         10
     195: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     200: checkcast     #130                // class Handful
     203: astore        11
     205: iconst_0
     206: istore        12
     208: aload         11
     210: invokevirtual #172                // Method Handful.getGreen:()I
     213: istore        11
     215: aload         10
     217: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     222: ifeq          261
     225: aload         10
     227: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     232: checkcast     #130                // class Handful
     235: astore        12
     237: iconst_0
     238: istore        14
     240: aload         12
     242: invokevirtual #172                // Method Handful.getGreen:()I
     245: istore        12
     247: iload         11
     249: iload         12
     251: if_icmpge     215
     254: iload         12
     256: istore        11
     258: goto          215
     261: iload         11
     263: istore        15
     265: aload         8
     267: checkcast     #19                 // class java/lang/Iterable
     270: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     275: astore        11
     277: aload         11
     279: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     284: ifne          295
     287: new           #165                // class java/util/NoSuchElementException
     290: dup
     291: invokespecial #166                // Method java/util/NoSuchElementException."<init>":()V
     294: athrow
     295: aload         11
     297: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     302: checkcast     #130                // class Handful
     305: astore        12
     307: iconst_0
     308: istore        14
     310: aload         12
     312: invokevirtual #175                // Method Handful.getBlue:()I
     315: istore        12
     317: aload         11
     319: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     324: ifeq          363
     327: aload         11
     329: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     334: checkcast     #130                // class Handful
     337: astore        14
     339: iconst_0
     340: istore        16
     342: aload         14
     344: invokevirtual #175                // Method Handful.getBlue:()I
     347: istore        14
     349: iload         12
     351: iload         14
     353: if_icmpge     317
     356: iload         14
     358: istore        12
     360: goto          317
     363: iload         12
     365: istore        9
     367: iload         13
     369: iload         15
     371: imul
     372: iload         9
     374: imul
     375: istore        18
     377: iload         17
     379: iload         18
     381: iadd
     382: istore_3
     383: goto          22
     386: iload_3
     387: istore_1
     388: new           #139                // class java/lang/StringBuilder
     391: dup
     392: invokespecial #140                // Method java/lang/StringBuilder."<init>":()V
     395: ldc           #142                // String res:
     397: invokevirtual #146                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     400: iload_1
     401: invokevirtual #149                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     404: invokevirtual #150                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     407: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
     410: swap
     411: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     414: return

  private static final java.util.List<Game> parseGames(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #19                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #21                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #31                 // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #33                 // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          88
      48: aload         6
      50: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #49                 // class java/lang/String
      64: astore        8
      66: astore        10
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokestatic  #188                // Method parseGame:(Ljava/lang/String;)LGame;
      76: aload         10
      78: swap
      79: invokeinterface #61,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      84: pop
      85: goto          38
      88: aload         4
      90: checkcast     #63                 // class java/util/List
      93: nop
      94: areturn

  private static final Game parseGame(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #194                // Method findId:(Ljava/lang/String;)I
       4: istore_1
       5: aload_0
       6: invokestatic  #198                // Method findHandfulsString:(Ljava/lang/String;)Ljava/lang/String;
       9: invokestatic  #202                // Method findHandfulDeclarations:(Ljava/lang/String;)Ljava/util/List;
      12: checkcast     #19                 // class java/lang/Iterable
      15: astore_3
      16: nop
      17: iconst_0
      18: istore        4
      20: aload_3
      21: astore        5
      23: new           #21                 // class java/util/ArrayList
      26: dup
      27: aload_3
      28: bipush        10
      30: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #31                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #33                 // class java/util/Collection
      39: astore        6
      41: iconst_0
      42: istore        7
      44: aload         5
      46: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        8
      53: aload         8
      55: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          337
      63: aload         8
      65: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        9
      72: aload         6
      74: aload         9
      76: checkcast     #49                 // class java/lang/String
      79: astore        10
      81: astore        25
      83: iconst_0
      84: istore        11
      86: iconst_0
      87: istore        12
      89: iconst_0
      90: istore        13
      92: iconst_0
      93: istore        14
      95: aload         10
      97: invokestatic  #205                // Method findCubeStrings:(Ljava/lang/String;)Ljava/util/List;
     100: checkcast     #19                 // class java/lang/Iterable
     103: astore        15
     105: iconst_0
     106: istore        16
     108: aload         15
     110: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     115: astore        17
     117: aload         17
     119: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     124: ifeq          311
     127: aload         17
     129: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     134: astore        18
     136: aload         18
     138: checkcast     #49                 // class java/lang/String
     141: astore        19
     143: iconst_0
     144: istore        20
     146: aload         19
     148: checkcast     #11                 // class java/lang/CharSequence
     151: iconst_1
     152: anewarray     #49                 // class java/lang/String
     155: astore        21
     157: aload         21
     159: iconst_0
     160: ldc           #207                // String
     162: aastore
     163: aload         21
     165: iconst_0
     166: iconst_0
     167: bipush        6
     169: aconst_null
     170: invokestatic  #211                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     173: astore        22
     175: aload         22
     177: invokestatic  #215                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     180: checkcast     #49                 // class java/lang/String
     183: invokestatic  #220                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     186: istore        21
     188: aload         22
     190: invokestatic  #223                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     193: checkcast     #49                 // class java/lang/String
     196: astore        23
     198: aload         23
     200: astore        24
     202: aload         24
     204: invokevirtual #226                // Method java/lang/String.hashCode:()I
     207: lookupswitch  { // 3
                112785: 240
               3027034: 266
              98619139: 253
               default: 306
          }
     240: aload         24
     242: ldc           #228                // String red
     244: invokevirtual #231                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     247: ifne          279
     250: goto          306
     253: aload         24
     255: ldc           #233                // String green
     257: invokevirtual #231                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     260: ifne          289
     263: goto          306
     266: aload         24
     268: ldc           #235                // String blue
     270: invokevirtual #231                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     273: ifne          299
     276: goto          306
     279: iload         12
     281: iload         21
     283: iadd
     284: istore        12
     286: goto          306
     289: iload         13
     291: iload         21
     293: iadd
     294: istore        13
     296: goto          306
     299: iload         14
     301: iload         21
     303: iadd
     304: istore        14
     306: nop
     307: nop
     308: goto          117
     311: nop
     312: new           #130                // class Handful
     315: dup
     316: iload         12
     318: iload         13
     320: iload         14
     322: invokespecial #238                // Method Handful."<init>":(III)V
     325: aload         25
     327: swap
     328: invokeinterface #61,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     333: pop
     334: goto          53
     337: aload         6
     339: checkcast     #63                 // class java/util/List
     342: nop
     343: astore_2
     344: new           #122                // class Game
     347: dup
     348: iload_1
     349: aload_2
     350: invokespecial #241                // Method Game."<init>":(ILjava/util/List;)V
     353: areturn

  private static final int findId(java.lang.String);
    Code:
       0: new           #254                // class kotlin/text/Regex
       3: dup
       4: ldc_w         #256                // String (?<=Game\\s)\\d+
       7: invokespecial #259                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      10: aload_0
      11: checkcast     #11                 // class java/lang/CharSequence
      14: iconst_0
      15: iconst_2
      16: aconst_null
      17: invokestatic  #263                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      20: dup
      21: ifnonnull     41
      24: pop
      25: ldc_w         #265                // String Required value was null.
      28: astore_1
      29: new           #267                // class java/lang/IllegalArgumentException
      32: dup
      33: aload_1
      34: invokevirtual #57                 // Method java/lang/Object.toString:()Ljava/lang/String;
      37: invokespecial #268                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      40: athrow
      41: invokeinterface #273,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      46: invokestatic  #220                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      49: ireturn

  private static final java.lang.String findHandfulsString(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #11                 // class java/lang/CharSequence
       4: astore_1
       5: new           #254                // class kotlin/text/Regex
       8: dup
       9: ldc_w         #276                // String Game\\s\\d+:\\s
      12: invokespecial #259                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: astore_2
      16: ldc_w         #278                // String
      19: astore_3
      20: aload_2
      21: aload_1
      22: aload_3
      23: invokevirtual #282                // Method kotlin/text/Regex.replace:(Ljava/lang/CharSequence;Ljava/lang/String;)Ljava/lang/String;
      26: areturn

  private static final java.util.List<java.lang.String> findHandfulDeclarations(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #11                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #49                 // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc_w         #286                // String ;
      14: aastore
      15: aload_1
      16: iconst_0
      17: iconst_0
      18: bipush        6
      20: aconst_null
      21: invokestatic  #211                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      24: areturn

  private static final java.util.List<java.lang.String> findCubeStrings(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #11                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #49                 // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc_w         #289                // String ,
      14: aastore
      15: aload_1
      16: iconst_0
      17: iconst_0
      18: bipush        6
      20: aconst_null
      21: invokestatic  #211                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      24: areturn

  private static final boolean isBeyondLimit(Handful);
    Code:
       0: aload_0
       1: invokevirtual #169                // Method Handful.getRed:()I
       4: bipush        12
       6: if_icmpgt     27
       9: aload_0
      10: invokevirtual #172                // Method Handful.getGreen:()I
      13: bipush        13
      15: if_icmpgt     27
      18: aload_0
      19: invokevirtual #175                // Method Handful.getBlue:()I
      22: bipush        14
      24: if_icmple     31
      27: iconst_1
      28: goto          32
      31: iconst_0
      32: ireturn
}