import java.io.File
import kotlin.collections.listOf

typealias Entry = List<List<String>>

val DIGS =
    listOf("abcdeg", "ab", "acdfg", "abcdf", "abef", "bcdef", "bcdefg", "abd", "abcdefg", "abcdef")

fun readLines(): List<Entry> {
  return File("in.txt").bufferedReader().readLines().map { l ->
    l.split(" | ").map { it.split(" ") }
  }
}

fun String.permute(result: String = ""): List<String> =
    if (isEmpty()) listOf(result)
    else flatMapIndexed { i, c -> removeRange(i, i + 1).permute(result + c) }

fun partOne(entry: Entry): Int {
  return entry[1].filter { x -> listOf(2, 3, 4, 7).contains(x.length) }.count()
}

fun getValidDigit(perm: String, dig: String): Int {
  // Check if the digit is valid
  var decoded = dig.map { perm[it - 'a'] }.sorted().joinToString("")
  return DIGS.indexOf(decoded)
}

fun tryPerm(perm: String, entry: Entry): Boolean {
  // Check if all signal patterns are valid digits
  var invalid = entry[0].map { getValidDigit(perm, it) }.any { it == -1 }
  return !invalid
}

fun partTwo(entry: Entry): Int {
  // Find correct permutation
  val perm = "abcdefg".permute().find { tryPerm(it, entry) }

  // Concat each digit
  return entry[1].map { getValidDigit(perm!!, it) }.joinToString(separator = "").toInt()
}

fun main() {
  println("Running...\n")

  val lines = readLines()

  val partOne = lines.map { partOne(it) }.sum()
  println("Day 8 part one: $partOne")

  val partTwo = lines.map { partTwo(it) }.sum()
  println("Day 8 part two: $partTwo")
}

Compiled from "main.kt"
public final class MainKt {
  private static final java.util.List<java.lang.String> DIGS;

  public static final java.util.List<java.lang.String> getDIGS();
    Code:
       0: getstatic     #12                 // Field DIGS:Ljava/util/List;
       3: areturn

  public static final java.util.List<java.util.List<java.util.List<java.lang.String>>> readLines();
    Code:
       0: new           #16                 // class java/io/File
       3: dup
       4: ldc           #18                 // String in.txt
       6: invokespecial #22                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: getstatic     #28                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      13: astore_1
      14: sipush        8192
      17: istore_2
      18: aload_0
      19: astore_3
      20: new           #30                 // class java/io/InputStreamReader
      23: dup
      24: new           #32                 // class java/io/FileInputStream
      27: dup
      28: aload_3
      29: invokespecial #35                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      32: checkcast     #37                 // class java/io/InputStream
      35: aload_1
      36: invokespecial #40                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      39: checkcast     #42                 // class java/io/Reader
      42: astore_3
      43: aload_3
      44: instanceof    #44                 // class java/io/BufferedReader
      47: ifeq          57
      50: aload_3
      51: checkcast     #44                 // class java/io/BufferedReader
      54: goto          66
      57: new           #44                 // class java/io/BufferedReader
      60: dup
      61: aload_3
      62: iload_2
      63: invokespecial #47                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      66: checkcast     #42                 // class java/io/Reader
      69: invokestatic  #52                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      72: checkcast     #54                 // class java/lang/Iterable
      75: astore_0
      76: iconst_0
      77: istore_1
      78: aload_0
      79: astore_2
      80: new           #56                 // class java/util/ArrayList
      83: dup
      84: aload_0
      85: bipush        10
      87: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      90: invokespecial #65                 // Method java/util/ArrayList."<init>":(I)V
      93: checkcast     #67                 // class java/util/Collection
      96: astore_3
      97: iconst_0
      98: istore        4
     100: aload_2
     101: invokeinterface #71,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     106: astore        5
     108: aload         5
     110: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     115: ifeq          301
     118: aload         5
     120: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     125: astore        6
     127: aload_3
     128: aload         6
     130: checkcast     #83                 // class java/lang/String
     133: astore        7
     135: astore        20
     137: iconst_0
     138: istore        8
     140: aload         7
     142: checkcast     #85                 // class java/lang/CharSequence
     145: iconst_1
     146: anewarray     #83                 // class java/lang/String
     149: astore        9
     151: aload         9
     153: iconst_0
     154: ldc           #87                 // String  |
     156: aastore
     157: aload         9
     159: iconst_0
     160: iconst_0
     161: bipush        6
     163: aconst_null
     164: invokestatic  #93                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     167: checkcast     #54                 // class java/lang/Iterable
     170: astore        9
     172: iconst_0
     173: istore        10
     175: aload         9
     177: astore        11
     179: new           #56                 // class java/util/ArrayList
     182: dup
     183: aload         9
     185: bipush        10
     187: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     190: invokespecial #65                 // Method java/util/ArrayList."<init>":(I)V
     193: checkcast     #67                 // class java/util/Collection
     196: astore        12
     198: iconst_0
     199: istore        13
     201: aload         11
     203: invokeinterface #71,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     208: astore        14
     210: aload         14
     212: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     217: ifeq          282
     220: aload         14
     222: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     227: astore        15
     229: aload         12
     231: aload         15
     233: checkcast     #83                 // class java/lang/String
     236: astore        16
     238: astore        17
     240: iconst_0
     241: istore        18
     243: aload         16
     245: checkcast     #85                 // class java/lang/CharSequence
     248: iconst_1
     249: anewarray     #83                 // class java/lang/String
     252: astore        19
     254: aload         19
     256: iconst_0
     257: ldc           #95                 // String
     259: aastore
     260: aload         19
     262: iconst_0
     263: iconst_0
     264: bipush        6
     266: aconst_null
     267: invokestatic  #93                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     270: aload         17
     272: swap
     273: invokeinterface #99,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     278: pop
     279: goto          210
     282: aload         12
     284: checkcast     #101                // class java/util/List
     287: nop
     288: nop
     289: aload         20
     291: swap
     292: invokeinterface #99,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     297: pop
     298: goto          108
     301: aload_3
     302: checkcast     #101                // class java/util/List
     305: nop
     306: areturn

