import java.io.File

fun waitForIt(in1: Int): Long {

	val pattern = """(\d)+""".toRegex()
	var lines = File("day2306_puzzle_input.txt").readLines()

	var line0 = pattern.findAll(lines[0]).map { it.value }.toList()
	var line1 = pattern.findAll(lines[1]).map { it.value }.toList()

	var time = mutableListOf<Pair<Long, Long>>()

	if (in1 == 1) {
		for (i in 0..line0.size - 1) {
			time.add(Pair(line0[i].toLong(), line1[i].toLong()))
		}
	} else {
		time.add(Pair(line0.joinToString("").toLong(), line1.joinToString("").toLong()))
	}

	var result = 1L
	time.forEach {
		var wins = 0L
		for (i in 0..it.first) {
			var dist = i * (it.first - i)
			if (dist > it.second) {
				wins += 1L
			}
		}
		result *= wins
	}
	return result
}

fun main() {
	var t1 = System.currentTimeMillis()

	var solution1 = waitForIt(1)
	var solution2 = waitForIt(2)

// print solution for part 1
	println("*******************************")
	println("--- Day 6: Wait For It ---")
	println("*******************************")
	println("Solution for part1")
	println("   $solution1 do you get if you multiply these numbers together")
	println()
// print solution for part 2
	println("*******************************")
	println("Solution for part2")
	println("   $solution2 many ways can you beat the record in this one much longer race")
	println()

	t1 = System.currentTimeMillis() - t1
	println("puzzle solved in ${t1} ms")
}

Compiled from "day2306_1_2.kt"
public final class Day2306_1_2Kt {
  public static final long waitForIt(int);
    Code:
       0: new           #8                  // class kotlin/text/Regex
       3: dup
       4: ldc           #10                 // String (\\d)+
       6: invokespecial #14                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: astore_1
      10: new           #16                 // class java/io/File
      13: dup
      14: ldc           #18                 // String day2306_puzzle_input.txt
      16: invokespecial #19                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      19: aconst_null
      20: iconst_1
      21: aconst_null
      22: invokestatic  #25                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      25: astore_2
      26: aload_1
      27: aload_2
      28: iconst_0
      29: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      34: checkcast     #33                 // class java/lang/CharSequence
      37: iconst_0
      38: iconst_2
      39: aconst_null
      40: invokestatic  #37                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      43: invokedynamic #56,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      48: invokestatic  #62                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      51: invokestatic  #66                 // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      54: astore_3
      55: aload_1
      56: aload_2
      57: iconst_1
      58: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      63: checkcast     #33                 // class java/lang/CharSequence
      66: iconst_0
      67: iconst_2
      68: aconst_null
      69: invokestatic  #37                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      72: invokedynamic #71,  0             // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      77: invokestatic  #62                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      80: invokestatic  #66                 // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      83: astore        4
      85: new           #73                 // class java/util/ArrayList
      88: dup
      89: invokespecial #76                 // Method java/util/ArrayList."<init>":()V
      92: checkcast     #27                 // class java/util/List
      95: astore        5
      97: iload_0
      98: iconst_1
      99: if_icmpne     176
     102: iconst_0
     103: istore        6
     105: aload_3
     106: invokeinterface #80,  1           // InterfaceMethod java/util/List.size:()I
     111: istore        7
     113: iload         6
     115: iload         7
     117: if_icmpge     244
     120: aload         5
     122: new           #82                 // class kotlin/Pair
     125: dup
     126: aload_3
     127: iload         6
     129: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #84                 // class java/lang/String
     137: invokestatic  #90                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     140: invokestatic  #94                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     143: aload         4
     145: iload         6
     147: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     152: checkcast     #84                 // class java/lang/String
     155: invokestatic  #90                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     158: invokestatic  #94                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     161: invokespecial #97                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     164: invokeinterface #101,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     169: pop
     170: iinc          6, 1
     173: goto          113
     176: aload         5
     178: new           #82                 // class kotlin/Pair
     181: dup
     182: aload_3
     183: checkcast     #103                // class java/lang/Iterable
     186: ldc           #105                // String
     188: checkcast     #33                 // class java/lang/CharSequence
     191: aconst_null
     192: aconst_null
     193: iconst_0
     194: aconst_null
     195: aconst_null
     196: bipush        62
     198: aconst_null
     199: invokestatic  #111                // 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;
     202: invokestatic  #90                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     205: invokestatic  #94                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     208: aload         4
     210: checkcast     #103                // class java/lang/Iterable
     213: ldc           #105                // String
     215: checkcast     #33                 // class java/lang/CharSequence
     218: aconst_null
     219: aconst_null
     220: iconst_0
     221: aconst_null
     222: aconst_null
     223: bipush        62
     225: aconst_null
     226: invokestatic  #111                // 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;
     229: invokestatic  #90                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     232: invokestatic  #94                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     235: invokespecial #97                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     238: invokeinterface #101,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     243: pop
     244: lconst_0
     245: lstore        21
     247: lconst_1
     248: lstore        21
     250: aload         5
     252: checkcast     #103                // class java/lang/Iterable
     255: astore        7
     257: iconst_0
     258: istore        8
     260: aload         7
     262: invokeinterface #115,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     267: astore        9
     269: aload         9
     271: invokeinterface #121,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     276: ifeq          396
     279: aload         9
     281: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     286: astore        10
     288: aload         10
     290: checkcast     #82                 // class kotlin/Pair
     293: astore        11
     295: iconst_0
     296: istore        12
     298: lconst_0
     299: lstore        13
     301: lconst_0
     302: lstore        15
     304: aload         11
     306: invokevirtual #128                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     309: checkcast     #130                // class java/lang/Number
     312: invokevirtual #134                // Method java/lang/Number.longValue:()J
     315: lstore        17
     317: lload         15
     319: lload         17
     321: lcmp
     322: ifgt          384
     325: lload         15
     327: aload         11
     329: invokevirtual #128                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     332: checkcast     #130                // class java/lang/Number
     335: invokevirtual #134                // Method java/lang/Number.longValue:()J
     338: lload         15
     340: lsub
     341: lmul
     342: lstore        19
     344: lload         19
     346: aload         11
     348: invokevirtual #137                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     351: checkcast     #130                // class java/lang/Number
     354: invokevirtual #134                // Method java/lang/Number.longValue:()J
     357: lcmp
     358: ifle          367
     361: lload         13
     363: lconst_1
     364: ladd
     365: lstore        13
     367: lload         15
     369: lload         17
     371: lcmp
     372: ifeq          384
     375: lload         15
     377: lconst_1
     378: ladd
     379: lstore        15
     381: goto          325
     384: lload         21
     386: lload         13
     388: lmul
     389: lstore        21
     391: nop
     392: nop
     393: goto          269
     396: nop
     397: lload         21
     399: lreturn

