package day06

import java.io.File
import kotlin.math.ceil
import kotlin.math.sqrt

data class Race(val time: Long, val distance: Long)

fun main() {
    run(::part1, ::solve)
    run(::part1, ::altSolve)
    run(::part2, ::solve)
    run(::part2, ::altSolve)
}

fun run(part: (String) -> List<Long>, solution: (Race) -> Long) {
    val lines = File("input.data").readLines()
    val result = part(lines[0]).zip(part(lines[1]))
        .map { (time, distance) -> Race(time = time, distance = distance) }
        .map { solution(it) }
        .reduce { acc, n -> acc * n }

    println(result)
}

fun part1(line: String): List<Long> = line.split(Regex(" +")).drop(1).map { it.toLong() }

fun part2(line: String): List<Long> = listOf(line.split(Regex(" +")).drop(1).joinToString(separator = "").toLong())

fun solve(race: Race): Long {
    var min = 0L
    var max = race.time / 2
    while (true) {
        val mid = (min + max + 1) / 2
        val prod = mid * (race.time - mid)
        if (prod <= race.distance) {
            min = mid
        } else {
            max = mid
        }
        if (max - min == 1L) {
            return race.time + 1L - 2L * max
        }
    }
}

fun altSolve(race: Race): Long {
    val discriminant = (race.time*race.time - 4*race.distance).toDouble()
    val solution = (race.time - sqrt(discriminant)) / 2
    val roundedUp = ceil(solution).toLong()
    return race.time + 1L - 2L * roundedUp
}

//  2449062
// 33149631

Compiled from "day06.kt"
final class day06.Day06Kt$main$8 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<day06.Race, java.lang.Long> {
  public static final day06.Day06Kt$main$8 INSTANCE;

  day06.Day06Kt$main$8();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day06/Day06Kt
       4: ldc           #13                 // String altSolve
       6: ldc           #15                 // String altSolve(Lday06/Race;)J
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Long invoke(day06.Race);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day06/Day06Kt.altSolve:(Lday06/Race;)J
      10: invokestatic  #39                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #43                 // class day06/Race
       5: invokevirtual #45                 // Method invoke:(Lday06/Race;)Ljava/lang/Long;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day06/Day06Kt$main$8
       3: dup
       4: invokespecial #50                 // Method "<init>":()V
       7: putstatic     #53                 // Field INSTANCE:Lday06/Day06Kt$main$8;
      10: return
}