  public static final java.util.List<java.lang.String> permute(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #123                // String <this>
       3: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #131                // String result
       9: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #85                 // class java/lang/CharSequence
      16: invokeinterface #135,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      21: ifne          28
      24: iconst_1
      25: goto          29
      28: iconst_0
      29: ifeq          39
      32: aload_1
      33: invokestatic  #139                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      36: goto          161
      39: aload_0
      40: checkcast     #85                 // class java/lang/CharSequence
      43: astore_2
      44: new           #56                 // class java/util/ArrayList
      47: dup
      48: invokespecial #142                // Method java/util/ArrayList."<init>":()V
      51: checkcast     #67                 // class java/util/Collection
      54: astore_3
      55: iconst_0
      56: istore        4
      58: iconst_0
      59: istore        5
      61: iload         5
      63: aload_2
      64: invokeinterface #135,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      69: if_icmpge     157
      72: aload_2
      73: iload         5
      75: invokeinterface #146,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      80: istore        6
      82: iload         4
      84: iinc          4, 1
      87: iload         6
      89: istore        7
      91: istore        8
      93: iconst_0
      94: istore        9
      96: aload_0
      97: astore        10
      99: iload         8
     101: iconst_1
     102: iadd
     103: istore        11
     105: aload         10
     107: checkcast     #85                 // class java/lang/CharSequence
     110: iload         8
     112: iload         11
     114: invokestatic  #150                // Method kotlin/text/StringsKt.removeRange:(Ljava/lang/CharSequence;II)Ljava/lang/CharSequence;
     117: invokevirtual #154                // Method java/lang/Object.toString:()Ljava/lang/String;
     120: new           #156                // class java/lang/StringBuilder
     123: dup
     124: invokespecial #157                // Method java/lang/StringBuilder."<init>":()V
     127: aload_1
     128: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     131: iload         7
     133: invokevirtual #164                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     136: invokevirtual #165                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     139: invokestatic  #167                // Method permute:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
     142: checkcast     #54                 // class java/lang/Iterable
     145: aload_3
     146: swap
     147: invokestatic  #171                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     150: pop
     151: iinc          5, 1
     154: goto          61
     157: aload_3
     158: checkcast     #101                // class java/util/List
     161: areturn

  public static java.util.List permute$default(java.lang.String, java.lang.String, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          9
       6: ldc           #180                // String
       8: astore_1
       9: aload_0
      10: aload_1
      11: invokestatic  #167                // Method permute:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      14: areturn

  public static final int partOne(java.util.List<? extends java.util.List<java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #185                // String entry
       3: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iconst_1
       8: invokeinterface #189,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #54                 // class java/lang/Iterable
      16: astore_1
      17: iconst_0
      18: istore_2
      19: aload_1
      20: astore_3
      21: new           #56                 // class java/util/ArrayList
      24: dup
      25: invokespecial #142                // Method java/util/ArrayList."<init>":()V
      28: checkcast     #67                 // class java/util/Collection
      31: astore        4
      33: iconst_0
      34: istore        5
      36: aload_3
      37: invokeinterface #71,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        6
      44: aload         6
      46: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          146
      54: aload         6
      56: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        7
      63: aload         7
      65: checkcast     #83                 // class java/lang/String
      68: astore        8
      70: iconst_0
      71: istore        9
      73: iconst_4
      74: anewarray     #191                // class java/lang/Integer
      77: astore        10
      79: aload         10
      81: iconst_0
      82: iconst_2
      83: invokestatic  #195                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: aastore
      87: aload         10
      89: iconst_1
      90: iconst_3
      91: invokestatic  #195                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: aastore
      95: aload         10
      97: iconst_2
      98: iconst_4
      99: invokestatic  #195                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     102: aastore
     103: aload         10
     105: iconst_3
     106: bipush        7
     108: invokestatic  #195                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     111: aastore
     112: aload         10
     114: invokestatic  #198                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     117: aload         8
     119: invokevirtual #199                // Method java/lang/String.length:()I
     122: invokestatic  #195                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     125: invokeinterface #202,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     130: ifeq          44
     133: aload         4
     135: aload         7
     137: invokeinterface #99,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     142: pop
     143: goto          44
     146: aload         4
     148: checkcast     #101                // class java/util/List
     151: nop
     152: checkcast     #67                 // class java/util/Collection
     155: invokeinterface #205,  1          // InterfaceMethod java/util/Collection.size:()I
     160: ireturn

  public static final int getValidDigit(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #216                // String perm
       3: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #218                // String dig
       9: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: checkcast     #85                 // class java/lang/CharSequence
      16: astore_3
      17: iconst_0
      18: istore        4
      20: aload_3
      21: astore        5
      23: new           #56                 // class java/util/ArrayList
      26: dup
      27: aload_3
      28: invokeinterface #135,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      33: invokespecial #65                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #67                 // class java/util/Collection
      39: astore        6
      41: iconst_0
      42: istore        7
      44: iconst_0
      45: istore        8
      47: iload         8
      49: aload         5
      51: invokeinterface #135,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      56: if_icmpge     108
      59: aload         5
      61: iload         8
      63: invokeinterface #146,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      68: istore        9
      70: aload         6
      72: iload         9
      74: istore        10
      76: astore        12
      78: iconst_0
      79: istore        11
      81: aload_0
      82: iload         10
      84: bipush        97
      86: isub
      87: invokevirtual #219                // Method java/lang/String.charAt:(I)C
      90: invokestatic  #224                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      93: aload         12
      95: swap
      96: invokeinterface #99,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     101: pop
     102: iinc          8, 1
     105: goto          47
     108: aload         6
     110: checkcast     #101                // class java/util/List
     113: nop
     114: checkcast     #54                 // class java/lang/Iterable
     117: invokestatic  #228                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     120: checkcast     #54                 // class java/lang/Iterable
     123: ldc           #180                // String
     125: checkcast     #85                 // class java/lang/CharSequence
     128: aconst_null
     129: aconst_null
     130: iconst_0
     131: aconst_null
     132: aconst_null
     133: bipush        62
     135: aconst_null
     136: invokestatic  #232                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     139: astore_2
     140: getstatic     #12                 // Field DIGS:Ljava/util/List;
     143: aload_2
     144: invokeinterface #236,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     149: ireturn

  public static final boolean tryPerm(java.lang.String, java.util.List<? extends java.util.List<java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #216                // String perm
       3: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #185                // String entry
       9: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: iconst_0
      14: invokeinterface #189,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      19: checkcast     #54                 // class java/lang/Iterable
      22: astore_3
      23: iconst_0
      24: istore        4
      26: aload_3
      27: astore        5
      29: new           #56                 // class java/util/ArrayList
      32: dup
      33: aload_3
      34: bipush        10
      36: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      39: invokespecial #65                 // Method java/util/ArrayList."<init>":(I)V
      42: checkcast     #67                 // class java/util/Collection
      45: astore        6
      47: iconst_0
      48: istore        7
      50: aload         5
      52: invokeinterface #71,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      57: astore        8
      59: aload         8
      61: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      66: ifeq          113
      69: aload         8
      71: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      76: astore        9
      78: aload         6
      80: aload         9
      82: checkcast     #83                 // class java/lang/String
      85: astore        10
      87: astore        12
      89: iconst_0
      90: istore        11
      92: aload_0
      93: aload         10
      95: invokestatic  #244                // Method getValidDigit:(Ljava/lang/String;Ljava/lang/String;)I
      98: invokestatic  #195                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     101: aload         12
     103: swap
     104: invokeinterface #99,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     109: pop
     110: goto          59
     113: aload         6
     115: checkcast     #101                // class java/util/List
     118: nop
     119: checkcast     #54                 // class java/lang/Iterable
     122: astore_3
     123: nop
     124: iconst_0
     125: istore        4
     127: aload_3
     128: instanceof    #67                 // class java/util/Collection
     131: ifeq          150
     134: aload_3
     135: checkcast     #67                 // class java/util/Collection
     138: invokeinterface #247,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     143: ifeq          150
     146: iconst_0
     147: goto          209
     150: aload_3
     151: invokeinterface #71,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     156: astore        5
     158: aload         5
     160: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     165: ifeq          208
     168: aload         5
     170: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     175: astore        6
     177: aload         6
     179: checkcast     #249                // class java/lang/Number
     182: invokevirtual #252                // Method java/lang/Number.intValue:()I
     185: istore        7
     187: iconst_0
     188: istore        8
     190: iload         7
     192: iconst_m1
     193: if_icmpne     200
     196: iconst_1
     197: goto          201
     200: iconst_0
     201: ifeq          158
     204: iconst_1
     205: goto          209
     208: iconst_0
     209: istore_2
     210: iload_2
     211: ifne          218
     214: iconst_1
     215: goto          219
     218: iconst_0
     219: ireturn

  public static final int partTwo(java.util.List<? extends java.util.List<java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #185                // String entry
       3: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc_w         #262                // String abcdefg
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #264                // Method permute$default:(Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #54                 // class java/lang/Iterable
      18: astore_3
      19: aload_3
      20: invokeinterface #71,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      25: astore        4
      27: aload         4
      29: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          70
      37: aload         4
      39: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      44: astore        5
      46: aload         5
      48: checkcast     #83                 // class java/lang/String
      51: astore        6
      53: iconst_0
      54: istore        7
      56: aload         6
      58: aload_0
      59: invokestatic  #266                // Method tryPerm:(Ljava/lang/String;Ljava/util/List;)Z
      62: ifeq          27
      65: aload         5
      67: goto          71
      70: aconst_null
      71: checkcast     #83                 // class java/lang/String
      74: astore_1
      75: aload_0
      76: iconst_1
      77: invokeinterface #189,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      82: checkcast     #54                 // class java/lang/Iterable
      85: astore_2
      86: iconst_0
      87: istore_3
      88: aload_2
      89: astore        4
      91: new           #56                 // class java/util/ArrayList
      94: dup
      95: aload_2
      96: bipush        10
      98: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     101: invokespecial #65                 // Method java/util/ArrayList."<init>":(I)V
     104: checkcast     #67                 // class java/util/Collection
     107: astore        5
     109: iconst_0
     110: istore        6
     112: aload         4
     114: invokeinterface #71,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     119: astore        7
     121: aload         7
     123: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     128: ifeq          179
     131: aload         7
     133: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     138: astore        8
     140: aload         5
     142: aload         8
     144: checkcast     #83                 // class java/lang/String
     147: astore        9
     149: astore        11
     151: iconst_0
     152: istore        10
     154: aload_1
     155: dup
     156: invokestatic  #270                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     159: aload         9
     161: invokestatic  #244                // Method getValidDigit:(Ljava/lang/String;Ljava/lang/String;)I
     164: invokestatic  #195                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     167: aload         11
     169: swap
     170: invokeinterface #99,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     175: pop
     176: goto          121
     179: aload         5
     181: checkcast     #101                // class java/util/List
     184: nop
     185: checkcast     #54                 // class java/lang/Iterable
     188: ldc           #180                // String
     190: checkcast     #85                 // class java/lang/CharSequence
     193: aconst_null
     194: aconst_null
     195: iconst_0
     196: aconst_null
     197: aconst_null
     198: bipush        62
     200: aconst_null
     201: invokestatic  #232                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     204: invokestatic  #274                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     207: ireturn

  public static final void main();
    Code:
       0: ldc_w         #279                // String Running...\n
       3: getstatic     #285                // Field java/lang/System.out:Ljava/io/PrintStream;
       6: swap
       7: invokevirtual #290                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      10: invokestatic  #292                // Method readLines:()Ljava/util/List;
      13: astore_0
      14: aload_0
      15: checkcast     #54                 // class java/lang/Iterable
      18: astore_2
      19: iconst_0
      20: istore_3
      21: aload_2
      22: astore        4
      24: new           #56                 // class java/util/ArrayList
      27: dup
      28: aload_2
      29: bipush        10
      31: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #65                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #67                 // class java/util/Collection
      40: astore        5
      42: iconst_0
      43: istore        6
      45: aload         4
      47: invokeinterface #71,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        7
      54: aload         7
      56: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          107
      64: aload         7
      66: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: astore        8
      73: aload         5
      75: aload         8
      77: checkcast     #101                // class java/util/List
      80: astore        9
      82: astore        12
      84: iconst_0
      85: istore        10
      87: aload         9
      89: invokestatic  #294                // Method partOne:(Ljava/util/List;)I
      92: invokestatic  #195                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      95: aload         12
      97: swap
      98: invokeinterface #99,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     103: pop
     104: goto          54
     107: aload         5
     109: checkcast     #101                // class java/util/List
     112: nop
     113: checkcast     #54                 // class java/lang/Iterable
     116: invokestatic  #298                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     119: istore_1
     120: new           #156                // class java/lang/StringBuilder
     123: dup
     124: invokespecial #157                // Method java/lang/StringBuilder."<init>":()V
     127: ldc_w         #300                // String Day 8 part one:
     130: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     133: iload_1
     134: invokevirtual #303                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     137: invokevirtual #165                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     140: getstatic     #285                // Field java/lang/System.out:Ljava/io/PrintStream;
     143: swap
     144: invokevirtual #290                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     147: aload_0
     148: checkcast     #54                 // class java/lang/Iterable
     151: astore_3
     152: iconst_0
     153: istore        4
     155: aload_3
     156: astore        5
     158: new           #56                 // class java/util/ArrayList
     161: dup
     162: aload_3
     163: bipush        10
     165: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     168: invokespecial #65                 // Method java/util/ArrayList."<init>":(I)V
     171: checkcast     #67                 // class java/util/Collection
     174: astore        6
     176: iconst_0
     177: istore        7
     179: aload         5
     181: invokeinterface #71,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     186: astore        8
     188: aload         8
     190: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     195: ifeq          241
     198: aload         8
     200: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     205: astore        9
     207: aload         6
     209: aload         9
     211: checkcast     #101                // class java/util/List
     214: astore        10
     216: astore        12
     218: iconst_0
     219: istore        11
     221: aload         10
     223: invokestatic  #305                // Method partTwo:(Ljava/util/List;)I
     226: invokestatic  #195                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     229: aload         12
     231: swap
     232: invokeinterface #99,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     237: pop
     238: goto          188
     241: aload         6
     243: checkcast     #101                // class java/util/List
     246: nop
     247: checkcast     #54                 // class java/lang/Iterable
     250: invokestatic  #298                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     253: istore_2
     254: new           #156                // class java/lang/StringBuilder
     257: dup
     258: invokespecial #157                // Method java/lang/StringBuilder."<init>":()V
     261: ldc_w         #307                // String Day 8 part two:
     264: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     267: iload_2
     268: invokevirtual #303                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     271: invokevirtual #165                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     274: getstatic     #285                // Field java/lang/System.out:Ljava/io/PrintStream;
     277: swap
     278: invokevirtual #290                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     281: return

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

  static {};
    Code:
       0: bipush        10
       2: anewarray     #83                 // class java/lang/String
       5: astore_0
       6: aload_0
       7: iconst_0
       8: ldc_w         #318                // String abcdeg
      11: aastore
      12: aload_0
      13: iconst_1
      14: ldc_w         #320                // String ab
      17: aastore
      18: aload_0
      19: iconst_2
      20: ldc_w         #322                // String acdfg
      23: aastore
      24: aload_0
      25: iconst_3
      26: ldc_w         #324                // String abcdf
      29: aastore
      30: aload_0
      31: iconst_4
      32: ldc_w         #326                // String abef
      35: aastore
      36: aload_0
      37: iconst_5
      38: ldc_w         #328                // String bcdef
      41: aastore
      42: aload_0
      43: bipush        6
      45: ldc_w         #330                // String bcdefg
      48: aastore
      49: aload_0
      50: bipush        7
      52: ldc_w         #332                // String abd
      55: aastore
      56: aload_0
      57: bipush        8
      59: ldc_w         #262                // String abcdefg
      62: aastore
      63: aload_0
      64: bipush        9
      66: ldc_w         #334                // String abcdef
      69: aastore
      70: aload_0
      71: invokestatic  #198                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      74: putstatic     #12                 // Field DIGS:Ljava/util/List;
      77: return
}


import java.io.File

private val numberRegex = Regex("""(\d|one|two|three|four|five|six|seven|eight|nine)""")
private val numberReverseRegex = Regex("""(\d|enin|thgie|neves|xis|evif|ruof|eerht|owt|eno)""")

private val validNumbers = mapOf(
    "1" to 1,
    "2" to 2,
    "3" to 3,
    "4" to 4,
    "5" to 5,
    "6" to 6,
    "7" to 7,
    "8" to 8,
    "9" to 9,
    "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 sumOfCalibrationValues(input: List<String>): Int {
    return input.sumOf {
        "${it.first { it.isDigit() }}${it.last { it.isDigit() }}".toInt()
    }
}

fun readFile(fileName: String): List<String> {
    val resourceFile: File = File("src/main/resources/$fileName") // Adjust the path accordingly
    return resourceFile.bufferedReader().use { it.readLines() }
}

fun sumOfCalibrationValuesWithStringDigits(input: List<String>): Int {
    return input.mapNotNull { line ->
        validNumbers[numberRegex.find(line)?.value ?: ""]
            ?.let { firstDigit ->
                validNumbers[numberReverseRegex.find(line.reversed())?.value?.reversed() ?: ""]
                    ?.let { secondDigit ->
                        "$firstDigit$secondDigit".toInt()
                    }
            }
    }.sum()
}

fun main(args: Array<String>) {
    println("Advent 2023 - Day1")
    // Part 1
//    val input = readFile("day-1-input1.txt")
//    val sumOfCalibrationValues = sumOfCalibrationValues(input)
//    println("Sum: $sumOfCalibrationValues")

    // Part 2
    val input = readFile("day-1-input2.txt")
    val sumOfCalibrationValues = sumOfCalibrationValuesWithStringDigits(input)

    println("Sum: $sumOfCalibrationValues")
}

Compiled from "Day1.kt"
public final class Day1Kt {
  private static final kotlin.text.Regex numberRegex;

  private static final kotlin.text.Regex numberReverseRegex;

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

  public static final int sumOfCalibrationValues(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifeq          252
      29: aload_3
      30: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      35: astore        4
      37: iload_2
      38: aload         4
      40: checkcast     #34                 // class java/lang/String
      43: astore        5
      45: istore        16
      47: iconst_0
      48: istore        6
      50: new           #36                 // class java/lang/StringBuilder
      53: dup
      54: invokespecial #40                 // Method java/lang/StringBuilder."<init>":()V
      57: aload         5
      59: checkcast     #42                 // class java/lang/CharSequence
      62: astore        7
      64: astore        8
      66: iconst_0
      67: istore        9
      69: iconst_0
      70: istore        10
      72: iload         10
      74: aload         7
      76: invokeinterface #46,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      81: if_icmpge     122
      84: aload         7
      86: iload         10
      88: invokeinterface #50,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      93: istore        11
      95: iload         11
      97: istore        12
      99: iconst_0
     100: istore        13
     102: iload         12
     104: invokestatic  #56                 // Method java/lang/Character.isDigit:(C)Z
     107: nop
     108: ifeq          116
     111: iload         11
     113: goto          132
     116: iinc          10, 1
     119: goto          72
     122: new           #58                 // class java/util/NoSuchElementException
     125: dup
     126: ldc           #60                 // String Char sequence contains no character matching the predicate.
     128: invokespecial #63                 // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     131: athrow
     132: istore        14
     134: aload         8
     136: iload         14
     138: invokevirtual #67                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     141: aload         5
     143: checkcast     #42                 // class java/lang/CharSequence
     146: astore        7
     148: astore        8
     150: iconst_0
     151: istore        9
     153: aload         7
     155: invokeinterface #46,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     160: iconst_m1
     161: iadd
     162: istore        10
     164: iconst_0
     165: iload         10
     167: if_icmpgt     215
     170: iload         10
     172: istore        11
     174: iinc          10, -1
     177: aload         7
     179: iload         11
     181: invokeinterface #50,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     186: istore        12
     188: iload         12
     190: istore        13
     192: iconst_0
     193: istore        15
     195: iload         13
     197: invokestatic  #56                 // Method java/lang/Character.isDigit:(C)Z
     200: nop
     201: ifeq          209
     204: iload         12
     206: goto          225
     209: iconst_0
     210: iload         10
     212: if_icmple     170
     215: new           #58                 // class java/util/NoSuchElementException
     218: dup
     219: ldc           #60                 // String Char sequence contains no character matching the predicate.
     221: invokespecial #63                 // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     224: athrow
     225: istore        14
     227: aload         8
     229: iload         14
     231: invokevirtual #67                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     234: invokevirtual #71                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     237: invokestatic  #77                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     240: nop
     241: istore        17
     243: iload         16
     245: iload         17
     247: iadd
     248: istore_2
     249: goto          20
     252: iload_2
     253: ireturn

  public static final java.util.List<java.lang.String> readFile(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #101                // String fileName
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #103                // class java/io/File
       9: dup
      10: new           #36                 // class java/lang/StringBuilder
      13: dup
      14: invokespecial #40                 // Method java/lang/StringBuilder."<init>":()V
      17: ldc           #105                // String src/main/resources/
      19: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: aload_0
      23: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      26: invokevirtual #71                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      29: invokespecial #109                // Method java/io/File."<init>":(Ljava/lang/String;)V
      32: astore_1
      33: aload_1
      34: astore_2
      35: getstatic     #115                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      38: astore_3
      39: sipush        8192
      42: istore        4
      44: aload_2
      45: astore        5
      47: new           #117                // class java/io/InputStreamReader
      50: dup
      51: new           #119                // class java/io/FileInputStream
      54: dup
      55: aload         5
      57: invokespecial #122                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      60: checkcast     #124                // class java/io/InputStream
      63: aload_3
      64: invokespecial #127                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      67: checkcast     #129                // class java/io/Reader
      70: astore        5
      72: aload         5
      74: instanceof    #131                // class java/io/BufferedReader
      77: ifeq          88
      80: aload         5
      82: checkcast     #131                // class java/io/BufferedReader
      85: goto          99
      88: new           #131                // class java/io/BufferedReader
      91: dup
      92: aload         5
      94: iload         4
      96: invokespecial #134                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      99: checkcast     #136                // class java/io/Closeable
     102: astore_2
     103: aconst_null
     104: astore_3
     105: nop
     106: aload_2
     107: checkcast     #131                // class java/io/BufferedReader
     110: astore        4
     112: iconst_0
     113: istore        5
     115: aload         4
     117: checkcast     #129                // class java/io/Reader
     120: invokestatic  #142                // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
     123: astore        4
     125: aload_2
     126: aload_3
     127: invokestatic  #148                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     130: aload         4
     132: goto          153
     135: astore        5
     137: aload         5
     139: astore_3
     140: aload         5
     142: athrow
     143: astore        5
     145: aload_2
     146: aload_3
     147: invokestatic  #148                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     150: aload         5
     152: athrow
     153: areturn
    Exception table:
       from    to  target type
         105   125   135   Class java/lang/Throwable
         105   125   143   any
         135   143   143   any
         143   145   143   any

  public static final int sumOfCalibrationValuesWithStringDigits(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #157                // class java/util/ArrayList
      18: dup
      19: invokespecial #158                // Method java/util/ArrayList."<init>":()V
      22: checkcast     #160                // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: astore        6
      33: iconst_0
      34: istore        7
      36: aload         6
      38: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        8
      45: aload         8
      47: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          289
      55: aload         8
      57: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        9
      64: aload         9
      66: astore        10
      68: iconst_0
      69: istore        11
      71: aload         10
      73: checkcast     #34                 // class java/lang/String
      76: astore        12
      78: iconst_0
      79: istore        13
      81: getstatic     #164                // Field validNumbers:Ljava/util/Map;
      84: getstatic     #168                // Field numberRegex:Lkotlin/text/Regex;
      87: aload         12
      89: checkcast     #42                 // class java/lang/CharSequence
      92: iconst_0
      93: iconst_2
      94: aconst_null
      95: invokestatic  #174                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      98: dup
      99: ifnull        111
     102: invokeinterface #179,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     107: dup
     108: ifnonnull     114
     111: pop
     112: ldc           #181                // String
     114: invokeinterface #187,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     119: checkcast     #73                 // class java/lang/Integer
     122: astore        14
     124: aload         14
     126: ifnull        260
     129: aload         14
     131: checkcast     #189                // class java/lang/Number
     134: invokevirtual #192                // Method java/lang/Number.intValue:()I
     137: istore        15
     139: iconst_0
     140: istore        16
     142: getstatic     #164                // Field validNumbers:Ljava/util/Map;
     145: getstatic     #195                // Field numberReverseRegex:Lkotlin/text/Regex;
     148: aload         12
     150: checkcast     #42                 // class java/lang/CharSequence
     153: invokestatic  #201                // Method kotlin/text/StringsKt.reversed:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     156: invokevirtual #202                // Method java/lang/Object.toString:()Ljava/lang/String;
     159: checkcast     #42                 // class java/lang/CharSequence
     162: iconst_0
     163: iconst_2
     164: aconst_null
     165: invokestatic  #174                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     168: dup
     169: ifnull        194
     172: invokeinterface #179,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     177: dup
     178: ifnull        194
     181: checkcast     #42                 // class java/lang/CharSequence
     184: invokestatic  #201                // Method kotlin/text/StringsKt.reversed:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     187: invokevirtual #202                // Method java/lang/Object.toString:()Ljava/lang/String;
     190: dup
     191: ifnonnull     197
     194: pop
     195: ldc           #181                // String
     197: invokeinterface #187,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     202: checkcast     #73                 // class java/lang/Integer
     205: astore        17
     207: aload         17
     209: ifnull        255
     212: aload         17
     214: checkcast     #189                // class java/lang/Number
     217: invokevirtual #192                // Method java/lang/Number.intValue:()I
     220: istore        18
     222: iconst_0
     223: istore        19
     225: new           #36                 // class java/lang/StringBuilder
     228: dup
     229: invokespecial #40                 // Method java/lang/StringBuilder."<init>":()V
     232: iload         15
     234: invokevirtual #205                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     237: iload         18
     239: invokevirtual #205                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     242: invokevirtual #71                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     245: invokestatic  #77                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     248: nop
     249: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     252: goto          256
     255: aconst_null
     256: nop
     257: goto          261
     260: aconst_null
     261: nop
     262: dup
     263: ifnull        284
     266: astore        20
     268: iconst_0
     269: istore        21
     271: aload         4
     273: aload         20
     275: invokeinterface #213,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     280: pop
     281: goto          285
     284: pop
     285: nop
     286: goto          45
     289: nop
     290: aload         4
     292: checkcast     #94                 // class java/util/List
     295: nop
     296: checkcast     #18                 // class java/lang/Iterable
     299: invokestatic  #219                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     302: ireturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #244                // String args
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #246                // String Advent 2023 - Day1
       8: getstatic     #252                // Field java/lang/System.out:Ljava/io/PrintStream;
      11: swap
      12: invokevirtual #258                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      15: ldc_w         #260                // String day-1-input2.txt
      18: invokestatic  #262                // Method readFile:(Ljava/lang/String;)Ljava/util/List;
      21: astore_1
      22: aload_1
      23: invokestatic  #264                // Method sumOfCalibrationValuesWithStringDigits:(Ljava/util/List;)I
      26: istore_2
      27: new           #36                 // class java/lang/StringBuilder
      30: dup
      31: invokespecial #40                 // Method java/lang/StringBuilder."<init>":()V
      34: ldc_w         #266                // String Sum:
      37: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      40: iload_2
      41: invokevirtual #205                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      44: invokevirtual #71                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      47: getstatic     #252                // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #258                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      54: return

  static {};
    Code:
       0: new           #170                // class kotlin/text/Regex
       3: dup
       4: ldc_w         #270                // String (\\d|one|two|three|four|five|six|seven|eight|nine)
       7: invokespecial #271                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      10: putstatic     #168                // Field numberRegex:Lkotlin/text/Regex;
      13: new           #170                // class kotlin/text/Regex
      16: dup
      17: ldc_w         #273                // String (\\d|enin|thgie|neves|xis|evif|ruof|eerht|owt|eno)
      20: invokespecial #271                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      23: putstatic     #195                // Field numberReverseRegex:Lkotlin/text/Regex;
      26: bipush        18
      28: anewarray     #275                // class kotlin/Pair
      31: astore_0
      32: aload_0
      33: iconst_0
      34: ldc_w         #277                // String 1
      37: iconst_1
      38: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      44: aastore
      45: aload_0
      46: iconst_1
      47: ldc_w         #285                // String 2
      50: iconst_2
      51: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      57: aastore
      58: aload_0
      59: iconst_2
      60: ldc_w         #287                // String 3
      63: iconst_3
      64: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      70: aastore
      71: aload_0
      72: iconst_3
      73: ldc_w         #289                // String 4
      76: iconst_4
      77: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      83: aastore
      84: aload_0
      85: iconst_4
      86: ldc_w         #291                // String 5
      89: iconst_5
      90: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      93: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      96: aastore
      97: aload_0
      98: iconst_5
      99: ldc_w         #293                // String 6
     102: bipush        6
     104: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     107: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     110: aastore
     111: aload_0
     112: bipush        6
     114: ldc_w         #295                // String 7
     117: bipush        7
     119: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     122: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     125: aastore
     126: aload_0
     127: bipush        7
     129: ldc_w         #297                // String 8
     132: bipush        8
     134: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     137: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     140: aastore
     141: aload_0
     142: bipush        8
     144: ldc_w         #299                // String 9
     147: bipush        9
     149: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     152: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     155: aastore
     156: aload_0
     157: bipush        9
     159: ldc_w         #301                // String one
     162: iconst_1
     163: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     166: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     169: aastore
     170: aload_0
     171: bipush        10
     173: ldc_w         #303                // String two
     176: iconst_2
     177: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     180: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     183: aastore
     184: aload_0
     185: bipush        11
     187: ldc_w         #305                // String three
     190: iconst_3
     191: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     194: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     197: aastore
     198: aload_0
     199: bipush        12
     201: ldc_w         #307                // String four
     204: iconst_4
     205: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     208: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     211: aastore
     212: aload_0
     213: bipush        13
     215: ldc_w         #309                // String five
     218: iconst_5
     219: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     222: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     225: aastore
     226: aload_0
     227: bipush        14
     229: ldc_w         #311                // String six
     232: bipush        6
     234: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     237: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     240: aastore
     241: aload_0
     242: bipush        15
     244: ldc_w         #313                // String seven
     247: bipush        7
     249: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     252: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     255: aastore
     256: aload_0
     257: bipush        16
     259: ldc_w         #315                // String eight
     262: bipush        8
     264: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     267: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     270: aastore
     271: aload_0
     272: bipush        17
     274: ldc_w         #317                // String nine
     277: bipush        9
     279: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     282: invokestatic  #283                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     285: aastore
     286: aload_0
     287: invokestatic  #323                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     290: putstatic     #164                // Field validNumbers:Ljava/util/Map;
     293: return
}


import java.util.Locale
import java.util.Optional
import kotlin.jvm.optionals.getOrDefault

data class GameLimit(val redLimit: Int = 12, val greenLimit: Int = 13, val blueLimit: Int = 14)

fun GameLimit.isValid(color: String, count: Int): Boolean {
    return when (color.lowercase(Locale.getDefault())) {
        "red" -> this.redLimit >= count
        "green" -> this.greenLimit >= count
        "blue" -> this.blueLimit >= count
        else -> false
    }
}

private val gameLimit = GameLimit()

fun sumOfIDOfLegitGames(input: List<String>): Int {
    return input.sumOf {
        val limitExceededGameId = getLimitExceededGameId(it).getOrDefault(0)
        limitExceededGameId
    }
}

fun getLimitExceededGameId(gameInput: String): Optional<Int> {
    val regex = Regex("Game (\\d+): (.*)")
    val matchResult = regex.find(gameInput)
    val groups = matchResult?.groupValues!!
    val didLimitExceed = didLimitExceed(groups[1].toInt(), groups[2])
    return if (!didLimitExceed) Optional.of(groups[1].toInt()) else Optional.empty<Int>()
}

fun didLimitExceed(gameId: Int, gameColorInput: String): Boolean {
    val numberRegex = Regex("""(\d+) (\w+)""")
    val numberMatches = numberRegex.findAll(gameColorInput)

    numberMatches.forEach { matchResult ->
        val groups = matchResult.groupValues
        val count = groups[1].toInt()
        val color = groups[2]

        if (!gameLimit.isValid(color = color, count)) return true
    }
    return false
}

fun sumOfIDAndPowerOfLegitGames(input: List<String>): Int {
    return input.sumOf {
        val (gameId, power) = getMinPowerAndGameId(it)
        if (gameId != 0) {
            println("Game $gameId: Minimum Power = $power")
        }
        power
    }
}

fun getMinPowerAndGameId(gameInput: String): Pair<Int, Int> {
    val regex = Regex("Game (\\d+): (.*)")
    val matchResult = regex.find(gameInput)
    val groups = matchResult?.groupValues!!

    val gameId = groups[1].toInt()
    val minPower = calculateMinPower(groups[2])

    return Pair(gameId, minPower)
}

fun calculateMinPower(gameColorInput: String): Int {
    val numberRegex = Regex("""(\d+) (\w+)""")
    val numberMatches = numberRegex.findAll(gameColorInput)

    var maxRed = 1
    var maxGreen = 1
    var maxBlue = 1

    for (matchResult in numberMatches) {
        val groups = matchResult.groupValues
        val count = groups[1].toInt()
        val color = groups[2]

        when (color) {
            "red" -> maxRed = maxOf(maxRed, count)
            "green" -> maxGreen = maxOf(maxGreen, count)
            "blue" -> maxBlue = maxOf(maxBlue, count)
        }
    }

    return maxRed * maxGreen * maxBlue
}

fun main(args: Array<String>) {
    println("Advent 2023 - Day2")

    val input = readFile("day-2-input1.txt")
    // Part 1
//    val sumOfIDOfLegitGames = sumOfIDOfLegitGames(input)
//
//    println("Sum: $sumOfIDOfLegitGames")

    // Part2
    val sumOfIDAndPowerOfLegitGames = sumOfIDAndPowerOfLegitGames(input)

    println("Sum: $sumOfIDAndPowerOfLegitGames")
}

Compiled from "Day2.kt"
public final class Day2Kt {
  private static final GameLimit gameLimit;

  public static final boolean isValid(GameLimit, java.lang.String, int);
    Code:
       0: aload_0
       1: ldc           #9                  // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String color
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: astore        4
      15: invokestatic  #23                 // Method java/util/Locale.getDefault:()Ljava/util/Locale;
      18: dup
      19: ldc           #25                 // String getDefault(...)
      21: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      24: aload         4
      26: swap
      27: invokevirtual #34                 // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
      30: dup
      31: ldc           #36                 // String toLowerCase(...)
      33: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      36: astore_3
      37: aload_3
      38: invokevirtual #40                 // Method java/lang/String.hashCode:()I
      41: lookupswitch  { // 3
                112785: 76
               3027034: 100
              98619139: 88
               default: 160
          }
      76: aload_3
      77: ldc           #42                 // String red
      79: invokevirtual #46                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      82: ifne          112
      85: goto          160
      88: aload_3
      89: ldc           #48                 // String green
      91: invokevirtual #46                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      94: ifne          128
      97: goto          160
     100: aload_3
     101: ldc           #50                 // String blue
     103: invokevirtual #46                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     106: ifne          144
     109: goto          160
     112: aload_0
     113: invokevirtual #55                 // Method GameLimit.getRedLimit:()I
     116: iload_2
     117: if_icmplt     124
     120: iconst_1
     121: goto          161
     124: iconst_0
     125: goto          161
     128: aload_0
     129: invokevirtual #58                 // Method GameLimit.getGreenLimit:()I
     132: iload_2
     133: if_icmplt     140
     136: iconst_1
     137: goto          161
     140: iconst_0
     141: goto          161
     144: aload_0
     145: invokevirtual #61                 // Method GameLimit.getBlueLimit:()I
     148: iload_2
     149: if_icmplt     156
     152: iconst_1
     153: goto          161
     156: iconst_0
     157: goto          161
     160: iconst_0
     161: ireturn

  public static final int sumOfIDOfLegitGames(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #71                 // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #73                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifeq          83
      29: aload_3
      30: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      35: astore        4
      37: iload_2
      38: aload         4
      40: checkcast     #30                 // class java/lang/String
      43: astore        5
      45: istore        8
      47: iconst_0
      48: istore        6
      50: aload         5
      52: invokestatic  #91                 // Method getLimitExceededGameId:(Ljava/lang/String;)Ljava/util/Optional;
      55: iconst_0
      56: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: invokestatic  #103                // Method kotlin/jvm/optionals/OptionalsKt.getOrDefault:(Ljava/util/Optional;Ljava/lang/Object;)Ljava/lang/Object;
      62: checkcast     #105                // class java/lang/Number
      65: invokevirtual #108                // Method java/lang/Number.intValue:()I
      68: istore        7
      70: iload         7
      72: istore        9
      74: iload         8
      76: iload         9
      78: iadd
      79: istore_2
      80: goto          20
      83: iload_2
      84: ireturn

  public static final java.util.Optional<java.lang.Integer> getLimitExceededGameId(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #115                // String gameInput
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #117                // class kotlin/text/Regex
       9: dup
      10: ldc           #119                // String Game (\\d+): (.*)
      12: invokespecial #123                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: astore_1
      16: aload_1
      17: aload_0
      18: checkcast     #125                // class java/lang/CharSequence
      21: iconst_0
      22: iconst_2
      23: aconst_null
      24: invokestatic  #129                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      27: astore_2
      28: aload_2
      29: dup
      30: ifnull        41
      33: invokeinterface #135,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      38: goto          43
      41: pop
      42: aconst_null
      43: dup
      44: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      47: astore_3
      48: aload_3
      49: iconst_1
      50: invokeinterface #145,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      55: checkcast     #30                 // class java/lang/String
      58: invokestatic  #149                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      61: aload_3
      62: iconst_2
      63: invokeinterface #145,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      68: checkcast     #30                 // class java/lang/String
      71: invokestatic  #153                // Method didLimitExceed:(ILjava/lang/String;)Z
      74: istore        4
      76: iload         4
      78: ifne          109
      81: aload_3
      82: iconst_1
      83: invokeinterface #145,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      88: checkcast     #30                 // class java/lang/String
      91: invokestatic  #149                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      94: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      97: invokestatic  #159                // Method java/util/Optional.of:(Ljava/lang/Object;)Ljava/util/Optional;
     100: dup
     101: ldc           #161                // String of(...)
     103: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     106: goto          118
     109: invokestatic  #165                // Method java/util/Optional.empty:()Ljava/util/Optional;
     112: dup
     113: ldc           #167                // String empty(...)
     115: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     118: areturn

  public static final boolean didLimitExceed(int, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #175                // String gameColorInput
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #117                // class kotlin/text/Regex
       9: dup
      10: ldc           #177                // String (\\d+) (\\w+)
      12: invokespecial #123                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: astore_2
      16: aload_2
      17: aload_1
      18: checkcast     #125                // class java/lang/CharSequence
      21: iconst_0
      22: iconst_2
      23: aconst_null
      24: invokestatic  #181                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      27: astore_3
      28: aload_3
      29: astore        4
      31: iconst_0
      32: istore        5
      34: aload         4
      36: invokeinterface #184,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      41: astore        6
      43: aload         6
      45: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          130
      53: aload         6
      55: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        7
      62: aload         7
      64: checkcast     #131                // class kotlin/text/MatchResult
      67: astore        8
      69: iconst_0
      70: istore        9
      72: aload         8
      74: invokeinterface #135,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      79: astore        10
      81: aload         10
      83: iconst_1
      84: invokeinterface #145,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      89: checkcast     #30                 // class java/lang/String
      92: invokestatic  #149                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      95: istore        11
      97: aload         10
      99: iconst_2
     100: invokeinterface #145,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     105: checkcast     #30                 // class java/lang/String
     108: astore        12
     110: getstatic     #187                // Field gameLimit:LGameLimit;
     113: aload         12
     115: iload         11
     117: invokestatic  #189                // Method isValid:(LGameLimit;Ljava/lang/String;I)Z
     120: ifne          125
     123: iconst_1
     124: ireturn
     125: nop
     126: nop
     127: goto          43
     130: nop
     131: iconst_0
     132: ireturn

  public static final int sumOfIDAndPowerOfLegitGames(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #71                 // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #73                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifeq          138
      29: aload_3
      30: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      35: astore        4
      37: iload_2
      38: aload         4
      40: checkcast     #30                 // class java/lang/String
      43: astore        5
      45: istore        10
      47: iconst_0
      48: istore        6
      50: aload         5
      52: invokestatic  #203                // Method getMinPowerAndGameId:(Ljava/lang/String;)Lkotlin/Pair;
      55: astore        7
      57: aload         7
      59: invokevirtual #208                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      62: checkcast     #105                // class java/lang/Number
      65: invokevirtual #108                // Method java/lang/Number.intValue:()I
      68: istore        8
      70: aload         7
      72: invokevirtual #211                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      75: checkcast     #105                // class java/lang/Number
      78: invokevirtual #108                // Method java/lang/Number.intValue:()I
      81: istore        9
      83: iload         8
      85: ifeq          125
      88: new           #213                // class java/lang/StringBuilder
      91: dup
      92: invokespecial #216                // Method java/lang/StringBuilder."<init>":()V
      95: ldc           #218                // String Game
      97: invokevirtual #222                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     100: iload         8
     102: invokevirtual #225                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     105: ldc           #227                // String : Minimum Power =
     107: invokevirtual #222                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     110: iload         9
     112: invokevirtual #225                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     115: invokevirtual #231                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     118: getstatic     #237                // Field java/lang/System.out:Ljava/io/PrintStream;
     121: swap
     122: invokevirtual #242                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     125: iload         9
     127: istore        11
     129: iload         10
     131: iload         11
     133: iadd
     134: istore_2
     135: goto          20
     138: iload_2
     139: ireturn

  public static final kotlin.Pair<java.lang.Integer, java.lang.Integer> getMinPowerAndGameId(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #115                // String gameInput
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #117                // class kotlin/text/Regex
       9: dup
      10: ldc           #119                // String Game (\\d+): (.*)
      12: invokespecial #123                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: astore_1
      16: aload_1
      17: aload_0
      18: checkcast     #125                // class java/lang/CharSequence
      21: iconst_0
      22: iconst_2
      23: aconst_null
      24: invokestatic  #129                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      27: astore_2
      28: aload_2
      29: dup
      30: ifnull        41
      33: invokeinterface #135,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      38: goto          43
      41: pop
      42: aconst_null
      43: dup
      44: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      47: astore_3
      48: aload_3
      49: iconst_1
      50: invokeinterface #145,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      55: checkcast     #30                 // class java/lang/String
      58: invokestatic  #149                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      61: istore        4
      63: aload_3
      64: iconst_2
      65: invokeinterface #145,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      70: checkcast     #30                 // class java/lang/String
      73: invokestatic  #248                // Method calculateMinPower:(Ljava/lang/String;)I
      76: istore        5
      78: new           #205                // class kotlin/Pair
      81: dup
      82: iload         4
      84: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      87: iload         5
      89: invokestatic  #97                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      92: invokespecial #251                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      95: areturn

  public static final int calculateMinPower(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #175                // String gameColorInput
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #117                // class kotlin/text/Regex
       9: dup
      10: ldc           #177                // String (\\d+) (\\w+)
      12: invokespecial #123                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: astore_1
      16: aload_1
      17: aload_0
      18: checkcast     #125                // class java/lang/CharSequence
      21: iconst_0
      22: iconst_2
      23: aconst_null
      24: invokestatic  #181                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      27: astore_2
      28: iconst_1
      29: istore_3
      30: iconst_1
      31: istore        4
      33: iconst_1
      34: istore        5
      36: aload_2
      37: invokeinterface #184,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      42: astore        6
      44: aload         6
      46: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          221
      54: aload         6
      56: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: checkcast     #131                // class kotlin/text/MatchResult
      64: astore        7
      66: aload         7
      68: invokeinterface #135,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      73: astore        8
      75: aload         8
      77: iconst_1
      78: invokeinterface #145,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      83: checkcast     #30                 // class java/lang/String
      86: invokestatic  #149                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      89: istore        9
      91: aload         8
      93: iconst_2
      94: invokeinterface #145,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      99: checkcast     #30                 // class java/lang/String
     102: astore        10
     104: aload         10
     106: astore        11
     108: aload         11
     110: invokevirtual #40                 // Method java/lang/String.hashCode:()I
     113: lookupswitch  { // 3
                112785: 148
               3027034: 174
              98619139: 161
               default: 218
          }
     148: aload         11
     150: ldc           #42                 // String red
     152: invokevirtual #46                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     155: ifne          187
     158: goto          44
     161: aload         11
     163: ldc           #48                 // String green
     165: invokevirtual #46                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     168: ifne          197
     171: goto          44
     174: aload         11
     176: ldc           #50                 // String blue
     178: invokevirtual #46                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     181: ifne          209
     184: goto          44
     187: iload_3
     188: iload         9
     190: invokestatic  #258                // Method java/lang/Math.max:(II)I
     193: istore_3
     194: goto          44
     197: iload         4
     199: iload         9
     201: invokestatic  #258                // Method java/lang/Math.max:(II)I
     204: istore        4
     206: goto          44
     209: iload         5
     211: iload         9
     213: invokestatic  #258                // Method java/lang/Math.max:(II)I
     216: istore        5
     218: goto          44
     221: iload_3
     222: iload         4
     224: imul
     225: iload         5
     227: imul
     228: ireturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc_w         #265                // String args
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: ldc_w         #267                // String Advent 2023 - Day2
      10: getstatic     #237                // Field java/lang/System.out:Ljava/io/PrintStream;
      13: swap
      14: invokevirtual #242                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      17: ldc_w         #269                // String day-2-input1.txt
      20: invokestatic  #275                // Method Day1Kt.readFile:(Ljava/lang/String;)Ljava/util/List;
      23: astore_1
      24: aload_1
      25: invokestatic  #277                // Method sumOfIDAndPowerOfLegitGames:(Ljava/util/List;)I
      28: istore_2
      29: new           #213                // class java/lang/StringBuilder
      32: dup
      33: invokespecial #216                // Method java/lang/StringBuilder."<init>":()V
      36: ldc_w         #279                // String Sum:
      39: invokevirtual #222                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: iload_2
      43: invokevirtual #225                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      46: invokevirtual #231                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      49: getstatic     #237                // Field java/lang/System.out:Ljava/io/PrintStream;
      52: swap
      53: invokevirtual #242                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      56: return

  static {};
    Code:
       0: new           #52                 // class GameLimit
       3: dup
       4: iconst_0
       5: iconst_0
       6: iconst_0
       7: bipush        7
       9: aconst_null
      10: invokespecial #284                // Method GameLimit."<init>":(IIIILkotlin/jvm/internal/DefaultConstructorMarker;)V
      13: putstatic     #187                // Field gameLimit:LGameLimit;
      16: return
}