  public static final void main();
    Code:
       0: invokestatic  #165                // Method java/lang/System.currentTimeMillis:()J
       3: lstore_0
       4: iconst_1
       5: invokestatic  #167                // Method waitForIt:(I)J
       8: lstore_2
       9: iconst_2
      10: invokestatic  #167                // Method waitForIt:(I)J
      13: lstore        4
      15: ldc           #169                // String *******************************
      17: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
      20: swap
      21: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      24: ldc           #181                // String --- Day 6: Wait For It ---
      26: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
      29: swap
      30: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      33: ldc           #169                // String *******************************
      35: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
      38: swap
      39: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      42: ldc           #183                // String Solution for part1
      44: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
      47: swap
      48: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      51: new           #185                // class java/lang/StringBuilder
      54: dup
      55: invokespecial #186                // Method java/lang/StringBuilder."<init>":()V
      58: ldc           #188                // String
      60: invokevirtual #192                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      63: lload_2
      64: invokevirtual #195                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      67: ldc           #197                // String  do you get if you multiply these numbers together
      69: invokevirtual #192                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      72: invokevirtual #201                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      75: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
      78: swap
      79: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      82: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
      85: invokevirtual #203                // Method java/io/PrintStream.println:()V
      88: ldc           #169                // String *******************************
      90: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
      93: swap
      94: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      97: ldc           #205                // String Solution for part2
      99: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
     102: swap
     103: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     106: new           #185                // class java/lang/StringBuilder
     109: dup
     110: invokespecial #186                // Method java/lang/StringBuilder."<init>":()V
     113: ldc           #188                // String
     115: invokevirtual #192                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     118: lload         4
     120: invokevirtual #195                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     123: ldc           #207                // String  many ways can you beat the record in this one much longer race
     125: invokevirtual #192                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     128: invokevirtual #201                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     131: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
     134: swap
     135: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     138: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
     141: invokevirtual #203                // Method java/io/PrintStream.println:()V
     144: invokestatic  #165                // Method java/lang/System.currentTimeMillis:()J
     147: lload_0
     148: lsub
     149: lstore_0
     150: new           #185                // class java/lang/StringBuilder
     153: dup
     154: invokespecial #186                // Method java/lang/StringBuilder."<init>":()V
     157: ldc           #209                // String puzzle solved in
     159: invokevirtual #192                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     162: lload_0
     163: invokevirtual #195                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     166: ldc           #211                // String  ms
     168: invokevirtual #192                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     171: invokevirtual #201                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     174: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
     177: swap
     178: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     181: return

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