Compiled from "day06.kt"
public final class day06.Day06Kt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field day06/Day06Kt$main$1.INSTANCE:Lday06/Day06Kt$main$1;
       3: checkcast     #14                 // class kotlin/jvm/functions/Function1
       6: getstatic     #19                 // Field day06/Day06Kt$main$2.INSTANCE:Lday06/Day06Kt$main$2;
       9: checkcast     #14                 // class kotlin/jvm/functions/Function1
      12: invokestatic  #23                 // Method run:(Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
      15: getstatic     #28                 // Field day06/Day06Kt$main$3.INSTANCE:Lday06/Day06Kt$main$3;
      18: checkcast     #14                 // class kotlin/jvm/functions/Function1
      21: getstatic     #33                 // Field day06/Day06Kt$main$4.INSTANCE:Lday06/Day06Kt$main$4;
      24: checkcast     #14                 // class kotlin/jvm/functions/Function1
      27: invokestatic  #23                 // Method run:(Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
      30: getstatic     #38                 // Field day06/Day06Kt$main$5.INSTANCE:Lday06/Day06Kt$main$5;
      33: checkcast     #14                 // class kotlin/jvm/functions/Function1
      36: getstatic     #43                 // Field day06/Day06Kt$main$6.INSTANCE:Lday06/Day06Kt$main$6;
      39: checkcast     #14                 // class kotlin/jvm/functions/Function1
      42: invokestatic  #23                 // Method run:(Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
      45: getstatic     #48                 // Field day06/Day06Kt$main$7.INSTANCE:Lday06/Day06Kt$main$7;
      48: checkcast     #14                 // class kotlin/jvm/functions/Function1
      51: getstatic     #53                 // Field day06/Day06Kt$main$8.INSTANCE:Lday06/Day06Kt$main$8;
      54: checkcast     #14                 // class kotlin/jvm/functions/Function1
      57: invokestatic  #23                 // Method run:(Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
      60: return

  public static final void run(kotlin.jvm.functions.Function1<? super java.lang.String, ? extends java.util.List<java.lang.Long>>, kotlin.jvm.functions.Function1<? super day06.Race, java.lang.Long>);
    Code:
       0: aload_0
       1: ldc           #57                 // String part
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #65                 // String solution
       9: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #67                 // class java/io/File
      15: dup
      16: ldc           #69                 // String input.data
      18: invokespecial #73                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      21: aconst_null
      22: iconst_1
      23: aconst_null
      24: invokestatic  #79                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      27: astore_2
      28: aload_0
      29: aload_2
      30: iconst_0
      31: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      36: invokeinterface #89,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      41: checkcast     #91                 // class java/lang/Iterable
      44: aload_0
      45: aload_2
      46: iconst_1
      47: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      52: invokeinterface #89,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      57: checkcast     #91                 // class java/lang/Iterable
      60: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.zip:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
      63: checkcast     #91                 // class java/lang/Iterable
      66: astore        5
      68: nop
      69: iconst_0
      70: istore        6
      72: aload         5
      74: astore        7
      76: new           #99                 // class java/util/ArrayList
      79: dup
      80: aload         5
      82: bipush        10
      84: invokestatic  #103                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      87: invokespecial #106                // Method java/util/ArrayList."<init>":(I)V
      90: checkcast     #108                // class java/util/Collection
      93: astore        8
      95: iconst_0
      96: istore        9
      98: aload         7
     100: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     105: astore        10
     107: aload         10
     109: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     114: ifeq          189
     117: aload         10
     119: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     124: astore        11
     126: aload         8
     128: aload         11
     130: checkcast     #124                // class kotlin/Pair
     133: astore        12
     135: astore        18
     137: iconst_0
     138: istore        13
     140: aload         12
     142: invokevirtual #127                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     145: checkcast     #129                // class java/lang/Number
     148: invokevirtual #133                // Method java/lang/Number.longValue:()J
     151: lstore        14
     153: aload         12
     155: invokevirtual #136                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     158: checkcast     #129                // class java/lang/Number
     161: invokevirtual #133                // Method java/lang/Number.longValue:()J
     164: lstore        16
     166: new           #138                // class day06/Race
     169: dup
     170: lload         14
     172: lload         16
     174: invokespecial #141                // Method day06/Race."<init>":(JJ)V
     177: aload         18
     179: swap
     180: invokeinterface #145,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     185: pop
     186: goto          107
     189: aload         8
     191: checkcast     #81                 // class java/util/List
     194: nop
     195: checkcast     #91                 // class java/lang/Iterable
     198: astore        5
     200: nop
     201: iconst_0
     202: istore        6
     204: aload         5
     206: astore        7
     208: new           #99                 // class java/util/ArrayList
     211: dup
     212: aload         5
     214: bipush        10
     216: invokestatic  #103                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     219: invokespecial #106                // Method java/util/ArrayList."<init>":(I)V
     222: checkcast     #108                // class java/util/Collection
     225: astore        8
     227: iconst_0
     228: istore        9
     230: aload         7
     232: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     237: astore        10
     239: aload         10
     241: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     246: ifeq          301
     249: aload         10
     251: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     256: astore        11
     258: aload         8
     260: aload         11
     262: checkcast     #138                // class day06/Race
     265: astore        12
     267: astore        18
     269: iconst_0
     270: istore        13
     272: aload_1
     273: aload         12
     275: invokeinterface #89,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     280: checkcast     #129                // class java/lang/Number
     283: invokevirtual #133                // Method java/lang/Number.longValue:()J
     286: invokestatic  #151                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     289: aload         18
     291: swap
     292: invokeinterface #145,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     297: pop
     298: goto          239
     301: aload         8
     303: checkcast     #81                 // class java/util/List
     306: nop
     307: checkcast     #91                 // class java/lang/Iterable
     310: astore        5
     312: nop
     313: iconst_0
     314: istore        6
     316: aload         5
     318: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     323: astore        7
     325: aload         7
     327: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     332: ifne          345
     335: new           #153                // class java/lang/UnsupportedOperationException
     338: dup
     339: ldc           #155                // String Empty collection can\'t be reduced.
     341: invokespecial #156                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     344: athrow
     345: aload         7
     347: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     352: astore        8
     354: aload         7
     356: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     361: ifeq          405
     364: aload         8
     366: aload         7
     368: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     373: checkcast     #129                // class java/lang/Number
     376: invokevirtual #133                // Method java/lang/Number.longValue:()J
     379: lstore        9
     381: checkcast     #129                // class java/lang/Number
     384: invokevirtual #133                // Method java/lang/Number.longValue:()J
     387: lstore        11
     389: iconst_0
     390: istore        13
     392: lload         11
     394: lload         9
     396: lmul
     397: invokestatic  #151                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     400: astore        8
     402: goto          354
     405: aload         8
     407: checkcast     #129                // class java/lang/Number
     410: invokevirtual #133                // Method java/lang/Number.longValue:()J
     413: lstore_3
     414: getstatic     #162                // Field java/lang/System.out:Ljava/io/PrintStream;
     417: lload_3
     418: invokevirtual #168                // Method java/io/PrintStream.println:(J)V
     421: return

  public static final java.util.List<java.lang.Long> part1(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #202                // String line
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #204                // class java/lang/CharSequence
      10: astore_1
      11: new           #206                // class kotlin/text/Regex
      14: dup
      15: ldc           #208                // String  +
      17: invokespecial #209                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      20: astore_2
      21: iconst_0
      22: istore_3
      23: aload_2
      24: aload_1
      25: iload_3
      26: invokevirtual #213                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      29: checkcast     #91                 // class java/lang/Iterable
      32: iconst_1
      33: invokestatic  #217                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      36: checkcast     #91                 // class java/lang/Iterable
      39: astore_1
      40: iconst_0
      41: istore_2
      42: aload_1
      43: astore_3
      44: new           #99                 // class java/util/ArrayList
      47: dup
      48: aload_1
      49: bipush        10
      51: invokestatic  #103                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      54: invokespecial #106                // Method java/util/ArrayList."<init>":(I)V
      57: checkcast     #108                // class java/util/Collection
      60: astore        4
      62: iconst_0
      63: istore        5
      65: aload_3
      66: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      71: astore        6
      73: aload         6
      75: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      80: ifeq          127
      83: aload         6
      85: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      90: astore        7
      92: aload         4
      94: aload         7
      96: checkcast     #219                // class java/lang/String
      99: astore        8
     101: astore        10
     103: iconst_0
     104: istore        9
     106: aload         8
     108: invokestatic  #223                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     111: nop
     112: invokestatic  #151                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     115: aload         10
     117: swap
     118: invokeinterface #145,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     123: pop
     124: goto          73
     127: aload         4
     129: checkcast     #81                 // class java/util/List
     132: nop
     133: areturn

  public static final java.util.List<java.lang.Long> part2(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #202                // String line
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #204                // class java/lang/CharSequence
      10: astore_1
      11: new           #206                // class kotlin/text/Regex
      14: dup
      15: ldc           #208                // String  +
      17: invokespecial #209                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      20: astore_2
      21: iconst_0
      22: istore_3
      23: aload_2
      24: aload_1
      25: iload_3
      26: invokevirtual #213                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      29: checkcast     #91                 // class java/lang/Iterable
      32: iconst_1
      33: invokestatic  #217                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      36: checkcast     #91                 // class java/lang/Iterable
      39: ldc           #228                // String
      41: checkcast     #204                // class java/lang/CharSequence
      44: aconst_null
      45: aconst_null
      46: iconst_0
      47: aconst_null
      48: aconst_null
      49: bipush        62
      51: aconst_null
      52: 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;
      55: invokestatic  #223                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      58: invokestatic  #151                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      61: invokestatic  #236                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      64: areturn

  public static final long solve(day06.Race);
    Code:
       0: aload_0
       1: ldc           #240                // String race
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: lconst_0
       7: lstore_1
       8: aload_0
       9: invokevirtual #243                // Method day06/Race.getTime:()J
      12: iconst_2
      13: i2l
      14: ldiv
      15: lstore_3
      16: nop
      17: lload_1
      18: lload_3
      19: ladd
      20: lconst_1
      21: ladd
      22: iconst_2
      23: i2l
      24: ldiv
      25: lstore        5
      27: lload         5
      29: aload_0
      30: invokevirtual #243                // Method day06/Race.getTime:()J
      33: lload         5
      35: lsub
      36: lmul
      37: lstore        7
      39: lload         7
      41: aload_0
      42: invokevirtual #246                // Method day06/Race.getDistance:()J
      45: lcmp
      46: ifgt          55
      49: lload         5
      51: lstore_1
      52: goto          58
      55: lload         5
      57: lstore_3
      58: lload_3
      59: lload_1
      60: lsub
      61: lconst_1
      62: lcmp
      63: ifne          16
      66: aload_0
      67: invokevirtual #243                // Method day06/Race.getTime:()J
      70: lconst_1
      71: ladd
      72: ldc2_w        #247                // long 2l
      75: lload_3
      76: lmul
      77: lsub
      78: lreturn

  public static final long altSolve(day06.Race);
    Code:
       0: aload_0
       1: ldc           #240                // String race
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #243                // Method day06/Race.getTime:()J
      10: aload_0
      11: invokevirtual #243                // Method day06/Race.getTime:()J
      14: lmul
      15: iconst_4
      16: i2l
      17: aload_0
      18: invokevirtual #246                // Method day06/Race.getDistance:()J
      21: lmul
      22: lsub
      23: l2d
      24: dstore_1
      25: aload_0
      26: invokevirtual #243                // Method day06/Race.getTime:()J
      29: l2d
      30: dload_1
      31: invokestatic  #259                // Method java/lang/Math.sqrt:(D)D
      34: dsub
      35: iconst_2
      36: i2d
      37: ddiv
      38: dstore_3
      39: dload_3
      40: invokestatic  #262                // Method java/lang/Math.ceil:(D)D
      43: d2l
      44: lstore        5
      46: aload_0
      47: invokevirtual #243                // Method day06/Race.getTime:()J
      50: lconst_1
      51: ladd
      52: ldc2_w        #247                // long 2l
      55: lload         5
      57: lmul
      58: lsub
      59: lreturn

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

Compiled from "day06.kt"
final class day06.Day06Kt$main$5 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, java.util.List<? extends java.lang.Long>> {
  public static final day06.Day06Kt$main$5 INSTANCE;

  day06.Day06Kt$main$5();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day06/Day06Kt
       4: ldc           #13                 // String part2
       6: ldc           #15                 // String part2(Ljava/lang/String;)Ljava/util/List;
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.util.List<java.lang.Long> invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #25                 // String p0
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day06/Day06Kt.part2:(Ljava/lang/String;)Ljava/util/List;
      10: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #37                 // class java/lang/String
       5: invokevirtual #39                 // Method invoke:(Ljava/lang/String;)Ljava/util/List;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day06/Day06Kt$main$5
       3: dup
       4: invokespecial #44                 // Method "<init>":()V
       7: putstatic     #47                 // Field INSTANCE:Lday06/Day06Kt$main$5;
      10: return
}

Compiled from "day06.kt"
final class day06.Day06Kt$main$7 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, java.util.List<? extends java.lang.Long>> {
  public static final day06.Day06Kt$main$7 INSTANCE;

  day06.Day06Kt$main$7();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day06/Day06Kt
       4: ldc           #13                 // String part2
       6: ldc           #15                 // String part2(Ljava/lang/String;)Ljava/util/List;
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.util.List<java.lang.Long> invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #25                 // String p0
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day06/Day06Kt.part2:(Ljava/lang/String;)Ljava/util/List;
      10: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #37                 // class java/lang/String
       5: invokevirtual #39                 // Method invoke:(Ljava/lang/String;)Ljava/util/List;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day06/Day06Kt$main$7
       3: dup
       4: invokespecial #44                 // Method "<init>":()V
       7: putstatic     #47                 // Field INSTANCE:Lday06/Day06Kt$main$7;
      10: return
}

Compiled from "day06.kt"
final class day06.Day06Kt$main$3 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, java.util.List<? extends java.lang.Long>> {
  public static final day06.Day06Kt$main$3 INSTANCE;

  day06.Day06Kt$main$3();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day06/Day06Kt
       4: ldc           #13                 // String part1
       6: ldc           #15                 // String part1(Ljava/lang/String;)Ljava/util/List;
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.util.List<java.lang.Long> invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #25                 // String p0
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day06/Day06Kt.part1:(Ljava/lang/String;)Ljava/util/List;
      10: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #37                 // class java/lang/String
       5: invokevirtual #39                 // Method invoke:(Ljava/lang/String;)Ljava/util/List;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day06/Day06Kt$main$3
       3: dup
       4: invokespecial #44                 // Method "<init>":()V
       7: putstatic     #47                 // Field INSTANCE:Lday06/Day06Kt$main$3;
      10: return
}

Compiled from "day06.kt"
final class day06.Day06Kt$main$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, java.util.List<? extends java.lang.Long>> {
  public static final day06.Day06Kt$main$1 INSTANCE;

  day06.Day06Kt$main$1();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day06/Day06Kt
       4: ldc           #13                 // String part1
       6: ldc           #15                 // String part1(Ljava/lang/String;)Ljava/util/List;
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.util.List<java.lang.Long> invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #25                 // String p0
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day06/Day06Kt.part1:(Ljava/lang/String;)Ljava/util/List;
      10: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #37                 // class java/lang/String
       5: invokevirtual #39                 // Method invoke:(Ljava/lang/String;)Ljava/util/List;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day06/Day06Kt$main$1
       3: dup
       4: invokespecial #44                 // Method "<init>":()V
       7: putstatic     #47                 // Field INSTANCE:Lday06/Day06Kt$main$1;
      10: return
}

Compiled from "day06.kt"
final class day06.Day06Kt$main$6 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<day06.Race, java.lang.Long> {
  public static final day06.Day06Kt$main$6 INSTANCE;

  day06.Day06Kt$main$6();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day06/Day06Kt
       4: ldc           #13                 // String solve
       6: ldc           #15                 // String solve(Lday06/Race;)J
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Long invoke(day06.Race);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day06/Day06Kt.solve:(Lday06/Race;)J
      10: invokestatic  #39                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #43                 // class day06/Race
       5: invokevirtual #45                 // Method invoke:(Lday06/Race;)Ljava/lang/Long;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day06/Day06Kt$main$6
       3: dup
       4: invokespecial #50                 // Method "<init>":()V
       7: putstatic     #53                 // Field INSTANCE:Lday06/Day06Kt$main$6;
      10: return
}

Compiled from "day06.kt"
final class day06.Day06Kt$main$4 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<day06.Race, java.lang.Long> {
  public static final day06.Day06Kt$main$4 INSTANCE;

  day06.Day06Kt$main$4();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day06/Day06Kt
       4: ldc           #13                 // String altSolve
       6: ldc           #15                 // String altSolve(Lday06/Race;)J
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Long invoke(day06.Race);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day06/Day06Kt.altSolve:(Lday06/Race;)J
      10: invokestatic  #39                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #43                 // class day06/Race
       5: invokevirtual #45                 // Method invoke:(Lday06/Race;)Ljava/lang/Long;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day06/Day06Kt$main$4
       3: dup
       4: invokespecial #50                 // Method "<init>":()V
       7: putstatic     #53                 // Field INSTANCE:Lday06/Day06Kt$main$4;
      10: return
}

Compiled from "day06.kt"
final class day06.Day06Kt$main$2 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<day06.Race, java.lang.Long> {
  public static final day06.Day06Kt$main$2 INSTANCE;

  day06.Day06Kt$main$2();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day06/Day06Kt
       4: ldc           #13                 // String solve
       6: ldc           #15                 // String solve(Lday06/Race;)J
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Long invoke(day06.Race);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day06/Day06Kt.solve:(Lday06/Race;)J
      10: invokestatic  #39                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #43                 // class day06/Race
       5: invokevirtual #45                 // Method invoke:(Lday06/Race;)Ljava/lang/Long;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day06/Day06Kt$main$2
       3: dup
       4: invokespecial #50                 // Method "<init>":()V
       7: putstatic     #53                 // Field INSTANCE:Lday06/Day06Kt$main$2;
      10: return
}


package day04

import java.io.File

fun main() {
    Part1("input.data").run()
    Part2("input.data").run()
}

data class Card(val matchingNumbers: Int, var copies: Int = 1)

abstract class Day04(val fileName: String) {
    val cards = parseInput()

    fun run() {
        var result = 0

        for ((idx, card) in cards.withIndex()) {
            for (idx2 in idx + 1..idx + card.matchingNumbers) {
                cards[idx2].copies += card.copies
            }
            result += score(card)
        }

        println(result)
    }

    abstract fun score(card: Card): Int

    private fun parseInput(): List<Card> {
        val cards = mutableListOf<Card>()
        for (line in File(fileName).readLines()) {
            val parts = line.split(": ", " | ")
            cards += Card(matchingNumbers = parseNumbers(parts[1]).intersect(parseNumbers(parts[2])).size)
        }
        return cards
    }

    private fun parseNumbers(numbers: String) = numbers.trim().split(Regex(" +")).toSet()
}

class Part1(fileName: String) : Day04(fileName) {
    override fun score(card: Card): Int {
        if (card.matchingNumbers == 0) return 0
        var result = 1
        repeat(card.matchingNumbers - 1) { result *= 2 }
        return result
    }
}

class Part2(fileName: String) : Day04(fileName) {
    override fun score(card: Card): Int = card.copies
}

// Part1:    25004
// Part2: 14427616

Compiled from "day04.kt"
public final class day04.Day04Kt {
  public static final void main();
    Code:
       0: new           #8                  // class day04/Part1
       3: dup
       4: ldc           #10                 // String input.data
       6: invokespecial #14                 // Method day04/Part1."<init>":(Ljava/lang/String;)V
       9: invokevirtual #17                 // Method day04/Part1.run:()V
      12: new           #19                 // class day04/Part2
      15: dup
      16: ldc           #10                 // String input.data
      18: invokespecial #20                 // Method day04/Part2."<init>":(Ljava/lang/String;)V
      21: invokevirtual #21                 // Method day04/Part2.run:()V
      24: return

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

Compiled from "day04.kt"
public abstract class day04.Day04 {
  private final java.lang.String fileName;

  private final java.util.List<day04.Card> cards;

  public day04.Day04(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String fileName
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #21                 // Field fileName:Ljava/lang/String;
      15: aload_0
      16: aload_0
      17: invokespecial #25                 // Method parseInput:()Ljava/util/List;
      20: putfield      #29                 // Field cards:Ljava/util/List;
      23: return

  public final java.lang.String getFileName();
    Code:
       0: aload_0
       1: getfield      #21                 // Field fileName:Ljava/lang/String;
       4: areturn

  public final java.util.List<day04.Card> getCards();
    Code:
       0: aload_0
       1: getfield      #29                 // Field cards:Ljava/util/List;
       4: areturn

  public final void run();
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: getfield      #29                 // Field cards:Ljava/util/List;
       6: checkcast     #38                 // class java/lang/Iterable
       9: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      14: astore_2
      15: iconst_0
      16: istore_3
      17: aload_2
      18: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          124
      26: iload_3
      27: istore        4
      29: iload_3
      30: iconst_1
      31: iadd
      32: istore_3
      33: aload_2
      34: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #54                 // class day04/Card
      42: astore        5
      44: iload         4
      46: iconst_1
      47: iadd
      48: istore        6
      50: iload         4
      52: aload         5
      54: invokevirtual #58                 // Method day04/Card.getMatchingNumbers:()I
      57: iadd
      58: istore        7
      60: iload         6
      62: iload         7
      64: if_icmpgt     112
      67: aload_0
      68: getfield      #29                 // Field cards:Ljava/util/List;
      71: iload         6
      73: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      78: checkcast     #54                 // class day04/Card
      81: astore        8
      83: aload         8
      85: aload         8
      87: invokevirtual #67                 // Method day04/Card.getCopies:()I
      90: aload         5
      92: invokevirtual #67                 // Method day04/Card.getCopies:()I
      95: iadd
      96: invokevirtual #71                 // Method day04/Card.setCopies:(I)V
      99: iload         6
     101: iload         7
     103: if_icmpeq     112
     106: iinc          6, 1
     109: goto          67
     112: iload_1
     113: aload_0
     114: aload         5
     116: invokevirtual #75                 // Method score:(Lday04/Card;)I
     119: iadd
     120: istore_1
     121: goto          17
     124: getstatic     #81                 // Field java/lang/System.out:Ljava/io/PrintStream;
     127: iload_1
     128: invokevirtual #86                 // Method java/io/PrintStream.println:(I)V
     131: return

  public abstract int score(day04.Card);

  private final java.util.List<day04.Card> parseInput();
    Code:
       0: new           #94                 // class java/util/ArrayList
       3: dup
       4: invokespecial #95                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #60                 // class java/util/List
      10: astore_1
      11: new           #97                 // class java/io/File
      14: dup
      15: aload_0
      16: getfield      #21                 // Field fileName:Ljava/lang/String;
      19: invokespecial #99                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      22: aconst_null
      23: iconst_1
      24: aconst_null
      25: invokestatic  #105                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      28: invokeinterface #106,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      33: astore_2
      34: aload_2
      35: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifeq          154
      43: aload_2
      44: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: checkcast     #108                // class java/lang/String
      52: astore_3
      53: aload_3
      54: checkcast     #110                // class java/lang/CharSequence
      57: iconst_2
      58: anewarray     #108                // class java/lang/String
      61: astore        5
      63: aload         5
      65: iconst_0
      66: ldc           #112                // String :
      68: aastore
      69: aload         5
      71: iconst_1
      72: ldc           #114                // String  |
      74: aastore
      75: aload         5
      77: iconst_0
      78: iconst_0
      79: bipush        6
      81: aconst_null
      82: invokestatic  #120                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      85: astore        4
      87: aload_1
      88: checkcast     #122                // class java/util/Collection
      91: new           #54                 // class day04/Card
      94: dup
      95: aload_0
      96: aload         4
      98: iconst_1
      99: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     104: checkcast     #108                // class java/lang/String
     107: invokespecial #126                // Method parseNumbers:(Ljava/lang/String;)Ljava/util/Set;
     110: checkcast     #38                 // class java/lang/Iterable
     113: aload_0
     114: aload         4
     116: iconst_2
     117: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     122: checkcast     #108                // class java/lang/String
     125: invokespecial #126                // Method parseNumbers:(Ljava/lang/String;)Ljava/util/Set;
     128: checkcast     #38                 // class java/lang/Iterable
     131: invokestatic  #132                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     134: invokeinterface #137,  1          // InterfaceMethod java/util/Set.size:()I
     139: iconst_0
     140: iconst_2
     141: aconst_null
     142: invokespecial #140                // Method day04/Card."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     145: invokeinterface #144,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     150: pop
     151: goto          34
     154: aload_1
     155: areturn

  private final java.util.Set<java.lang.String> parseNumbers(java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #110                // class java/lang/CharSequence
       4: invokestatic  #151                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
       7: invokevirtual #154                // Method java/lang/Object.toString:()Ljava/lang/String;
      10: checkcast     #110                // class java/lang/CharSequence
      13: astore_2
      14: new           #156                // class kotlin/text/Regex
      17: dup
      18: ldc           #158                // String  +
      20: invokespecial #159                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      23: astore_3
      24: iconst_0
      25: istore        4
      27: aload_3
      28: aload_2
      29: iload         4
      31: invokevirtual #163                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      34: checkcast     #38                 // class java/lang/Iterable
      37: invokestatic  #167                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
      40: areturn
}


package day03

import java.io.File

fun main() {
    run(::part1)
    run(::part2)
}

data class Number(val value: Int, val row: Int, val colStart: Int, var colEnd: Int)

fun run(part: (numbers: List<Number>, char: Char, row: Int, col: Int) -> Int) {
    val lines = File("input.data").readLines()
    val numbers = parseEngine(lines)
    var result = 0

    for ((row, line) in lines.withIndex()) {
        for ((col, char) in line.withIndex()) {
            result += part(numbers, char, row, col)
        }
    }
    println(result)
}

fun part1(numbers: List<Number>, char: Char, row: Int, col: Int): Int {
    var result = 0
    if (char != '.' && !char.isDigit()) {
        for (number in numbers) {
            if (adjacent(number, row, col)) {
                result += number.value
            }
        }
    }
    return result
}

fun part2(numbers: List<Number>, char: Char, row: Int, col: Int): Int {
    var result = 0
    if (char == '*') {
        val adjacentNumbers = mutableListOf<Number>()
        for (number in numbers) {
            if (adjacent(number, row, col)) adjacentNumbers += number
        }
        if (adjacentNumbers.size == 2) {
            result += adjacentNumbers[0].value * adjacentNumbers[1].value
        }
    }
    return result
}

fun parseEngine(lines: List<String>): List<Number> {
    val numbers = mutableListOf<Number>()
    for ((row, line) in lines.withIndex()) {
        var firstDigit = -1
        for ((col, char) in line.withIndex()) {
            if (char.isDigit()) {
                if (firstDigit == -1) {
                    firstDigit = col
                }
            } else {
                if (firstDigit != -1) {
                    val value = line.substring(firstDigit, col).toInt()
                    numbers += Number(value = value, row = row, colStart = firstDigit, colEnd = col)
                    firstDigit = -1
                }
            }
        }
        if (firstDigit != -1) {
            val value = line.substring(firstDigit, line.length).toInt()
            numbers += Number(value = value, row = row, colStart = firstDigit, colEnd = line.length)
        }
    }
    return numbers
}

fun adjacent(number: Number, row: Int, col: Int): Boolean =
    row in number.row - 1..number.row + 1 && col in number.colStart - 1..number.colEnd

// Part1:   527144
// Part2: 81463996

Compiled from "day03.kt"
public final class day03.Day03Kt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field day03/Day03Kt$main$1.INSTANCE:Lday03/Day03Kt$main$1;
       3: checkcast     #14                 // class kotlin/jvm/functions/Function4
       6: invokestatic  #18                 // Method run:(Lkotlin/jvm/functions/Function4;)V
       9: getstatic     #23                 // Field day03/Day03Kt$main$2.INSTANCE:Lday03/Day03Kt$main$2;
      12: checkcast     #14                 // class kotlin/jvm/functions/Function4
      15: invokestatic  #18                 // Method run:(Lkotlin/jvm/functions/Function4;)V
      18: return

  public static final void run(kotlin.jvm.functions.Function4<? super java.util.List<day03.Number>, ? super java.lang.Character, ? super java.lang.Integer, ? super java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #27                 // String part
       3: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #35                 // class java/io/File
       9: dup
      10: ldc           #37                 // String input.data
      12: invokespecial #41                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      15: aconst_null
      16: iconst_1
      17: aconst_null
      18: invokestatic  #47                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      21: astore_1
      22: aload_1
      23: invokestatic  #51                 // Method parseEngine:(Ljava/util/List;)Ljava/util/List;
      26: astore_2
      27: iconst_0
      28: istore_3
      29: aload_1
      30: checkcast     #53                 // class java/lang/Iterable
      33: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        4
      40: iconst_0
      41: istore        5
      43: aload         4
      45: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          142
      53: iload         5
      55: istore        6
      57: iload         5
      59: iconst_1
      60: iadd
      61: istore        5
      63: aload         4
      65: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: checkcast     #69                 // class java/lang/String
      73: astore        7
      75: iconst_0
      76: istore        8
      78: aload         7
      80: invokevirtual #73                 // Method java/lang/String.length:()I
      83: istore        9
      85: iload         8
      87: iload         9
      89: if_icmpge     43
      92: iload         8
      94: istore        10
      96: aload         7
      98: iload         8
     100: invokevirtual #77                 // Method java/lang/String.charAt:(I)C
     103: istore        11
     105: iload_3
     106: aload_0
     107: aload_2
     108: iload         11
     110: invokestatic  #83                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     113: iload         6
     115: invokestatic  #88                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     118: iload         10
     120: invokestatic  #88                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     123: invokeinterface #92,  5           // InterfaceMethod kotlin/jvm/functions/Function4.invoke:(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     128: checkcast     #94                 // class java/lang/Number
     131: invokevirtual #97                 // Method java/lang/Number.intValue:()I
     134: iadd
     135: istore_3
     136: iinc          8, 1
     139: goto          85
     142: getstatic     #103                // Field java/lang/System.out:Ljava/io/PrintStream;
     145: iload_3
     146: invokevirtual #109                // Method java/io/PrintStream.println:(I)V
     149: return

  public static final int part1(java.util.List<day03.Number>, char, int, int);
    Code:
       0: aload_0
       1: ldc           #127                // String numbers
       3: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore        4
       9: iload_1
      10: bipush        46
      12: if_icmpeq     75
      15: iload_1
      16: invokestatic  #131                // Method java/lang/Character.isDigit:(C)Z
      19: ifne          75
      22: aload_0
      23: invokeinterface #132,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      28: astore        5
      30: aload         5
      32: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      37: ifeq          75
      40: aload         5
      42: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      47: checkcast     #134                // class day03/Number
      50: astore        6
      52: aload         6
      54: iload_2
      55: iload_3
      56: invokestatic  #138                // Method adjacent:(Lday03/Number;II)Z
      59: ifeq          30
      62: iload         4
      64: aload         6
      66: invokevirtual #141                // Method day03/Number.getValue:()I
      69: iadd
      70: istore        4
      72: goto          30
      75: iload         4
      77: ireturn

  public static final int part2(java.util.List<day03.Number>, char, int, int);
    Code:
       0: aload_0
       1: ldc           #127                // String numbers
       3: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore        4
       9: iload_1
      10: bipush        42
      12: if_icmpne     128
      15: new           #146                // class java/util/ArrayList
      18: dup
      19: invokespecial #148                // Method java/util/ArrayList."<init>":()V
      22: checkcast     #123                // class java/util/List
      25: astore        5
      27: aload_0
      28: invokeinterface #132,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      33: astore        6
      35: aload         6
      37: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          83
      45: aload         6
      47: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: checkcast     #134                // class day03/Number
      55: astore        7
      57: aload         7
      59: iload_2
      60: iload_3
      61: invokestatic  #138                // Method adjacent:(Lday03/Number;II)Z
      64: ifeq          35
      67: aload         5
      69: checkcast     #150                // class java/util/Collection
      72: aload         7
      74: invokeinterface #154,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      79: pop
      80: goto          35
      83: aload         5
      85: invokeinterface #157,  1          // InterfaceMethod java/util/List.size:()I
      90: iconst_2
      91: if_icmpne     128
      94: iload         4
      96: aload         5
      98: iconst_0
      99: invokeinterface #161,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     104: checkcast     #134                // class day03/Number
     107: invokevirtual #141                // Method day03/Number.getValue:()I
     110: aload         5
     112: iconst_1
     113: invokeinterface #161,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     118: checkcast     #134                // class day03/Number
     121: invokevirtual #141                // Method day03/Number.getValue:()I
     124: imul
     125: iadd
     126: istore        4
     128: iload         4
     130: ireturn

  public static final java.util.List<day03.Number> parseEngine(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #164                // String lines
       3: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #146                // class java/util/ArrayList
       9: dup
      10: invokespecial #148                // Method java/util/ArrayList."<init>":()V
      13: checkcast     #123                // class java/util/List
      16: astore_1
      17: aload_0
      18: checkcast     #53                 // class java/lang/Iterable
      21: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      26: astore_2
      27: iconst_0
      28: istore_3
      29: aload_2
      30: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      35: ifeq          232
      38: iload_3
      39: istore        4
      41: iload_3
      42: iconst_1
      43: iadd
      44: istore_3
      45: aload_2
      46: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: checkcast     #69                 // class java/lang/String
      54: astore        5
      56: iconst_m1
      57: istore        6
      59: iconst_0
      60: istore        7
      62: aload         5
      64: invokevirtual #73                 // Method java/lang/String.length:()I
      67: istore        8
      69: iload         7
      71: iload         8
      73: if_icmpge     171
      76: iload         7
      78: istore        9
      80: aload         5
      82: iload         7
      84: invokevirtual #77                 // Method java/lang/String.charAt:(I)C
      87: istore        10
      89: iload         10
      91: invokestatic  #131                // Method java/lang/Character.isDigit:(C)Z
      94: ifeq          110
      97: iload         6
      99: iconst_m1
     100: if_icmpne     165
     103: iload         9
     105: istore        6
     107: goto          165
     110: iload         6
     112: iconst_m1
     113: if_icmpeq     165
     116: nop
     117: aload         5
     119: iload         6
     121: iload         9
     123: invokevirtual #168                // Method java/lang/String.substring:(II)Ljava/lang/String;
     126: dup
     127: ldc           #170                // String substring(...)
     129: invokestatic  #173                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     132: invokestatic  #177                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     135: istore        11
     137: aload_1
     138: checkcast     #150                // class java/util/Collection
     141: new           #134                // class day03/Number
     144: dup
     145: iload         11
     147: iload         4
     149: iload         6
     151: iload         9
     153: invokespecial #180                // Method day03/Number."<init>":(IIII)V
     156: invokeinterface #154,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     161: pop
     162: iconst_m1
     163: istore        6
     165: iinc          7, 1
     168: goto          69
     171: iload         6
     173: iconst_m1
     174: if_icmpeq     29
     177: nop
     178: aload         5
     180: iload         6
     182: aload         5
     184: invokevirtual #73                 // Method java/lang/String.length:()I
     187: invokevirtual #168                // Method java/lang/String.substring:(II)Ljava/lang/String;
     190: dup
     191: ldc           #170                // String substring(...)
     193: invokestatic  #173                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     196: invokestatic  #177                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     199: istore        7
     201: aload_1
     202: checkcast     #150                // class java/util/Collection
     205: new           #134                // class day03/Number
     208: dup
     209: iload         7
     211: iload         4
     213: iload         6
     215: aload         5
     217: invokevirtual #73                 // Method java/lang/String.length:()I
     220: invokespecial #180                // Method day03/Number."<init>":(IIII)V
     223: invokeinterface #154,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     228: pop
     229: goto          29
     232: aload_1
     233: areturn

  public static final boolean adjacent(day03.Number, int, int);
    Code:
       0: aload_0
       1: ldc           #183                // String number
       3: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #186                // Method day03/Number.getRow:()I
      10: iconst_1
      11: isub
      12: istore_3
      13: iload_1
      14: aload_0
      15: invokevirtual #186                // Method day03/Number.getRow:()I
      18: iconst_1
      19: iadd
      20: if_icmpgt     36
      23: iload_3
      24: iload_1
      25: if_icmpgt     32
      28: iconst_1
      29: goto          37
      32: iconst_0
      33: goto          37
      36: iconst_0
      37: ifeq          76
      40: aload_0
      41: invokevirtual #189                // Method day03/Number.getColStart:()I
      44: iconst_1
      45: isub
      46: istore_3
      47: iload_2
      48: aload_0
      49: invokevirtual #192                // Method day03/Number.getColEnd:()I
      52: if_icmpgt     68
      55: iload_3
      56: iload_2
      57: if_icmpgt     64
      60: iconst_1
      61: goto          69
      64: iconst_0
      65: goto          69
      68: iconst_0
      69: ifeq          76
      72: iconst_1
      73: goto          77
      76: iconst_0
      77: ireturn

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

Compiled from "day03.kt"
final class day03.Day03Kt$main$2 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function4<java.util.List<? extends day03.Number>, java.lang.Character, java.lang.Integer, java.lang.Integer, java.lang.Integer> {
  public static final day03.Day03Kt$main$2 INSTANCE;

  day03.Day03Kt$main$2();
    Code:
       0: aload_0
       1: iconst_4
       2: ldc           #11                 // class day03/Day03Kt
       4: ldc           #13                 // String part2
       6: ldc           #15                 // String part2(Ljava/util/List;CII)I
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Integer invoke(java.util.List<day03.Number>, char, int, int);
    Code:
       0: aload_1
       1: ldc           #25                 // String p0
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: iload_2
       8: iload_3
       9: iload         4
      11: invokestatic  #34                 // Method day03/Day03Kt.part2:(Ljava/util/List;CII)I
      14: invokestatic  #40                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #49                 // class java/util/List
       5: aload_2
       6: checkcast     #51                 // class java/lang/Character
       9: invokevirtual #55                 // Method java/lang/Character.charValue:()C
      12: aload_3
      13: checkcast     #57                 // class java/lang/Number
      16: invokevirtual #61                 // Method java/lang/Number.intValue:()I
      19: aload         4
      21: checkcast     #57                 // class java/lang/Number
      24: invokevirtual #61                 // Method java/lang/Number.intValue:()I
      27: invokevirtual #63                 // Method invoke:(Ljava/util/List;CII)Ljava/lang/Integer;
      30: areturn

  static {};
    Code:
       0: new           #2                  // class day03/Day03Kt$main$2
       3: dup
       4: invokespecial #68                 // Method "<init>":()V
       7: putstatic     #71                 // Field INSTANCE:Lday03/Day03Kt$main$2;
      10: return
}

Compiled from "day03.kt"
final class day03.Day03Kt$main$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function4<java.util.List<? extends day03.Number>, java.lang.Character, java.lang.Integer, java.lang.Integer, java.lang.Integer> {
  public static final day03.Day03Kt$main$1 INSTANCE;

  day03.Day03Kt$main$1();
    Code:
       0: aload_0
       1: iconst_4
       2: ldc           #11                 // class day03/Day03Kt
       4: ldc           #13                 // String part1
       6: ldc           #15                 // String part1(Ljava/util/List;CII)I
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Integer invoke(java.util.List<day03.Number>, char, int, int);
    Code:
       0: aload_1
       1: ldc           #25                 // String p0
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: iload_2
       8: iload_3
       9: iload         4
      11: invokestatic  #34                 // Method day03/Day03Kt.part1:(Ljava/util/List;CII)I
      14: invokestatic  #40                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #49                 // class java/util/List
       5: aload_2
       6: checkcast     #51                 // class java/lang/Character
       9: invokevirtual #55                 // Method java/lang/Character.charValue:()C
      12: aload_3
      13: checkcast     #57                 // class java/lang/Number
      16: invokevirtual #61                 // Method java/lang/Number.intValue:()I
      19: aload         4
      21: checkcast     #57                 // class java/lang/Number
      24: invokevirtual #61                 // Method java/lang/Number.intValue:()I
      27: invokevirtual #63                 // Method invoke:(Ljava/util/List;CII)Ljava/lang/Integer;
      30: areturn

  static {};
    Code:
       0: new           #2                  // class day03/Day03Kt$main$1
       3: dup
       4: invokespecial #68                 // Method "<init>":()V
       7: putstatic     #71                 // Field INSTANCE:Lday03/Day03Kt$main$1;
      10: return
}


package day03_oop

import java.io.File

fun main() {
    Part1("input.data").run()
    Part2("input.data").run()
}

data class Number(val value: Int, val row: Int, val colStart: Int, var colEnd: Int)

abstract class Day03(fileName: String) {
    private val lines = File(fileName).readLines()
    val numbers = parseEngine()

    abstract fun score(char: Char, row: Int, col: Int): Int

    fun run() {
        var result = 0

        for ((row, line) in lines.withIndex()) {
            for ((col, char) in line.withIndex()) {
                result += score(char, row, col)
            }
        }
        println(result)
    }

    private fun parseEngine(): List<Number> {
        val numbers = mutableListOf<Number>()
        for ((row, line) in lines.withIndex()) {
            var firstDigit = -1
            for ((col, char) in line.withIndex()) {
                if (char.isDigit()) {
                    if (firstDigit == -1) {
                        firstDigit = col
                    }
                } else {
                    if (firstDigit != -1) {
                        val value = line.substring(firstDigit, col).toInt()
                        numbers += Number(value = value, row = row, colStart = firstDigit, colEnd = col)
                        firstDigit = -1
                    }
                }
            }
            if (firstDigit != -1) {
                val value = line.substring(firstDigit, line.length).toInt()
                numbers += Number(value = value, row = row, colStart = firstDigit, colEnd = line.length)
            }
        }
        return numbers
    }

    fun adjacent(number: Number, row: Int, col: Int): Boolean =
            row in number.row - 1..number.row + 1 && col in number.colStart - 1..number.colEnd
}

class Part1(fileName: String) : Day03(fileName) {
    override fun score(char: Char, row: Int, col: Int): Int {
        var result = 0
        if (char != '.' && !char.isDigit()) {
            for (number in numbers) {
                if (adjacent(number, row, col)) {
                    result += number.value
                }
            }
        }
        return result
    }
}

class Part2(fileName: String) : Day03(fileName) {
    override fun score(char: Char, row: Int, col: Int): Int {
        var result = 0
        if (char == '*') {
            val adjacentNumbers = mutableListOf<Number>()
            for (number in numbers) {
                if (adjacent(number, row, col)) adjacentNumbers += number
            }
            if (adjacentNumbers.size == 2) {
                result += adjacentNumbers[0].value * adjacentNumbers[1].value
            }
        }
        return result
    }
}

Compiled from "day03_oop.kt"
public final class day03_oop.Day03_oopKt {
  public static final void main();
    Code:
       0: new           #8                  // class day03_oop/Part1
       3: dup
       4: ldc           #10                 // String input.data
       6: invokespecial #14                 // Method day03_oop/Part1."<init>":(Ljava/lang/String;)V
       9: invokevirtual #17                 // Method day03_oop/Part1.run:()V
      12: new           #19                 // class day03_oop/Part2
      15: dup
      16: ldc           #10                 // String input.data
      18: invokespecial #20                 // Method day03_oop/Part2."<init>":(Ljava/lang/String;)V
      21: invokevirtual #21                 // Method day03_oop/Part2.run:()V
      24: return

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


package day02

import java.io.File
import kotlin.math.max

data class Game(val id: Int, val colors: Colors)
data class Colors(val red: Int, val green: Int, val blue: Int)

fun main() {
    println(run(::part1))
    println(run(::part2))
}

fun run(score: (Game) -> Int): Int = File("input.data").readLines().sumOf { score(parseGame(it)) }

fun parseGame(line: String): Game {
    val (gameIdStr, gameDataStr) = line.split(": ")
    val gameId = gameIdStr.split(" ")[1].toInt()
    return Game(id = gameId, colors = parseColors(gameDataStr))
}

fun parseColors(gameDataStr: String): Colors {
    var red = 0
    var green = 0
    var blue = 0
    for (setStr in gameDataStr.split("; ")) {
        val colorsStr = setStr.split(", ")
        for (colorStr in colorsStr) {
            val (cubesStr, color) = colorStr.split(" ")
            val cubes = cubesStr.toInt()
            when (color) {
                "red" -> red = max(red, cubes)
                "green" -> green = max(green, cubes)
                "blue" -> blue = max(blue, cubes)
            }
        }
    }
    return Colors(red = red, green = green, blue = blue)
}

fun part1(game: Game): Int {
    val colors = game.colors
    if (colors.red <= 12 && colors.green <= 13 && colors.blue <= 14) return game.id
    return 0
}

fun part2(game: Game): Int {
    return game.colors.red * game.colors.green * game.colors.blue
}

Compiled from "day02.kt"
public final class day02.Day02Kt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field day02/Day02Kt$main$1.INSTANCE:Lday02/Day02Kt$main$1;
       3: checkcast     #14                 // class kotlin/jvm/functions/Function1
       6: invokestatic  #18                 // Method run:(Lkotlin/jvm/functions/Function1;)I
       9: istore_0
      10: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      13: iload_0
      14: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      17: getstatic     #35                 // Field day02/Day02Kt$main$2.INSTANCE:Lday02/Day02Kt$main$2;
      20: checkcast     #14                 // class kotlin/jvm/functions/Function1
      23: invokestatic  #18                 // Method run:(Lkotlin/jvm/functions/Function1;)I
      26: istore_0
      27: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      30: iload_0
      31: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      34: return

  public static final int run(kotlin.jvm.functions.Function1<? super day02.Game, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #39                 // String score
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #47                 // class java/io/File
       9: dup
      10: ldc           #49                 // String input.data
      12: invokespecial #53                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      15: aconst_null
      16: iconst_1
      17: aconst_null
      18: invokestatic  #59                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      21: checkcast     #61                 // class java/lang/Iterable
      24: astore_1
      25: iconst_0
      26: istore_2
      27: aload_1
      28: invokeinterface #65,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore_3
      34: aload_3
      35: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifeq          92
      43: aload_3
      44: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        4
      51: iload_2
      52: aload         4
      54: checkcast     #77                 // class java/lang/String
      57: astore        5
      59: istore        7
      61: iconst_0
      62: istore        6
      64: aload_0
      65: aload         5
      67: invokestatic  #81                 // Method parseGame:(Ljava/lang/String;)Lday02/Game;
      70: invokeinterface #85,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      75: checkcast     #87                 // class java/lang/Number
      78: invokevirtual #91                 // Method java/lang/Number.intValue:()I
      81: istore        8
      83: iload         7
      85: iload         8
      87: iadd
      88: istore_2
      89: goto          34
      92: iload_2
      93: ireturn

  public static final day02.Game parseGame(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #98                 // String line
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #100                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #77                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #102                // String :
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #108                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_1
      30: aload_1
      31: iconst_0
      32: invokeinterface #114,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      37: checkcast     #77                 // class java/lang/String
      40: astore_2
      41: aload_1
      42: iconst_1
      43: invokeinterface #114,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      48: checkcast     #77                 // class java/lang/String
      51: astore_3
      52: aload_2
      53: checkcast     #100                // class java/lang/CharSequence
      56: iconst_1
      57: anewarray     #77                 // class java/lang/String
      60: astore        5
      62: aload         5
      64: iconst_0
      65: ldc           #116                // String
      67: aastore
      68: aload         5
      70: iconst_0
      71: iconst_0
      72: bipush        6
      74: aconst_null
      75: invokestatic  #108                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      78: iconst_1
      79: invokeinterface #114,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      84: checkcast     #77                 // class java/lang/String
      87: invokestatic  #122                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      90: istore        4
      92: new           #124                // class day02/Game
      95: dup
      96: iload         4
      98: aload_3
      99: invokestatic  #128                // Method parseColors:(Ljava/lang/String;)Lday02/Colors;
     102: invokespecial #131                // Method day02/Game."<init>":(ILday02/Colors;)V
     105: areturn

  public static final day02.Colors parseColors(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #135                // String gameDataStr
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: iconst_0
       9: istore_2
      10: iconst_0
      11: istore_3
      12: aload_0
      13: checkcast     #100                // class java/lang/CharSequence
      16: iconst_1
      17: anewarray     #77                 // class java/lang/String
      20: astore        5
      22: aload         5
      24: iconst_0
      25: ldc           #137                // String ;
      27: aastore
      28: aload         5
      30: iconst_0
      31: iconst_0
      32: bipush        6
      34: aconst_null
      35: invokestatic  #108                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      38: invokeinterface #138,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      43: astore        4
      45: aload         4
      47: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          301
      55: aload         4
      57: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: checkcast     #77                 // class java/lang/String
      65: astore        5
      67: aload         5
      69: checkcast     #100                // class java/lang/CharSequence
      72: iconst_1
      73: anewarray     #77                 // class java/lang/String
      76: astore        7
      78: aload         7
      80: iconst_0
      81: ldc           #140                // String ,
      83: aastore
      84: aload         7
      86: iconst_0
      87: iconst_0
      88: bipush        6
      90: aconst_null
      91: invokestatic  #108                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      94: astore        6
      96: aload         6
      98: invokeinterface #138,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     103: astore        7
     105: aload         7
     107: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     112: ifeq          45
     115: aload         7
     117: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     122: checkcast     #77                 // class java/lang/String
     125: astore        8
     127: aload         8
     129: checkcast     #100                // class java/lang/CharSequence
     132: iconst_1
     133: anewarray     #77                 // class java/lang/String
     136: astore        10
     138: aload         10
     140: iconst_0
     141: ldc           #116                // String
     143: aastore
     144: aload         10
     146: iconst_0
     147: iconst_0
     148: bipush        6
     150: aconst_null
     151: invokestatic  #108                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     154: astore        9
     156: aload         9
     158: iconst_0
     159: invokeinterface #114,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     164: checkcast     #77                 // class java/lang/String
     167: astore        10
     169: aload         9
     171: iconst_1
     172: invokeinterface #114,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     177: checkcast     #77                 // class java/lang/String
     180: astore        11
     182: aload         10
     184: invokestatic  #122                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     187: istore        12
     189: aload         11
     191: astore        13
     193: aload         13
     195: invokevirtual #143                // Method java/lang/String.hashCode:()I
     198: lookupswitch  { // 3
                112785: 232
               3027034: 258
              98619139: 245
               default: 298
          }
     232: aload         13
     234: ldc           #145                // String red
     236: invokevirtual #149                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     239: ifne          271
     242: goto          105
     245: aload         13
     247: ldc           #151                // String green
     249: invokevirtual #149                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     252: ifne          281
     255: goto          105
     258: aload         13
     260: ldc           #153                // String blue
     262: invokevirtual #149                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     265: ifne          291
     268: goto          105
     271: iload_1
     272: iload         12
     274: invokestatic  #159                // Method java/lang/Math.max:(II)I
     277: istore_1
     278: goto          105
     281: iload_2
     282: iload         12
     284: invokestatic  #159                // Method java/lang/Math.max:(II)I
     287: istore_2
     288: goto          105
     291: iload_3
     292: iload         12
     294: invokestatic  #159                // Method java/lang/Math.max:(II)I
     297: istore_3
     298: goto          105
     301: new           #161                // class day02/Colors
     304: dup
     305: iload_1
     306: iload_2
     307: iload_3
     308: invokespecial #164                // Method day02/Colors."<init>":(III)V
     311: areturn

  public static final int part1(day02.Game);
    Code:
       0: aload_0
       1: ldc           #175                // String game
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #179                // Method day02/Game.getColors:()Lday02/Colors;
      10: astore_1
      11: aload_1
      12: invokevirtual #182                // Method day02/Colors.getRed:()I
      15: bipush        12
      17: if_icmpgt     43
      20: aload_1
      21: invokevirtual #185                // Method day02/Colors.getGreen:()I
      24: bipush        13
      26: if_icmpgt     43
      29: aload_1
      30: invokevirtual #188                // Method day02/Colors.getBlue:()I
      33: bipush        14
      35: if_icmpgt     43
      38: aload_0
      39: invokevirtual #191                // Method day02/Game.getId:()I
      42: ireturn
      43: iconst_0
      44: ireturn

  public static final int part2(day02.Game);
    Code:
       0: aload_0
       1: ldc           #175                // String game
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #179                // Method day02/Game.getColors:()Lday02/Colors;
      10: invokevirtual #182                // Method day02/Colors.getRed:()I
      13: aload_0
      14: invokevirtual #179                // Method day02/Game.getColors:()Lday02/Colors;
      17: invokevirtual #185                // Method day02/Colors.getGreen:()I
      20: imul
      21: aload_0
      22: invokevirtual #179                // Method day02/Game.getColors:()Lday02/Colors;
      25: invokevirtual #188                // Method day02/Colors.getBlue:()I
      28: imul
      29: ireturn

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

Compiled from "day02.kt"
final class day02.Day02Kt$main$2 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<day02.Game, java.lang.Integer> {
  public static final day02.Day02Kt$main$2 INSTANCE;

  day02.Day02Kt$main$2();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day02/Day02Kt
       4: ldc           #13                 // String part2
       6: ldc           #15                 // String part2(Lday02/Game;)I
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Integer invoke(day02.Game);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day02/Day02Kt.part2:(Lday02/Game;)I
      10: invokestatic  #39                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #43                 // class day02/Game
       5: invokevirtual #45                 // Method invoke:(Lday02/Game;)Ljava/lang/Integer;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day02/Day02Kt$main$2
       3: dup
       4: invokespecial #50                 // Method "<init>":()V
       7: putstatic     #53                 // Field INSTANCE:Lday02/Day02Kt$main$2;
      10: return
}

Compiled from "day02.kt"
final class day02.Day02Kt$main$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<day02.Game, java.lang.Integer> {
  public static final day02.Day02Kt$main$1 INSTANCE;

  day02.Day02Kt$main$1();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class day02/Day02Kt
       4: ldc           #13                 // String part1
       6: ldc           #15                 // String part1(Lday02/Game;)I
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Integer invoke(day02.Game);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method day02/Day02Kt.part1:(Lday02/Game;)I
      10: invokestatic  #39                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #43                 // class day02/Game
       5: invokevirtual #45                 // Method invoke:(Lday02/Game;)Ljava/lang/Integer;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class day02/Day02Kt$main$1
       3: dup
       4: invokespecial #50                 // Method "<init>":()V
       7: putstatic     #53                 // Field INSTANCE:Lday02/Day02Kt$main$1;
      10: return
}