  private static final java.lang.String waitForIt$lambda$0(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc           #220                // String it
       3: invokestatic  #226                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #231,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      12: areturn

  private static final java.lang.String waitForIt$lambda$1(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc           #220                // String it
       3: invokestatic  #226                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #231,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      12: areturn
}


import java.io.File
import kotlin.math.*

fun gearRatio(): Int {
	var result = 0
	val patternSymbol = """\W""".toRegex()
	val patternPartNumber = """(\d)+""".toRegex()
	var y = 0

	File("day2303_puzzle_input.txt").forEachLine {
		var matchSymbol = patternSymbol.findAll(it.replace(".", "a"))
		matchSymbol.forEach {
			var x = it.range.first
			//println("${it.value}: $y $x")
			var yPartNumber = 0
			File("day2303_puzzle_input.txt").forEachLine {
				var matchPartNumber = patternPartNumber.findAll(it)
				matchPartNumber.forEach {
					//println("   ${it.value.toInt()}: $yPartNumber, ${it.range}")
					var rangeCheck = IntRange(it.range.first-1, it.range.last + 1)
					if (abs(y - yPartNumber) < 2 && rangeCheck.contains(x)) {
						//println("  ->  ok")
						// if there are more than one symbols adjacent to a number, this has to be reworked.
						// (swich order, look for partNumber and check for adjacent symbols, break after
						// first symbol is found.)
						result += it.value.toInt()
					}
				}
				yPartNumber += 1
			}
		}
		y += 1
	}
	return result
}

fun gearRatioPart2(): Int {
	var result = 0
	val patternSymbol = """\*""".toRegex()
	val patternPartNumber = """(\d)+""".toRegex()
	var y = 0

	File("day2303_puzzle_input.txt").forEachLine {
		var matchSymbol = patternSymbol.findAll(it)
		matchSymbol.forEach {
			var gearRatio = 1
			var gearCount = 0
			var x = it.range.first
			var yPartNumber = 0
			File("day2303_puzzle_input.txt").forEachLine {
				var matchPartNumber = patternPartNumber.findAll(it)
				matchPartNumber.forEach {
					var rangeCheck = IntRange(it.range.first-1, it.range.last + 1)
					if (abs(y - yPartNumber) < 2 && rangeCheck.contains(x)) {
						gearRatio *= it.value.toInt()
						gearCount += 1
					}
				}
				yPartNumber += 1
			}
			if (gearCount == 2) result += gearRatio
		}
		y += 1
	}
	return result
}

fun main() {
	var t1 = System.currentTimeMillis()

	var solution1 = gearRatio()
	var solution2 = gearRatioPart2()

// print solution for part 1
	println("*******************************")
	println("--- Day 3: Gear Ratios ---")
	println("*******************************")
	println("Solution for part1")
	println("   $solution1 is the sum of all of the part numbers in the engine schematic")
	println()
// print solution for part 2
	println("*******************************")
	println("Solution for part2")
	println("   $solution2 is the sum of all of the gear ratios in your engine schematic")
	println()

	t1 = System.currentTimeMillis() - t1
	println("puzzle solved in ${t1} ms")
}

Compiled from "day2303_1_2.kt"
public final class Day2303_1_2Kt {
  public static final int gearRatio();
    Code:
       0: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
       3: dup
       4: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
       7: astore_0
       8: new           #14                 // class kotlin/text/Regex
      11: dup
      12: ldc           #16                 // String \\W
      14: invokespecial #19                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      17: astore_1
      18: new           #14                 // class kotlin/text/Regex
      21: dup
      22: ldc           #21                 // String (\\d)+
      24: invokespecial #19                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      27: astore_2
      28: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
      31: dup
      32: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      35: astore_3
      36: new           #23                 // class java/io/File
      39: dup
      40: ldc           #25                 // String day2303_puzzle_input.txt
      42: invokespecial #26                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      45: aconst_null
      46: aload_1
      47: aload_3
      48: aload_2
      49: aload_0
      50: invokedynamic #46,  0             // InvokeDynamic #0:invoke:(Lkotlin/text/Regex;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/text/Regex;Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function1;
      55: iconst_1
      56: aconst_null
      57: invokestatic  #52                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      60: aload_0
      61: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      64: ireturn

  public static final int gearRatioPart2();
    Code:
       0: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
       3: dup
       4: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
       7: astore_0
       8: new           #14                 // class kotlin/text/Regex
      11: dup
      12: ldc           #65                 // String \\*
      14: invokespecial #19                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      17: astore_1
      18: new           #14                 // class kotlin/text/Regex
      21: dup
      22: ldc           #21                 // String (\\d)+
      24: invokespecial #19                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      27: astore_2
      28: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
      31: dup
      32: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      35: astore_3
      36: new           #23                 // class java/io/File
      39: dup
      40: ldc           #25                 // String day2303_puzzle_input.txt
      42: invokespecial #26                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      45: aconst_null
      46: aload_1
      47: aload_3
      48: aload_0
      49: aload_2
      50: invokedynamic #73,  0             // InvokeDynamic #1:invoke:(Lkotlin/text/Regex;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/text/Regex;)Lkotlin/jvm/functions/Function1;
      55: iconst_1
      56: aconst_null
      57: invokestatic  #52                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      60: aload_0
      61: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      64: ireturn

  public static final void main();
    Code:
       0: invokestatic  #80                 // Method java/lang/System.currentTimeMillis:()J
       3: lstore_0
       4: invokestatic  #82                 // Method gearRatio:()I
       7: istore_2
       8: invokestatic  #84                 // Method gearRatioPart2:()I
      11: istore_3
      12: ldc           #86                 // String *******************************
      14: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
      17: swap
      18: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      21: ldc           #98                 // String --- Day 3: Gear Ratios ---
      23: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: swap
      27: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: ldc           #86                 // String *******************************
      32: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
      35: swap
      36: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      39: ldc           #100                // String Solution for part1
      41: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
      44: swap
      45: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      48: new           #102                // class java/lang/StringBuilder
      51: dup
      52: invokespecial #103                // Method java/lang/StringBuilder."<init>":()V
      55: ldc           #105                // String
      57: invokevirtual #109                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      60: iload_2
      61: invokevirtual #112                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      64: ldc           #114                // String  is the sum of all of the part numbers in the engine schematic
      66: invokevirtual #109                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      69: invokevirtual #118                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      72: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
      75: swap
      76: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      79: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
      82: invokevirtual #120                // Method java/io/PrintStream.println:()V
      85: ldc           #86                 // String *******************************
      87: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
      90: swap
      91: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      94: ldc           #122                // String Solution for part2
      96: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
      99: swap
     100: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: new           #102                // class java/lang/StringBuilder
     106: dup
     107: invokespecial #103                // Method java/lang/StringBuilder."<init>":()V
     110: ldc           #105                // String
     112: invokevirtual #109                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     115: iload_3
     116: invokevirtual #112                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     119: ldc           #124                // String  is the sum of all of the gear ratios in your engine schematic
     121: invokevirtual #109                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     124: invokevirtual #118                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     127: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     130: swap
     131: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     134: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     137: invokevirtual #120                // Method java/io/PrintStream.println:()V
     140: invokestatic  #80                 // Method java/lang/System.currentTimeMillis:()J
     143: lload_0
     144: lsub
     145: lstore_0
     146: new           #102                // class java/lang/StringBuilder
     149: dup
     150: invokespecial #103                // Method java/lang/StringBuilder."<init>":()V
     153: ldc           #126                // String puzzle solved in
     155: invokevirtual #109                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     158: lload_0
     159: invokevirtual #129                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     162: ldc           #131                // String  ms
     164: invokevirtual #109                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     167: invokevirtual #118                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     170: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     173: swap
     174: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     177: return

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

  private static final kotlin.Unit gearRatio$lambda$3$lambda$2$lambda$1(kotlin.text.Regex, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, java.lang.String);
    Code:
       0: aload         5
       2: ldc           #144                // String it
       4: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload         5
      10: checkcast     #152                // class java/lang/CharSequence
      13: iconst_0
      14: iconst_2
      15: aconst_null
      16: invokestatic  #156                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      19: astore        6
      21: aload         6
      23: astore        7
      25: iconst_0
      26: istore        8
      28: aload         7
      30: invokeinterface #162,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      35: astore        9
      37: aload         9
      39: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          153
      47: aload         9
      49: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      54: astore        10
      56: aload         10
      58: checkcast     #174                // class kotlin/text/MatchResult
      61: astore        11
      63: iconst_0
      64: istore        12
      66: new           #176                // class kotlin/ranges/IntRange
      69: dup
      70: aload         11
      72: invokeinterface #180,  1          // InterfaceMethod kotlin/text/MatchResult.getRange:()Lkotlin/ranges/IntRange;
      77: invokevirtual #183                // Method kotlin/ranges/IntRange.getFirst:()I
      80: iconst_1
      81: isub
      82: aload         11
      84: invokeinterface #180,  1          // InterfaceMethod kotlin/text/MatchResult.getRange:()Lkotlin/ranges/IntRange;
      89: invokevirtual #186                // Method kotlin/ranges/IntRange.getLast:()I
      92: iconst_1
      93: iadd
      94: invokespecial #189                // Method kotlin/ranges/IntRange."<init>":(II)V
      97: astore        13
      99: aload_2
     100: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     103: aload_1
     104: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     107: isub
     108: invokestatic  #195                // Method java/lang/Math.abs:(I)I
     111: iconst_2
     112: if_icmpge     148
     115: aload         13
     117: aload_3
     118: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     121: invokevirtual #199                // Method kotlin/ranges/IntRange.contains:(I)Z
     124: ifeq          148
     127: aload         4
     129: aload         4
     131: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     134: aload         11
     136: invokeinterface #202,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     141: invokestatic  #208                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     144: iadd
     145: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     148: nop
     149: nop
     150: goto          37
     153: nop
     154: aload_1
     155: aload_1
     156: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     159: iconst_1
     160: iadd
     161: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     164: getstatic     #214                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     167: areturn

  private static final kotlin.Unit gearRatio$lambda$3(kotlin.text.Regex, kotlin.jvm.internal.Ref$IntRef, kotlin.text.Regex, kotlin.jvm.internal.Ref$IntRef, java.lang.String);
    Code:
       0: aload         4
       2: ldc           #144                // String it
       4: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload         4
      10: ldc           #234                // String .
      12: ldc           #236                // String a
      14: iconst_0
      15: iconst_4
      16: aconst_null
      17: invokestatic  #242                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      20: checkcast     #152                // class java/lang/CharSequence
      23: iconst_0
      24: iconst_2
      25: aconst_null
      26: invokestatic  #156                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      29: astore        5
      31: aload         5
      33: astore        6
      35: iconst_0
      36: istore        7
      38: aload         6
      40: invokeinterface #162,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      45: astore        8
      47: aload         8
      49: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          141
      57: aload         8
      59: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        9
      66: aload         9
      68: checkcast     #174                // class kotlin/text/MatchResult
      71: astore        10
      73: iconst_0
      74: istore        11
      76: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
      79: dup
      80: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      83: astore        12
      85: aload         12
      87: aload         10
      89: invokeinterface #180,  1          // InterfaceMethod kotlin/text/MatchResult.getRange:()Lkotlin/ranges/IntRange;
      94: invokevirtual #183                // Method kotlin/ranges/IntRange.getFirst:()I
      97: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     100: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
     103: dup
     104: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     107: astore        13
     109: new           #23                 // class java/io/File
     112: dup
     113: ldc           #25                 // String day2303_puzzle_input.txt
     115: invokespecial #26                 // Method java/io/File."<init>":(Ljava/lang/String;)V
     118: aconst_null
     119: aload_2
     120: aload         13
     122: aload_1
     123: aload         12
     125: aload_3
     126: invokedynamic #248,  0            // InvokeDynamic #2:invoke:(Lkotlin/text/Regex;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function1;
     131: iconst_1
     132: aconst_null
     133: invokestatic  #52                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
     136: nop
     137: nop
     138: goto          47
     141: nop
     142: aload_1
     143: aload_1
     144: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     147: iconst_1
     148: iadd
     149: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     152: getstatic     #214                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     155: areturn

  private static final kotlin.Unit gearRatioPart2$lambda$7$lambda$6$lambda$5(kotlin.text.Regex, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, java.lang.String);
    Code:
       0: aload         6
       2: ldc           #144                // String it
       4: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload         6
      10: checkcast     #152                // class java/lang/CharSequence
      13: iconst_0
      14: iconst_2
      15: aconst_null
      16: invokestatic  #156                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      19: astore        7
      21: aload         7
      23: astore        8
      25: iconst_0
      26: istore        9
      28: aload         8
      30: invokeinterface #162,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      35: astore        10
      37: aload         10
      39: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          165
      47: aload         10
      49: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      54: astore        11
      56: aload         11
      58: checkcast     #174                // class kotlin/text/MatchResult
      61: astore        12
      63: iconst_0
      64: istore        13
      66: new           #176                // class kotlin/ranges/IntRange
      69: dup
      70: aload         12
      72: invokeinterface #180,  1          // InterfaceMethod kotlin/text/MatchResult.getRange:()Lkotlin/ranges/IntRange;
      77: invokevirtual #183                // Method kotlin/ranges/IntRange.getFirst:()I
      80: iconst_1
      81: isub
      82: aload         12
      84: invokeinterface #180,  1          // InterfaceMethod kotlin/text/MatchResult.getRange:()Lkotlin/ranges/IntRange;
      89: invokevirtual #186                // Method kotlin/ranges/IntRange.getLast:()I
      92: iconst_1
      93: iadd
      94: invokespecial #189                // Method kotlin/ranges/IntRange."<init>":(II)V
      97: astore        14
      99: aload_2
     100: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     103: aload_1
     104: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     107: isub
     108: invokestatic  #195                // Method java/lang/Math.abs:(I)I
     111: iconst_2
     112: if_icmpge     160
     115: aload         14
     117: aload_3
     118: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     121: invokevirtual #199                // Method kotlin/ranges/IntRange.contains:(I)Z
     124: ifeq          160
     127: aload         4
     129: aload         4
     131: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     134: aload         12
     136: invokeinterface #202,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     141: invokestatic  #208                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     144: imul
     145: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     148: aload         5
     150: aload         5
     152: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     155: iconst_1
     156: iadd
     157: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     160: nop
     161: nop
     162: goto          37
     165: nop
     166: aload_1
     167: aload_1
     168: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     171: iconst_1
     172: iadd
     173: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     176: getstatic     #214                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     179: areturn

  private static final kotlin.Unit gearRatioPart2$lambda$7(kotlin.text.Regex, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, kotlin.text.Regex, java.lang.String);
    Code:
       0: aload         4
       2: ldc           #144                // String it
       4: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload         4
      10: checkcast     #152                // class java/lang/CharSequence
      13: iconst_0
      14: iconst_2
      15: aconst_null
      16: invokestatic  #156                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      19: astore        5
      21: aload         5
      23: astore        6
      25: iconst_0
      26: istore        7
      28: aload         6
      30: invokeinterface #162,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      35: astore        8
      37: aload         8
      39: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          181
      47: aload         8
      49: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      54: astore        9
      56: aload         9
      58: checkcast     #174                // class kotlin/text/MatchResult
      61: astore        10
      63: iconst_0
      64: istore        11
      66: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
      69: dup
      70: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      73: astore        12
      75: aload         12
      77: iconst_1
      78: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      81: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
      84: dup
      85: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      88: astore        13
      90: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
      93: dup
      94: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      97: astore        14
      99: aload         14
     101: aload         10
     103: invokeinterface #180,  1          // InterfaceMethod kotlin/text/MatchResult.getRange:()Lkotlin/ranges/IntRange;
     108: invokevirtual #183                // Method kotlin/ranges/IntRange.getFirst:()I
     111: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     114: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
     117: dup
     118: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     121: astore        15
     123: new           #23                 // class java/io/File
     126: dup
     127: ldc           #25                 // String day2303_puzzle_input.txt
     129: invokespecial #26                 // Method java/io/File."<init>":(Ljava/lang/String;)V
     132: aconst_null
     133: aload_3
     134: aload         15
     136: aload_1
     137: aload         14
     139: aload         12
     141: aload         13
     143: invokedynamic #264,  0            // InvokeDynamic #3:invoke:(Lkotlin/text/Regex;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function1;
     148: iconst_1
     149: aconst_null
     150: invokestatic  #52                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
     153: aload         13
     155: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     158: iconst_2
     159: if_icmpne     176
     162: aload_2
     163: aload_2
     164: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     167: aload         12
     169: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     172: iadd
     173: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     176: nop
     177: nop
     178: goto          37
     181: nop
     182: aload_1
     183: aload_1
     184: getfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     187: iconst_1
     188: iadd
     189: putfield      #56                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     192: getstatic     #214                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     195: areturn
}


import java.io.File

fun cube(in1: Int): Int {
	var result = 0

	File("day2302_puzzle_input.txt").forEachLine {
		var gamePossible = true
		var maxRed = 0
		var maxGreen = 0
		var maxBlue = 0
		var instruction = it.split(": ")
		var game = instruction[0].substringAfter("Game ").toInt()
		var results = instruction[1].split("; ")
		results.forEach{
			var colours = it.split(", ")
			colours.forEach{
				if (it.contains("green")) {
					if (it.substringBefore(" green").toInt() > 13) {
						gamePossible = false
					}
					maxGreen = maxOf(maxGreen, it.substringBefore(" green").toInt())
				}
				if (it.contains("red")) {
					if (it.substringBefore(" red").toInt() > 12) {
						gamePossible = false
					}
					maxRed = maxOf(maxRed, it.substringBefore(" red").toInt())
				}
				if (it.contains("blue")) {
					if (it.substringBefore(" blue").toInt() > 14) {
						gamePossible = false
					}
					maxBlue = maxOf(maxBlue, it.substringBefore(" blue").toInt())
				}
			}
		}
		if (in1 == 1) {
			if (gamePossible) result += game
		} else {
			result += maxRed * maxGreen * maxBlue

		}
	}
	return result
}

fun main() {
	var t1 = System.currentTimeMillis()

	var solution1 = cube(1)
	var solution2 = cube(2)

// print solution for part 1
	println("*******************************")
	println("--- Day 2: Cube Conundrum ---")
	println("*******************************")
	println("Solution for part1")
	println("   $solution1 is the sum of the IDs of those games")
	println()
// print solution for part 2
	println("*******************************")
	println("Solution for part2")
	println("   $solution2 is the sum of the power of these sets")
	println()

	t1 = System.currentTimeMillis() - t1
	println("puzzle solved in ${t1} ms")
}

Compiled from "day02_1_2.kt"
public final class Day02_1_2Kt {
  public static final int cube(int);
    Code:
       0: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
       3: dup
       4: invokespecial #12                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
       7: astore_1
       8: new           #14                 // class java/io/File
      11: dup
      12: ldc           #16                 // String day2302_puzzle_input.txt
      14: invokespecial #19                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      17: aconst_null
      18: iload_0
      19: aload_1
      20: invokedynamic #39,  0             // InvokeDynamic #0:invoke:(ILkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function1;
      25: iconst_1
      26: aconst_null
      27: invokestatic  #45                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      30: aload_1
      31: getfield      #49                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      34: ireturn

  public static final void main();
    Code:
       0: invokestatic  #59                 // Method java/lang/System.currentTimeMillis:()J
       3: lstore_0
       4: iconst_1
       5: invokestatic  #61                 // Method cube:(I)I
       8: istore_2
       9: iconst_2
      10: invokestatic  #61                 // Method cube:(I)I
      13: istore_3
      14: ldc           #63                 // String *******************************
      16: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
      19: swap
      20: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      23: ldc           #75                 // String --- Day 2: Cube Conundrum ---
      25: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: swap
      29: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      32: ldc           #63                 // String *******************************
      34: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
      37: swap
      38: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      41: ldc           #77                 // String Solution for part1
      43: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
      46: swap
      47: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      50: new           #79                 // class java/lang/StringBuilder
      53: dup
      54: invokespecial #80                 // Method java/lang/StringBuilder."<init>":()V
      57: ldc           #82                 // String
      59: invokevirtual #86                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      62: iload_2
      63: invokevirtual #89                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      66: ldc           #91                 // String  is the sum of the IDs of those games
      68: invokevirtual #86                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      71: invokevirtual #95                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      74: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
      84: invokevirtual #97                 // Method java/io/PrintStream.println:()V
      87: ldc           #63                 // String *******************************
      89: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
      92: swap
      93: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      96: ldc           #99                 // String Solution for part2
      98: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
     101: swap
     102: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     105: new           #79                 // class java/lang/StringBuilder
     108: dup
     109: invokespecial #80                 // Method java/lang/StringBuilder."<init>":()V
     112: ldc           #82                 // String
     114: invokevirtual #86                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     117: iload_3
     118: invokevirtual #89                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     121: ldc           #101                // String  is the sum of the power of these sets
     123: invokevirtual #86                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     126: invokevirtual #95                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     129: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
     132: swap
     133: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     136: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
     139: invokevirtual #97                 // Method java/io/PrintStream.println:()V
     142: invokestatic  #59                 // Method java/lang/System.currentTimeMillis:()J
     145: lload_0
     146: lsub
     147: lstore_0
     148: new           #79                 // class java/lang/StringBuilder
     151: dup
     152: invokespecial #80                 // Method java/lang/StringBuilder."<init>":()V
     155: ldc           #103                // String puzzle solved in
     157: invokevirtual #86                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     160: lload_0
     161: invokevirtual #106                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     164: ldc           #108                // String  ms
     166: invokevirtual #86                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     169: invokevirtual #95                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     172: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
     175: swap
     176: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     179: return

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

  private static final kotlin.Unit cube$lambda$2(int, kotlin.jvm.internal.Ref$IntRef, java.lang.String);
    Code:
       0: aload_2
       1: ldc           #119                // String it
       3: invokestatic  #125                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_3
       8: iconst_1
       9: istore_3
      10: iconst_0
      11: istore        4
      13: iconst_0
      14: istore        5
      16: iconst_0
      17: istore        6
      19: aload_2
      20: checkcast     #127                // class java/lang/CharSequence
      23: iconst_1
      24: anewarray     #129                // class java/lang/String
      27: astore        8
      29: aload         8
      31: iconst_0
      32: ldc           #131                // String :
      34: aastore
      35: aload         8
      37: iconst_0
      38: iconst_0
      39: bipush        6
      41: aconst_null
      42: invokestatic  #137                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      45: astore        7
      47: aload         7
      49: iconst_0
      50: invokeinterface #143,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      55: checkcast     #129                // class java/lang/String
      58: ldc           #145                // String Game
      60: aconst_null
      61: iconst_2
      62: aconst_null
      63: invokestatic  #149                // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      66: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      69: istore        8
      71: aload         7
      73: iconst_1
      74: invokeinterface #143,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      79: checkcast     #127                // class java/lang/CharSequence
      82: iconst_1
      83: anewarray     #129                // class java/lang/String
      86: astore        10
      88: aload         10
      90: iconst_0
      91: ldc           #157                // String ;
      93: aastore
      94: aload         10
      96: iconst_0
      97: iconst_0
      98: bipush        6
     100: aconst_null
     101: invokestatic  #137                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     104: astore        9
     106: aload         9
     108: checkcast     #159                // class java/lang/Iterable
     111: astore        10
     113: iconst_0
     114: istore        11
     116: aload         10
     118: invokeinterface #163,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     123: astore        12
     125: aload         12
     127: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     132: ifeq          422
     135: aload         12
     137: invokeinterface #173,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     142: astore        13
     144: aload         13
     146: checkcast     #129                // class java/lang/String
     149: astore        14
     151: iconst_0
     152: istore        15
     154: aload         14
     156: checkcast     #127                // class java/lang/CharSequence
     159: iconst_1
     160: anewarray     #129                // class java/lang/String
     163: astore        16
     165: aload         16
     167: iconst_0
     168: ldc           #175                // String ,
     170: aastore
     171: aload         16
     173: iconst_0
     174: iconst_0
     175: bipush        6
     177: aconst_null
     178: invokestatic  #137                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     181: astore        17
     183: aload         17
     185: checkcast     #159                // class java/lang/Iterable
     188: astore        16
     190: iconst_0
     191: istore        18
     193: aload         16
     195: invokeinterface #163,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     200: astore        19
     202: aload         19
     204: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     209: ifeq          416
     212: aload         19
     214: invokeinterface #173,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     219: astore        20
     221: aload         20
     223: checkcast     #129                // class java/lang/String
     226: astore        21
     228: iconst_0
     229: istore        22
     231: aload         21
     233: checkcast     #127                // class java/lang/CharSequence
     236: ldc           #177                // String green
     238: checkcast     #127                // class java/lang/CharSequence
     241: iconst_0
     242: iconst_2
     243: aconst_null
     244: invokestatic  #181                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
     247: ifeq          291
     250: aload         21
     252: ldc           #183                // String  green
     254: aconst_null
     255: iconst_2
     256: aconst_null
     257: invokestatic  #186                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     260: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     263: bipush        13
     265: if_icmple     270
     268: iconst_0
     269: istore_3
     270: nop
     271: iload         5
     273: aload         21
     275: ldc           #183                // String  green
     277: aconst_null
     278: iconst_2
     279: aconst_null
     280: invokestatic  #186                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     283: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     286: invokestatic  #192                // Method java/lang/Math.max:(II)I
     289: istore        5
     291: aload         21
     293: checkcast     #127                // class java/lang/CharSequence
     296: ldc           #194                // String red
     298: checkcast     #127                // class java/lang/CharSequence
     301: iconst_0
     302: iconst_2
     303: aconst_null
     304: invokestatic  #181                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
     307: ifeq          351
     310: aload         21
     312: ldc           #196                // String  red
     314: aconst_null
     315: iconst_2
     316: aconst_null
     317: invokestatic  #186                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     320: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     323: bipush        12
     325: if_icmple     330
     328: iconst_0
     329: istore_3
     330: nop
     331: iload         4
     333: aload         21
     335: ldc           #196                // String  red
     337: aconst_null
     338: iconst_2
     339: aconst_null
     340: invokestatic  #186                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     343: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     346: invokestatic  #192                // Method java/lang/Math.max:(II)I
     349: istore        4
     351: aload         21
     353: checkcast     #127                // class java/lang/CharSequence
     356: ldc           #198                // String blue
     358: checkcast     #127                // class java/lang/CharSequence
     361: iconst_0
     362: iconst_2
     363: aconst_null
     364: invokestatic  #181                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
     367: ifeq          411
     370: aload         21
     372: ldc           #200                // String  blue
     374: aconst_null
     375: iconst_2
     376: aconst_null
     377: invokestatic  #186                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     380: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     383: bipush        14
     385: if_icmple     390
     388: iconst_0
     389: istore_3
     390: nop
     391: iload         6
     393: aload         21
     395: ldc           #200                // String  blue
     397: aconst_null
     398: iconst_2
     399: aconst_null
     400: invokestatic  #186                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     403: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     406: invokestatic  #192                // Method java/lang/Math.max:(II)I
     409: istore        6
     411: nop
     412: nop
     413: goto          202
     416: nop
     417: nop
     418: nop
     419: goto          125
     422: nop
     423: iload_0
     424: iconst_1
     425: if_icmpne     446
     428: iload_3
     429: ifeq          463
     432: aload_1
     433: aload_1
     434: getfield      #49                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     437: iload         8
     439: iadd
     440: putfield      #49                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     443: goto          463
     446: aload_1
     447: aload_1
     448: getfield      #49                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     451: iload         4
     453: iload         5
     455: imul
     456: iload         6
     458: imul
     459: iadd
     460: putfield      #49                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     463: getstatic     #206                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     466: areturn
}


import java.io.*
import java.math.*
import java.security.*
import java.text.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.regex.*
import java.util.stream.*
import kotlin.collections.*
import kotlin.comparisons.*
import kotlin.io.*
import kotlin.jvm.*
import kotlin.jvm.functions.*
import kotlin.jvm.internal.*
import kotlin.ranges.*
import kotlin.sequences.*
import kotlin.text.*

/*
 *   Hackerrank - Diagonal Difference
 *   https://www.hackerrank.com/challenges/diagonal-difference/problem
 */

fun diagonalDifference(arr: Array<Array<Int>>): Int {
    var primaryDiagonal = 0
    var secondaryDiagonal = 0
    var counter = 0

    for(line in 1..arr.size){
        primaryDiagonal += arr[counter][counter]
        secondaryDiagonal += arr[counter][(arr.size - 1) - counter]
        counter++
    }
    return Math.abs(primaryDiagonal - secondaryDiagonal)
}

fun main(args: Array<String>) {
    val n = readLine()!!.trim().toInt()

    val arr = Array<Array<Int>>(n, { Array<Int>(n, { 0 }) })

    for (i in 0 until n) {
        arr[i] = readLine()!!.trimEnd().split(" ").map{ it.toInt() }.toTypedArray()
    }

    val result = diagonalDifference(arr)

    println(result)
}

Compiled from "DiagonalDifference.kt"
public final class DiagonalDifferenceKt {
  public static final int diagonalDifference(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc           #9                  // String arr
       3: invokestatic  #15                 // 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: iconst_1
      13: istore        4
      15: aload_0
      16: checkcast     #17                 // class "[Ljava/lang/Object;"
      19: arraylength
      20: istore        5
      22: iload         4
      24: iload         5
      26: if_icmpgt     75
      29: iload_1
      30: aload_0
      31: iload_3
      32: aaload
      33: iload_3
      34: aaload
      35: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      38: iadd
      39: istore_1
      40: iload_2
      41: aload_0
      42: iload_3
      43: aaload
      44: aload_0
      45: checkcast     #17                 // class "[Ljava/lang/Object;"
      48: arraylength
      49: iconst_1
      50: isub
      51: iload_3
      52: isub
      53: aaload
      54: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      57: iadd
      58: istore_2
      59: iinc          3, 1
      62: iload         4
      64: iload         5
      66: if_icmpeq     75
      69: iinc          4, 1
      72: goto          29
      75: iload_1
      76: iload_2
      77: isub
      78: invokestatic  #29                 // Method java/lang/Math.abs:(I)I
      81: ireturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #40                 // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: nop
       7: invokestatic  #46                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      10: dup
      11: invokestatic  #50                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      14: checkcast     #52                 // class java/lang/CharSequence
      17: invokestatic  #58                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      20: invokevirtual #61                 // Method java/lang/Object.toString:()Ljava/lang/String;
      23: invokestatic  #65                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      26: istore_1
      27: iconst_0
      28: istore_3
      29: iload_1
      30: anewarray     #67                 // class "[Ljava/lang/Integer;"
      33: astore        4
      35: iload_3
      36: iload_1
      37: if_icmpge     98
      40: iload_3
      41: istore        5
      43: aload         4
      45: iload         5
      47: iconst_0
      48: istore        6
      50: iload_1
      51: anewarray     #19                 // class java/lang/Integer
      54: astore        7
      56: istore        14
      58: astore        13
      60: iload         6
      62: iload_1
      63: if_icmpge     85
      66: iload         6
      68: istore        8
      70: aload         7
      72: iload         8
      74: iconst_0
      75: invokestatic  #71                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: aastore
      79: iinc          6, 1
      82: goto          60
      85: aload         13
      87: iload         14
      89: aload         7
      91: aastore
      92: iinc          3, 1
      95: goto          35
      98: aload         4
     100: astore_2
     101: iconst_0
     102: istore_3
     103: iload_3
     104: iload_1
     105: if_icmpge     297
     108: aload_2
     109: iload_3
     110: invokestatic  #46                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
     113: dup
     114: invokestatic  #50                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     117: checkcast     #52                 // class java/lang/CharSequence
     120: invokestatic  #74                 // Method kotlin/text/StringsKt.trimEnd:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     123: invokevirtual #61                 // Method java/lang/Object.toString:()Ljava/lang/String;
     126: checkcast     #52                 // class java/lang/CharSequence
     129: iconst_1
     130: anewarray     #76                 // class java/lang/String
     133: astore        4
     135: aload         4
     137: iconst_0
     138: ldc           #78                 // String
     140: aastore
     141: aload         4
     143: iconst_0
     144: iconst_0
     145: bipush        6
     147: aconst_null
     148: invokestatic  #82                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     151: checkcast     #84                 // class java/lang/Iterable
     154: astore        4
     156: istore        14
     158: astore        13
     160: iconst_0
     161: istore        5
     163: aload         4
     165: astore        6
     167: new           #86                 // class java/util/ArrayList
     170: dup
     171: aload         4
     173: bipush        10
     175: invokestatic  #92                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     178: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
     181: checkcast     #98                 // class java/util/Collection
     184: astore        7
     186: iconst_0
     187: istore        8
     189: aload         6
     191: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     196: astore        9
     198: aload         9
     200: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     205: ifeq          252
     208: aload         9
     210: invokeinterface #112,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     215: astore        10
     217: aload         7
     219: aload         10
     221: checkcast     #76                 // class java/lang/String
     224: astore        11
     226: astore        15
     228: iconst_0
     229: istore        12
     231: aload         11
     233: invokestatic  #65                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     236: nop
     237: invokestatic  #71                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     240: aload         15
     242: swap
     243: invokeinterface #116,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     248: pop
     249: goto          198
     252: aload         7
     254: checkcast     #118                // class java/util/List
     257: nop
     258: astore        15
     260: aload         13
     262: iload         14
     264: aload         15
     266: checkcast     #98                 // class java/util/Collection
     269: astore        4
     271: nop
     272: iconst_0
     273: istore        5
     275: aload         4
     277: astore        6
     279: aload         6
     281: iconst_0
     282: anewarray     #19                 // class java/lang/Integer
     285: invokeinterface #122,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     290: aastore
     291: iinc          3, 1
     294: goto          103
     297: aload_2
     298: invokestatic  #124                // Method diagonalDifference:([[Ljava/lang/Integer;)I
     301: istore_3
     302: getstatic     #130                // Field java/lang/System.out:Ljava/io/PrintStream;
     305: iload_3
     306: invokevirtual #135                // Method java/io/PrintStream.println:(I)V
     309: return
}


import java.io.File
import java.io.FileReader
import java.util.stream.Stream

fun main(args: Array<String>) {
    FileReader(File("./input.txt")).buffered().use {
        main(it.lines())
    }
}

fun doExample() {
    val lines = listOf(
            "b inc 5 if a > 1",
            "a inc 1 if b < 5",
            "c dec -10 if a >= 1",
            "c inc -20 if c == 10"
    )
    main(lines.stream())
}

fun main(instructionLines: Stream<String>) {
    val registers = HashMap<String, Int>()
    var overallMax = Int.MIN_VALUE
    instructionLines.forEach({
        line -> parseInstruction(line).perform(registers)
                val currentMax = registers.values.max() ?: Int.MIN_VALUE
                if (currentMax > overallMax) {
                    overallMax = currentMax
                }

    })
    println(registers)
    val maxValue = registers.values.max()
    println("current max value is $maxValue")
    println("overall max value seen is $overallMax")
}

enum class Operator(val token : String) {
    GT(">"),
    LT("<"),
    GTE(">="),
    LTE("<="),
    EQ("=="),
    NE("!=")
}

fun parseOperator(token: String) : Operator {
    Operator.values()
            .filter { token == it.token }
            .forEach { return it }
    throw IllegalArgumentException("token does not represent an operator: " + token);
}

class Condition(
        val label : String,
        val operator : Operator,
        val reference : Int
) {
    fun evaluate(registers: Map<String, Int>) : Boolean {
        val query = registers.getOrDefault(label, 0)
        return when (operator) {
            Operator.GT -> query > reference
            Operator.GTE -> query >= reference
            Operator.LT -> query < reference
            Operator.LTE -> query <= reference
            Operator.EQ -> query == reference
            Operator.NE -> query != reference
        }
    }
}

class Instruction(
        val target: String,
        val delta: Int,
        val condition : Condition
) {
    fun perform(registers: MutableMap<String, Int>) {
        var value = registers.getOrDefault(target, 0)
        if (condition.evaluate(registers)) {
            value += delta
        }
        registers.put(target, value)
    }
}

fun parseInstruction(line: String): Instruction {
    val tokens = line.split(Regex("\\s+"))
    val delta = tokens[2].toInt() * (if ("inc" == tokens[1]) 1 else -1)
    val condition = Condition(tokens[4], parseOperator(tokens[5]), tokens[6].toInt())
    return Instruction(tokens[0], delta, condition)
}

Compiled from "Registers.kt"
public final class RegistersKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #11                 // String args
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #19                 // class java/io/FileReader
       9: dup
      10: new           #21                 // class java/io/File
      13: dup
      14: ldc           #23                 // String ./input.txt
      16: invokespecial #27                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      19: invokespecial #30                 // Method java/io/FileReader."<init>":(Ljava/io/File;)V
      22: checkcast     #32                 // class java/io/Reader
      25: astore_1
      26: sipush        8192
      29: istore_2
      30: aload_1
      31: instanceof    #34                 // class java/io/BufferedReader
      34: ifeq          44
      37: aload_1
      38: checkcast     #34                 // class java/io/BufferedReader
      41: goto          53
      44: new           #34                 // class java/io/BufferedReader
      47: dup
      48: aload_1
      49: iload_2
      50: invokespecial #37                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      53: checkcast     #39                 // class java/io/Closeable
      56: astore_1
      57: aconst_null
      58: astore_2
      59: nop
      60: aload_1
      61: checkcast     #34                 // class java/io/BufferedReader
      64: astore_3
      65: iconst_0
      66: istore        4
      68: aload_3
      69: invokevirtual #43                 // Method java/io/BufferedReader.lines:()Ljava/util/stream/Stream;
      72: dup
      73: ldc           #45                 // String lines(...)
      75: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      78: invokestatic  #51                 // Method main:(Ljava/util/stream/Stream;)V
      81: nop
      82: getstatic     #57                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      85: astore_3
      86: aload_1
      87: aload_2
      88: invokestatic  #63                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
      91: goto          112
      94: astore        4
      96: aload         4
      98: astore_2
      99: aload         4
     101: athrow
     102: astore        4
     104: aload_1
     105: aload_2
     106: invokestatic  #63                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     109: aload         4
     111: athrow
     112: return
    Exception table:
       from    to  target type
          59    86    94   Class java/lang/Throwable
          59    86   102   any
          94   102   102   any
         102   104   102   any

  public static final void doExample();
    Code:
       0: iconst_4
       1: anewarray     #73                 // class java/lang/String
       4: astore_1
       5: aload_1
       6: iconst_0
       7: ldc           #75                 // String b inc 5 if a > 1
       9: aastore
      10: aload_1
      11: iconst_1
      12: ldc           #77                 // String a inc 1 if b < 5
      14: aastore
      15: aload_1
      16: iconst_2
      17: ldc           #79                 // String c dec -10 if a >= 1
      19: aastore
      20: aload_1
      21: iconst_3
      22: ldc           #81                 // String c inc -20 if c == 10
      24: aastore
      25: aload_1
      26: invokestatic  #87                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      29: astore_0
      30: aload_0
      31: invokeinterface #92,  1           // InterfaceMethod java/util/List.stream:()Ljava/util/stream/Stream;
      36: dup
      37: ldc           #94                 // String stream(...)
      39: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      42: invokestatic  #51                 // Method main:(Ljava/util/stream/Stream;)V
      45: return

  public static final void main(java.util.stream.Stream<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #98                 // String instructionLines
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #100                // class java/util/HashMap
       9: dup
      10: invokespecial #102                // Method java/util/HashMap."<init>":()V
      13: astore_1
      14: new           #104                // class kotlin/jvm/internal/Ref$IntRef
      17: dup
      18: invokespecial #105                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      21: astore_2
      22: aload_2
      23: ldc           #106                // int -2147483648
      25: putfield      #109                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      28: aload_0
      29: aload_1
      30: aload_2
      31: invokedynamic #129,  0            // InvokeDynamic #0:invoke:(Ljava/util/HashMap;Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function1;
      36: invokedynamic #140,  0            // InvokeDynamic #1:accept:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/Consumer;
      41: invokeinterface #146,  2          // InterfaceMethod java/util/stream/Stream.forEach:(Ljava/util/function/Consumer;)V
      46: getstatic     #152                // Field java/lang/System.out:Ljava/io/PrintStream;
      49: aload_1
      50: invokevirtual #157                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      53: aload_1
      54: invokevirtual #161                // Method java/util/HashMap.values:()Ljava/util/Collection;
      57: dup
      58: ldc           #163                // String <get-values>(...)
      60: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      63: checkcast     #165                // class java/lang/Iterable
      66: invokestatic  #169                // Method kotlin/collections/CollectionsKt.maxOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
      69: checkcast     #171                // class java/lang/Number
      72: invokevirtual #175                // Method java/lang/Number.intValue:()I
      75: istore_3
      76: new           #177                // class java/lang/StringBuilder
      79: dup
      80: invokespecial #178                // Method java/lang/StringBuilder."<init>":()V
      83: ldc           #180                // String current max value is
      85: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      88: iload_3
      89: invokevirtual #187                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      92: invokevirtual #191                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      95: getstatic     #152                // Field java/lang/System.out:Ljava/io/PrintStream;
      98: swap
      99: invokevirtual #157                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     102: new           #177                // class java/lang/StringBuilder
     105: dup
     106: invokespecial #178                // Method java/lang/StringBuilder."<init>":()V
     109: ldc           #193                // String overall max value seen is
     111: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     114: aload_2
     115: getfield      #109                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     118: invokevirtual #187                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     121: invokevirtual #191                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     124: getstatic     #152                // Field java/lang/System.out:Ljava/io/PrintStream;
     127: swap
     128: invokevirtual #157                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     131: return

  public static final Operator parseOperator(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #203                // String token
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: invokestatic  #208                // Method Operator.values:()[LOperator;
       9: astore_1
      10: nop
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #210                // class java/util/ArrayList
      18: dup
      19: invokespecial #211                // Method java/util/ArrayList."<init>":()V
      22: checkcast     #213                // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: iconst_0
      31: istore        6
      33: aload_3
      34: arraylength
      35: istore        7
      37: iload         6
      39: iload         7
      41: if_icmpge     85
      44: aload_3
      45: iload         6
      47: aaload
      48: astore        8
      50: aload         8
      52: astore        9
      54: iconst_0
      55: istore        10
      57: aload_0
      58: aload         9
      60: invokevirtual #216                // Method Operator.getToken:()Ljava/lang/String;
      63: invokestatic  #220                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      66: ifeq          79
      69: aload         4
      71: aload         8
      73: invokeinterface #224,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      78: pop
      79: iinc          6, 1
      82: goto          37
      85: aload         4
      87: checkcast     #89                 // class java/util/List
      90: nop
      91: checkcast     #165                // class java/lang/Iterable
      94: astore_1
      95: nop
      96: iconst_0
      97: istore_2
      98: aload_1
      99: invokeinterface #228,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     104: astore_3
     105: aload_3
     106: invokeinterface #234,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     111: ifeq          135
     114: aload_3
     115: invokeinterface #238,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     120: astore        4
     122: aload         4
     124: checkcast     #205                // class Operator
     127: astore        5
     129: iconst_0
     130: istore        6
     132: aload         5
     134: areturn
     135: nop
     136: new           #240                // class java/lang/IllegalArgumentException
     139: dup
     140: new           #177                // class java/lang/StringBuilder
     143: dup
     144: invokespecial #178                // Method java/lang/StringBuilder."<init>":()V
     147: ldc           #242                // String token does not represent an operator:
     149: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     152: aload_0
     153: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     156: invokevirtual #191                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     159: invokespecial #243                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     162: athrow

  public static final Instruction parseInstruction(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #266                // String line
       4: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #268                // class java/lang/CharSequence
      11: astore_2
      12: new           #270                // class kotlin/text/Regex
      15: dup
      16: ldc_w         #272                // String \\s+
      19: invokespecial #273                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      22: astore_3
      23: iconst_0
      24: istore        4
      26: aload_3
      27: aload_2
      28: iload         4
      30: invokevirtual #277                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      33: astore_1
      34: aload_1
      35: iconst_2
      36: invokeinterface #281,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      41: checkcast     #73                 // class java/lang/String
      44: invokestatic  #287                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      47: ldc_w         #289                // String inc
      50: aload_1
      51: iconst_1
      52: invokeinterface #281,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      57: invokestatic  #220                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      60: ifeq          67
      63: iconst_1
      64: goto          68
      67: iconst_m1
      68: imul
      69: istore_2
      70: new           #291                // class Condition
      73: dup
      74: aload_1
      75: iconst_4
      76: invokeinterface #281,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      81: checkcast     #73                 // class java/lang/String
      84: aload_1
      85: iconst_5
      86: invokeinterface #281,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      91: checkcast     #73                 // class java/lang/String
      94: invokestatic  #293                // Method parseOperator:(Ljava/lang/String;)LOperator;
      97: aload_1
      98: bipush        6
     100: invokeinterface #281,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     105: checkcast     #73                 // class java/lang/String
     108: invokestatic  #287                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     111: invokespecial #296                // Method Condition."<init>":(Ljava/lang/String;LOperator;I)V
     114: astore_3
     115: new           #298                // class Instruction
     118: dup
     119: aload_1
     120: iconst_0
     121: invokeinterface #281,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     126: checkcast     #73                 // class java/lang/String
     129: iload_2
     130: aload_3
     131: invokespecial #301                // Method Instruction."<init>":(Ljava/lang/String;ILCondition;)V
     134: areturn

  private static final kotlin.Unit main$lambda$1(java.util.HashMap, kotlin.jvm.internal.Ref$IntRef, java.lang.String);
    Code:
       0: aload_2
       1: invokestatic  #308                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       4: aload_2
       5: invokestatic  #310                // Method parseInstruction:(Ljava/lang/String;)LInstruction;
       8: aload_0
       9: checkcast     #312                // class java/util/Map
      12: invokevirtual #316                // Method Instruction.perform:(Ljava/util/Map;)V
      15: aload_0
      16: invokevirtual #161                // Method java/util/HashMap.values:()Ljava/util/Collection;
      19: dup
      20: ldc           #163                // String <get-values>(...)
      22: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      25: checkcast     #165                // class java/lang/Iterable
      28: invokestatic  #169                // Method kotlin/collections/CollectionsKt.maxOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
      31: checkcast     #171                // class java/lang/Number
      34: invokevirtual #175                // Method java/lang/Number.intValue:()I
      37: istore_3
      38: iload_3
      39: aload_1
      40: getfield      #109                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      43: if_icmple     51
      46: aload_1
      47: iload_3
      48: putfield      #109                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      51: getstatic     #57                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      54: areturn

  private static final void main$lambda$2(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #323,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: pop
       8: return
}