package year_2017.day07

import kotlin.math.absoluteValue
import readInput
import second

fun part1(input: List<String>): String {
    val programs = input.map(String::parse)

    return programs.findBottomProgram()
}

fun part2(input: List<String>): Int {
    val programs = input.map(String::parse)
    allPrograms = programs.associateBy { it.name }.toMutableMap()

    return allPrograms[programs.findBottomProgram()]!!.findImbalance()
}

var allPrograms: Map<String, Program> = mapOf()

fun main() {
    val input = readInput("main/year_2017/day07/Day07")
    println(part1(input))
    println(part2(input))
}

fun Collection<Program>.findBottomProgram(): String {
    val allNames = this.flatMap { p -> listOf(p.name.trim()) + p.programsCarried.map { it.trim() } }
    val nameCounts = allNames.associateBy { s -> allNames.count { it == s } }

    return nameCounts[1]!!
}

data class Program(
    val name: String,
    val weight: Int,
    val programsCarried: List<String>
) {
    private fun totalWeightCarried(): Int {
        return weight + programsCarried
            .sumOf { name ->
                allPrograms[name.trim()]!!.totalWeightCarried()
            }
    }

    private fun childrenAreBalanced() =
        programsCarried.map { allPrograms[it.trim()]!!.totalWeightCarried() }.distinct().size == 1

    fun findImbalance(imbalance: Int? = null): Int =
        if (imbalance != null && childrenAreBalanced()) {
            weight - imbalance
        } else {
            val subTrees = programsCarried.groupBy { allPrograms[it.trim()]!!.totalWeightCarried() }
            val outOfBalanceTree = subTrees.minBy { it.value.size }.value.first().trim()

            allPrograms[outOfBalanceTree]!!.findImbalance(imbalance = imbalance ?: subTrees.keys.reduce { a, b -> a - b }.absoluteValue)
        }
}

fun String.parse(): Program {
    return this.split("->").let {
        val split = it.first().split((" ("))
        val name = split.first().trim()
        val weight = split.second().trim().dropLast(1).toInt()
        val programs = if (it.size > 1) {
            it.second().split((", ").trim())
        } else emptyList()
        Program(name.trim(), weight, programs.map(String::trim))
    }
}

Compiled from "day07.kt"
public final class year_2017.day07.Day07Kt {
  private static java.util.Map<java.lang.String, year_2017.day07.Program> allPrograms;

  public static final java.lang.String part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #20                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #32                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          96
      56: aload         7
      58: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #48                 // class java/lang/String
      72: astore        9
      74: astore        11
      76: iconst_0
      77: istore        10
      79: aload         9
      81: invokestatic  #52                 // Method parse:(Ljava/lang/String;)Lyear_2017/day07/Program;
      84: aload         11
      86: swap
      87: invokeinterface #56,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      92: pop
      93: goto          46
      96: aload         5
      98: checkcast     #58                 // class java/util/List
     101: nop
     102: astore_1
     103: aload_1
     104: checkcast     #32                 // class java/util/Collection
     107: invokestatic  #62                 // Method findBottomProgram:(Ljava/util/Collection;)Ljava/lang/String;
     110: areturn

  public static final int part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #20                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #32                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          96
      56: aload         7
      58: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #48                 // class java/lang/String
      72: astore        9
      74: astore        12
      76: iconst_0
      77: istore        10
      79: aload         9
      81: invokestatic  #52                 // Method parse:(Ljava/lang/String;)Lyear_2017/day07/Program;
      84: aload         12
      86: swap
      87: invokeinterface #56,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      92: pop
      93: goto          46
      96: aload         5
      98: checkcast     #58                 // class java/util/List
     101: nop
     102: astore_1
     103: aload_1
     104: checkcast     #18                 // class java/lang/Iterable
     107: astore_2
     108: iconst_0
     109: istore_3
     110: aload_2
     111: bipush        10
     113: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     116: invokestatic  #86                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     119: bipush        16
     121: invokestatic  #92                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     124: istore        4
     126: aload_2
     127: astore        5
     129: new           #94                 // class java/util/LinkedHashMap
     132: dup
     133: iload         4
     135: invokespecial #95                 // Method java/util/LinkedHashMap."<init>":(I)V
     138: checkcast     #97                 // class java/util/Map
     141: astore        6
     143: iconst_0
     144: istore        7
     146: aload         5
     148: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     153: astore        8
     155: aload         8
     157: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     162: ifeq          207
     165: aload         8
     167: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     172: astore        9
     174: aload         6
     176: aload         9
     178: checkcast     #99                 // class year_2017/day07/Program
     181: astore        10
     183: astore        12
     185: iconst_0
     186: istore        11
     188: aload         10
     190: invokevirtual #103                // Method year_2017/day07/Program.getName:()Ljava/lang/String;
     193: aload         12
     195: swap
     196: aload         9
     198: invokeinterface #107,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     203: pop
     204: goto          155
     207: aload         6
     209: nop
     210: invokestatic  #111                // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     213: putstatic     #115                // Field allPrograms:Ljava/util/Map;
     216: getstatic     #115                // Field allPrograms:Ljava/util/Map;
     219: aload_1
     220: checkcast     #32                 // class java/util/Collection
     223: invokestatic  #62                 // Method findBottomProgram:(Ljava/util/Collection;)Ljava/lang/String;
     226: invokeinterface #119,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     231: dup
     232: invokestatic  #123                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     235: checkcast     #99                 // class year_2017/day07/Program
     238: aconst_null
     239: iconst_1
     240: aconst_null
     241: invokestatic  #127                // Method year_2017/day07/Program.findImbalance$default:(Lyear_2017/day07/Program;Ljava/lang/Integer;ILjava/lang/Object;)I
     244: ireturn

  public static final java.util.Map<java.lang.String, year_2017.day07.Program> getAllPrograms();
    Code:
       0: getstatic     #115                // Field allPrograms:Ljava/util/Map;
       3: areturn

  public static final void setAllPrograms(java.util.Map<java.lang.String, year_2017.day07.Program>);
    Code:
       0: aload_0
       1: ldc           #145                // String <set-?>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: putstatic     #115                // Field allPrograms:Ljava/util/Map;
      10: return

  public static final void main();
    Code:
       0: ldc           #149                // String main/year_2017/day07/Day07
       2: invokestatic  #155                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #157                // Method part1:(Ljava/util/List;)Ljava/lang/String;
      10: getstatic     #163                // Field java/lang/System.out:Ljava/io/PrintStream;
      13: swap
      14: invokevirtual #168                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      17: aload_0
      18: invokestatic  #170                // Method part2:(Ljava/util/List;)I
      21: istore_1
      22: getstatic     #163                // Field java/lang/System.out:Ljava/io/PrintStream;
      25: iload_1
      26: invokevirtual #172                // Method java/io/PrintStream.println:(I)V
      29: return

  public static final java.lang.String findBottomProgram(java.util.Collection<year_2017.day07.Program>);
    Code:
       0: aload_0
       1: ldc           #175                // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #20                 // class java/util/ArrayList
      19: dup
      20: invokespecial #177                // Method java/util/ArrayList."<init>":()V
      23: checkcast     #32                 // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        6
      31: aload         4
      33: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        7
      40: aload         7
      42: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          227
      50: aload         7
      52: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        8
      59: aload         8
      61: checkcast     #99                 // class year_2017/day07/Program
      64: astore        9
      66: iconst_0
      67: istore        10
      69: aload         9
      71: invokevirtual #103                // Method year_2017/day07/Program.getName:()Ljava/lang/String;
      74: checkcast     #179                // class java/lang/CharSequence
      77: invokestatic  #185                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      80: invokevirtual #188                // Method java/lang/Object.toString:()Ljava/lang/String;
      83: invokestatic  #192                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      86: checkcast     #32                 // class java/util/Collection
      89: aload         9
      91: invokevirtual #196                // Method year_2017/day07/Program.getProgramsCarried:()Ljava/util/List;
      94: checkcast     #18                 // class java/lang/Iterable
      97: astore        11
      99: astore        12
     101: iconst_0
     102: istore        13
     104: aload         11
     106: astore        14
     108: new           #20                 // class java/util/ArrayList
     111: dup
     112: aload         11
     114: bipush        10
     116: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     119: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     122: checkcast     #32                 // class java/util/Collection
     125: astore        15
     127: iconst_0
     128: istore        16
     130: aload         14
     132: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     137: astore        17
     139: aload         17
     141: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     146: ifeq          196
     149: aload         17
     151: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     156: astore        18
     158: aload         15
     160: aload         18
     162: checkcast     #48                 // class java/lang/String
     165: astore        19
     167: astore        20
     169: iconst_0
     170: istore        21
     172: aload         19
     174: checkcast     #179                // class java/lang/CharSequence
     177: invokestatic  #185                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     180: invokevirtual #188                // Method java/lang/Object.toString:()Ljava/lang/String;
     183: nop
     184: aload         20
     186: swap
     187: invokeinterface #56,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     192: pop
     193: goto          139
     196: aload         15
     198: checkcast     #58                 // class java/util/List
     201: nop
     202: aload         12
     204: swap
     205: checkcast     #18                 // class java/lang/Iterable
     208: invokestatic  #200                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     211: checkcast     #18                 // class java/lang/Iterable
     214: astore        9
     216: aload         5
     218: aload         9
     220: invokestatic  #204                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     223: pop
     224: goto          40
     227: aload         5
     229: checkcast     #58                 // class java/util/List
     232: nop
     233: astore_1
     234: aload_1
     235: checkcast     #18                 // class java/lang/Iterable
     238: astore_3
     239: iconst_0
     240: istore        4
     242: aload_3
     243: bipush        10
     245: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     248: invokestatic  #86                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     251: bipush        16
     253: invokestatic  #92                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     256: istore        5
     258: aload_3
     259: astore        6
     261: new           #94                 // class java/util/LinkedHashMap
     264: dup
     265: iload         5
     267: invokespecial #95                 // Method java/util/LinkedHashMap."<init>":(I)V
     270: checkcast     #97                 // class java/util/Map
     273: astore        7
     275: iconst_0
     276: istore        8
     278: aload         6
     280: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     285: astore        9
     287: aload         9
     289: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     294: ifeq          439
     297: aload         9
     299: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     304: astore        10
     306: aload         7
     308: aload         10
     310: checkcast     #48                 // class java/lang/String
     313: astore        11
     315: astore        22
     317: iconst_0
     318: istore        12
     320: aload_1
     321: checkcast     #18                 // class java/lang/Iterable
     324: astore        13
     326: iconst_0
     327: istore        14
     329: aload         13
     331: instanceof    #32                 // class java/util/Collection
     334: ifeq          354
     337: aload         13
     339: checkcast     #32                 // class java/util/Collection
     342: invokeinterface #207,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     347: ifeq          354
     350: iconst_0
     351: goto          421
     354: iconst_0
     355: istore        15
     357: aload         13
     359: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     364: astore        16
     366: aload         16
     368: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     373: ifeq          419
     376: aload         16
     378: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     383: astore        17
     385: aload         17
     387: checkcast     #48                 // class java/lang/String
     390: astore        18
     392: iconst_0
     393: istore        19
     395: aload         18
     397: aload         11
     399: invokestatic  #211                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     402: ifeq          366
     405: iinc          15, 1
     408: iload         15
     410: ifge          366
     413: invokestatic  #214                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     416: goto          366
     419: iload         15
     421: nop
     422: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     425: aload         22
     427: swap
     428: aload         10
     430: invokeinterface #107,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     435: pop
     436: goto          287
     439: aload         7
     441: nop
     442: astore_2
     443: aload_2
     444: iconst_1
     445: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     448: invokeinterface #119,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     453: dup
     454: invokestatic  #123                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     457: checkcast     #48                 // class java/lang/String
     460: areturn

  public static final year_2017.day07.Program parse(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #175                // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #179                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #48                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #240                // String ->
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #244                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_2
      30: iconst_0
      31: istore_3
      32: aload_2
      33: invokestatic  #248                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      36: checkcast     #179                // class java/lang/CharSequence
      39: iconst_1
      40: anewarray     #48                 // class java/lang/String
      43: astore        4
      45: aload         4
      47: iconst_0
      48: ldc           #250                // String  (
      50: aastore
      51: aload         4
      53: iconst_0
      54: iconst_0
      55: bipush        6
      57: aconst_null
      58: invokestatic  #244                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      61: astore        5
      63: aload         5
      65: invokestatic  #248                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      68: checkcast     #48                 // class java/lang/String
      71: checkcast     #179                // class java/lang/CharSequence
      74: invokestatic  #185                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      77: invokevirtual #188                // Method java/lang/Object.toString:()Ljava/lang/String;
      80: astore        4
      82: aload         5
      84: invokestatic  #253                // Method UtilsKt.second:(Ljava/util/List;)Ljava/lang/Object;
      87: checkcast     #48                 // class java/lang/String
      90: checkcast     #179                // class java/lang/CharSequence
      93: invokestatic  #185                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      96: invokevirtual #188                // Method java/lang/Object.toString:()Ljava/lang/String;
      99: iconst_1
     100: invokestatic  #257                // Method kotlin/text/StringsKt.dropLast:(Ljava/lang/String;I)Ljava/lang/String;
     103: invokestatic  #261                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     106: istore        6
     108: aload_2
     109: invokeinterface #265,  1          // InterfaceMethod java/util/List.size:()I
     114: iconst_1
     115: if_icmple     160
     118: aload_2
     119: invokestatic  #253                // Method UtilsKt.second:(Ljava/util/List;)Ljava/lang/Object;
     122: checkcast     #179                // class java/lang/CharSequence
     125: iconst_1
     126: anewarray     #48                 // class java/lang/String
     129: astore        7
     131: aload         7
     133: iconst_0
     134: ldc_w         #267                // String ,
     137: checkcast     #179                // class java/lang/CharSequence
     140: invokestatic  #185                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     143: invokevirtual #188                // Method java/lang/Object.toString:()Ljava/lang/String;
     146: aastore
     147: aload         7
     149: iconst_0
     150: iconst_0
     151: bipush        6
     153: aconst_null
     154: invokestatic  #244                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     157: goto          163
     160: invokestatic  #270                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     163: astore        8
     165: aload         4
     167: checkcast     #179                // class java/lang/CharSequence
     170: invokestatic  #185                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     173: invokevirtual #188                // Method java/lang/Object.toString:()Ljava/lang/String;
     176: iload         6
     178: aload         8
     180: checkcast     #18                 // class java/lang/Iterable
     183: astore        7
     185: istore        9
     187: astore        10
     189: iconst_0
     190: istore        11
     192: aload         7
     194: astore        12
     196: new           #20                 // class java/util/ArrayList
     199: dup
     200: aload         7
     202: bipush        10
     204: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     207: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     210: checkcast     #32                 // class java/util/Collection
     213: astore        13
     215: iconst_0
     216: istore        14
     218: aload         12
     220: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     225: astore        15
     227: aload         15
     229: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     234: ifeq          284
     237: aload         15
     239: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     244: astore        16
     246: aload         13
     248: aload         16
     250: checkcast     #48                 // class java/lang/String
     253: astore        17
     255: astore        18
     257: iconst_0
     258: istore        19
     260: aload         17
     262: checkcast     #179                // class java/lang/CharSequence
     265: invokestatic  #185                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     268: invokevirtual #188                // Method java/lang/Object.toString:()Ljava/lang/String;
     271: nop
     272: aload         18
     274: swap
     275: invokeinterface #56,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     280: pop
     281: goto          227
     284: aload         13
     286: checkcast     #58                 // class java/util/List
     289: nop
     290: astore        18
     292: aload         10
     294: iload         9
     296: aload         18
     298: astore        20
     300: istore        21
     302: astore        22
     304: new           #99                 // class year_2017/day07/Program
     307: dup
     308: aload         22
     310: iload         21
     312: aload         20
     314: invokespecial #273                // Method year_2017/day07/Program."<init>":(Ljava/lang/String;ILjava/util/List;)V
     317: nop
     318: areturn

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

  static {};
    Code:
       0: invokestatic  #289                // Method kotlin/collections/MapsKt.emptyMap:()Ljava/util/Map;
       3: putstatic     #115                // Field allPrograms:Ljava/util/Map;
       6: return
}


package year_2017.day23

import readInput
import second

val registers = mutableMapOf(
    'a' to 0,
    'b' to 0,
    'c' to 0,
    'd' to 0,
    'e' to 0,
    'f' to 0,
    'g' to 0,
    'h' to 0,
)

fun part1(input: List<String>): Int {
    val instructions = input.map(String::toInstruction)
    return runInstructions(instructions)
}

private fun runInstructions(instructions: List<Instruction>): Int {
    var counter = 0
    var index = 0
    while (index in instructions.indices) {
        print("index $index, counter $counter \r")
        val instruction = instructions[index]
        when (instruction.command) {
            "set" -> {
                registers[instruction.x] = if (instruction.yIsNumber()) instruction.y.toInt() else registers[instruction.y.first()]!!
                index++
            }

            "sub" -> {
                registers[instruction.x] =
                    registers[instruction.x]!! - if (instruction.yIsNumber()) instruction.y.toInt() else registers[instruction.y.first()]!!
                index++
            }

            "mul" -> {
                registers[instruction.x] =
                    registers[instruction.x]!! * if (instruction.yIsNumber()) instruction.y.toInt() else registers[instruction.y.first()]!!
                counter++
                index++
            }

            "jnz" -> {
                val v = if (instruction.x.isDigit()) instruction.x.digitToInt() else registers[instruction.x]!!
                if (v != 0) index += instruction.y.toInt()
                else index++
            }

            else -> error("unknown instruction ${instruction.command}")
        }
    }
    return counter
}

fun part2(input: List<String>): Int {
    val start = input.first().split(" ")[2].toInt() * 100 + 100000
    return (start..start + 17000 step 17).count {
        !it.toBigInteger().isProbablePrime(5)
    }
}

fun main() {
    val input = readInput("main/year_2017/day23/Day23")
    println(part1(input))
    println(part2(input))
}

fun String.toInstruction(): Instruction {
    return this.split(" ").let {
        Instruction(command = it.first(), x = it.second().first(), y = it[2])
    }
}

data class Instruction(val command: String, val x: Char, val y: String) {
    fun yIsNumber() = y.first().isDigit() || y.first() == '-'
}

Compiled from "day23.kt"
public final class year_2017.day23.Day23Kt {
  private static final java.util.Map<java.lang.Character, java.lang.Integer> registers;

  public static final java.util.Map<java.lang.Character, java.lang.Integer> getRegisters();
    Code:
       0: getstatic     #12                 // Field registers:Ljava/util/Map;
       3: areturn

  public static final int part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #17                 // String input
       3: invokestatic  #23                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #25                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #27                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #33                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #37                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #39                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          96
      56: aload         7
      58: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #55                 // class java/lang/String
      72: astore        9
      74: astore        11
      76: iconst_0
      77: istore        10
      79: aload         9
      81: invokestatic  #59                 // Method toInstruction:(Ljava/lang/String;)Lyear_2017/day23/Instruction;
      84: aload         11
      86: swap
      87: invokeinterface #63,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      92: pop
      93: goto          46
      96: aload         5
      98: checkcast     #65                 // class java/util/List
     101: nop
     102: astore_1
     103: aload_1
     104: invokestatic  #68                 // Method runInstructions:(Ljava/util/List;)I
     107: ireturn

  private static final int runInstructions(java.util.List<year_2017.day23.Instruction>);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_0
       3: istore_2
       4: iconst_0
       5: iload_2
       6: if_icmpgt     30
       9: iload_2
      10: aload_0
      11: checkcast     #39                 // class java/util/Collection
      14: invokeinterface #88,  1           // InterfaceMethod java/util/Collection.size:()I
      19: if_icmpge     26
      22: iconst_1
      23: goto          31
      26: iconst_0
      27: goto          31
      30: iconst_0
      31: ifeq          580
      34: new           #90                 // class java/lang/StringBuilder
      37: dup
      38: invokespecial #93                 // Method java/lang/StringBuilder."<init>":()V
      41: ldc           #95                 // String index
      43: invokevirtual #99                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      46: iload_2
      47: invokevirtual #102                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      50: ldc           #104                // String , counter
      52: invokevirtual #99                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      55: iload_1
      56: invokevirtual #102                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      59: ldc           #106                // String  \r
      61: invokevirtual #99                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      64: invokevirtual #110                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      67: getstatic     #116                // Field java/lang/System.out:Ljava/io/PrintStream;
      70: swap
      71: invokevirtual #122                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      74: aload_0
      75: iload_2
      76: invokeinterface #126,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      81: checkcast     #128                // class year_2017/day23/Instruction
      84: astore_3
      85: aload_3
      86: invokevirtual #131                // Method year_2017/day23/Instruction.getCommand:()Ljava/lang/String;
      89: astore        4
      91: aload         4
      93: invokevirtual #134                // Method java/lang/String.hashCode:()I
      96: lookupswitch  { // 4
                105398: 179
                108484: 166
                113762: 153
                114240: 140
               default: 547
          }
     140: aload         4
     142: ldc           #136                // String sub
     144: invokevirtual #139                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     147: ifne          267
     150: goto          547
     153: aload         4
     155: ldc           #141                // String set
     157: invokevirtual #139                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     160: ifne          192
     163: goto          547
     166: aload         4
     168: ldc           #143                // String mul
     170: invokevirtual #139                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     173: ifne          369
     176: goto          547
     179: aload         4
     181: ldc           #145                // String jnz
     183: invokevirtual #139                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     186: ifne          474
     189: goto          547
     192: getstatic     #12                 // Field registers:Ljava/util/Map;
     195: aload_3
     196: invokevirtual #149                // Method year_2017/day23/Instruction.getX:()C
     199: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     202: aload_3
     203: invokevirtual #158                // Method year_2017/day23/Instruction.yIsNumber:()Z
     206: ifeq          219
     209: aload_3
     210: invokevirtual #161                // Method year_2017/day23/Instruction.getY:()Ljava/lang/String;
     213: invokestatic  #167                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     216: goto          250
     219: getstatic     #12                 // Field registers:Ljava/util/Map;
     222: aload_3
     223: invokevirtual #161                // Method year_2017/day23/Instruction.getY:()Ljava/lang/String;
     226: checkcast     #169                // class java/lang/CharSequence
     229: invokestatic  #175                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     232: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     235: invokeinterface #180,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     240: dup
     241: invokestatic  #183                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     244: checkcast     #185                // class java/lang/Number
     247: invokevirtual #188                // Method java/lang/Number.intValue:()I
     250: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     253: invokeinterface #195,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     258: pop
     259: iload_2
     260: iinc          2, 1
     263: pop
     264: goto          4
     267: nop
     268: getstatic     #12                 // Field registers:Ljava/util/Map;
     271: aload_3
     272: invokevirtual #149                // Method year_2017/day23/Instruction.getX:()C
     275: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     278: getstatic     #12                 // Field registers:Ljava/util/Map;
     281: aload_3
     282: invokevirtual #149                // Method year_2017/day23/Instruction.getX:()C
     285: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     288: invokeinterface #180,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     293: dup
     294: invokestatic  #183                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     297: checkcast     #185                // class java/lang/Number
     300: invokevirtual #188                // Method java/lang/Number.intValue:()I
     303: aload_3
     304: invokevirtual #158                // Method year_2017/day23/Instruction.yIsNumber:()Z
     307: ifeq          320
     310: aload_3
     311: invokevirtual #161                // Method year_2017/day23/Instruction.getY:()Ljava/lang/String;
     314: invokestatic  #167                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     317: goto          351
     320: getstatic     #12                 // Field registers:Ljava/util/Map;
     323: aload_3
     324: invokevirtual #161                // Method year_2017/day23/Instruction.getY:()Ljava/lang/String;
     327: checkcast     #169                // class java/lang/CharSequence
     330: invokestatic  #175                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     333: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     336: invokeinterface #180,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     341: dup
     342: invokestatic  #183                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     345: checkcast     #185                // class java/lang/Number
     348: invokevirtual #188                // Method java/lang/Number.intValue:()I
     351: isub
     352: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     355: invokeinterface #195,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     360: pop
     361: iload_2
     362: iinc          2, 1
     365: pop
     366: goto          4
     369: nop
     370: getstatic     #12                 // Field registers:Ljava/util/Map;
     373: aload_3
     374: invokevirtual #149                // Method year_2017/day23/Instruction.getX:()C
     377: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     380: getstatic     #12                 // Field registers:Ljava/util/Map;
     383: aload_3
     384: invokevirtual #149                // Method year_2017/day23/Instruction.getX:()C
     387: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     390: invokeinterface #180,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     395: dup
     396: invokestatic  #183                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     399: checkcast     #185                // class java/lang/Number
     402: invokevirtual #188                // Method java/lang/Number.intValue:()I
     405: aload_3
     406: invokevirtual #158                // Method year_2017/day23/Instruction.yIsNumber:()Z
     409: ifeq          422
     412: aload_3
     413: invokevirtual #161                // Method year_2017/day23/Instruction.getY:()Ljava/lang/String;
     416: invokestatic  #167                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     419: goto          453
     422: getstatic     #12                 // Field registers:Ljava/util/Map;
     425: aload_3
     426: invokevirtual #161                // Method year_2017/day23/Instruction.getY:()Ljava/lang/String;
     429: checkcast     #169                // class java/lang/CharSequence
     432: invokestatic  #175                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     435: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     438: invokeinterface #180,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     443: dup
     444: invokestatic  #183                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     447: checkcast     #185                // class java/lang/Number
     450: invokevirtual #188                // Method java/lang/Number.intValue:()I
     453: imul
     454: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     457: invokeinterface #195,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     462: pop
     463: iinc          1, 1
     466: iload_2
     467: iinc          2, 1
     470: pop
     471: goto          4
     474: aload_3
     475: invokevirtual #149                // Method year_2017/day23/Instruction.getX:()C
     478: invokestatic  #199                // Method java/lang/Character.isDigit:(C)Z
     481: ifeq          494
     484: aload_3
     485: invokevirtual #149                // Method year_2017/day23/Instruction.getX:()C
     488: invokestatic  #205                // Method kotlin/text/CharsKt.digitToInt:(C)I
     491: goto          519
     494: getstatic     #12                 // Field registers:Ljava/util/Map;
     497: aload_3
     498: invokevirtual #149                // Method year_2017/day23/Instruction.getX:()C
     501: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     504: invokeinterface #180,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     509: dup
     510: invokestatic  #183                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     513: checkcast     #185                // class java/lang/Number
     516: invokevirtual #188                // Method java/lang/Number.intValue:()I
     519: istore        5
     521: iload         5
     523: ifeq          539
     526: iload_2
     527: aload_3
     528: invokevirtual #161                // Method year_2017/day23/Instruction.getY:()Ljava/lang/String;
     531: invokestatic  #167                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     534: iadd
     535: istore_2
     536: goto          4
     539: iload_2
     540: iinc          2, 1
     543: pop
     544: goto          4
     547: new           #207                // class java/lang/IllegalStateException
     550: dup
     551: new           #90                 // class java/lang/StringBuilder
     554: dup
     555: invokespecial #93                 // Method java/lang/StringBuilder."<init>":()V
     558: ldc           #209                // String unknown instruction
     560: invokevirtual #99                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     563: aload_3
     564: invokevirtual #131                // Method year_2017/day23/Instruction.getCommand:()Ljava/lang/String;
     567: invokevirtual #99                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     570: invokevirtual #110                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     573: invokevirtual #210                // Method java/lang/Object.toString:()Ljava/lang/String;
     576: invokespecial #213                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     579: athrow
     580: iload_1
     581: ireturn

  public static final int part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #17                 // String input
       3: invokestatic  #23                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #222                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      10: checkcast     #169                // class java/lang/CharSequence
      13: iconst_1
      14: anewarray     #55                 // class java/lang/String
      17: astore_2
      18: aload_2
      19: iconst_0
      20: ldc           #224                // String
      22: aastore
      23: aload_2
      24: iconst_0
      25: iconst_0
      26: bipush        6
      28: aconst_null
      29: invokestatic  #228                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      32: iconst_2
      33: invokeinterface #126,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      38: checkcast     #55                 // class java/lang/String
      41: invokestatic  #167                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      44: bipush        100
      46: imul
      47: ldc           #229                // int 100000
      49: iadd
      50: istore_1
      51: new           #231                // class kotlin/ranges/IntRange
      54: dup
      55: iload_1
      56: iload_1
      57: sipush        17000
      60: iadd
      61: invokespecial #234                // Method kotlin/ranges/IntRange."<init>":(II)V
      64: checkcast     #236                // class kotlin/ranges/IntProgression
      67: bipush        17
      69: invokestatic  #242                // Method kotlin/ranges/RangesKt.step:(Lkotlin/ranges/IntProgression;I)Lkotlin/ranges/IntProgression;
      72: checkcast     #25                 // class java/lang/Iterable
      75: astore_2
      76: iconst_0
      77: istore_3
      78: aload_2
      79: instanceof    #39                 // class java/util/Collection
      82: ifeq          101
      85: aload_2
      86: checkcast     #39                 // class java/util/Collection
      89: invokeinterface #245,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      94: ifeq          101
      97: iconst_0
      98: goto          183
     101: iconst_0
     102: istore        4
     104: aload_2
     105: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     110: astore        5
     112: aload         5
     114: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     119: ifeq          181
     122: aload         5
     124: checkcast     #247                // class kotlin/collections/IntIterator
     127: invokevirtual #250                // Method kotlin/collections/IntIterator.nextInt:()I
     130: istore        6
     132: iload         6
     134: istore        7
     136: iconst_0
     137: istore        8
     139: iload         7
     141: i2l
     142: invokestatic  #255                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     145: dup
     146: ldc_w         #257                // String valueOf(...)
     149: invokestatic  #260                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     152: iconst_5
     153: invokevirtual #264                // Method java/math/BigInteger.isProbablePrime:(I)Z
     156: ifne          163
     159: iconst_1
     160: goto          164
     163: iconst_0
     164: ifeq          112
     167: iinc          4, 1
     170: iload         4
     172: ifge          112
     175: invokestatic  #267                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     178: goto          112
     181: iload         4
     183: ireturn

  public static final void main();
    Code:
       0: ldc_w         #277                // String main/year_2017/day23/Day23
       3: invokestatic  #283                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       6: astore_0
       7: aload_0
       8: invokestatic  #285                // Method part1:(Ljava/util/List;)I
      11: istore_1
      12: getstatic     #116                // Field java/lang/System.out:Ljava/io/PrintStream;
      15: iload_1
      16: invokevirtual #288                // Method java/io/PrintStream.println:(I)V
      19: aload_0
      20: invokestatic  #290                // Method part2:(Ljava/util/List;)I
      23: istore_1
      24: getstatic     #116                // Field java/lang/System.out:Ljava/io/PrintStream;
      27: iload_1
      28: invokevirtual #288                // Method java/io/PrintStream.println:(I)V
      31: return

  public static final year_2017.day23.Instruction toInstruction(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #292                // String <this>
       4: invokestatic  #23                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #169                // class java/lang/CharSequence
      11: iconst_1
      12: anewarray     #55                 // class java/lang/String
      15: astore_1
      16: aload_1
      17: iconst_0
      18: ldc           #224                // String
      20: aastore
      21: aload_1
      22: iconst_0
      23: iconst_0
      24: bipush        6
      26: aconst_null
      27: invokestatic  #228                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      30: astore_2
      31: iconst_0
      32: istore_3
      33: new           #128                // class year_2017/day23/Instruction
      36: dup
      37: aload_2
      38: invokestatic  #222                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      41: checkcast     #55                 // class java/lang/String
      44: aload_2
      45: invokestatic  #295                // Method UtilsKt.second:(Ljava/util/List;)Ljava/lang/Object;
      48: checkcast     #169                // class java/lang/CharSequence
      51: invokestatic  #175                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
      54: aload_2
      55: iconst_2
      56: invokeinterface #126,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      61: checkcast     #55                 // class java/lang/String
      64: invokespecial #298                // Method year_2017/day23/Instruction."<init>":(Ljava/lang/String;CLjava/lang/String;)V
      67: nop
      68: areturn

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

  static {};
    Code:
       0: bipush        8
       2: anewarray     #308                // class kotlin/Pair
       5: astore_0
       6: aload_0
       7: iconst_0
       8: bipush        97
      10: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      13: iconst_0
      14: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      20: aastore
      21: aload_0
      22: iconst_1
      23: bipush        98
      25: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      28: iconst_0
      29: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      35: aastore
      36: aload_0
      37: iconst_2
      38: bipush        99
      40: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      43: iconst_0
      44: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      50: aastore
      51: aload_0
      52: iconst_3
      53: bipush        100
      55: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      58: iconst_0
      59: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      62: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      65: aastore
      66: aload_0
      67: iconst_4
      68: bipush        101
      70: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      73: iconst_0
      74: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      77: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      80: aastore
      81: aload_0
      82: iconst_5
      83: bipush        102
      85: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      88: iconst_0
      89: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      92: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      95: aastore
      96: aload_0
      97: bipush        6
      99: bipush        103
     101: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     104: iconst_0
     105: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     111: aastore
     112: aload_0
     113: bipush        7
     115: bipush        104
     117: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     120: iconst_0
     121: invokestatic  #191                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     124: invokestatic  #314                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     127: aastore
     128: aload_0
     129: invokestatic  #320                // Method kotlin/collections/MapsKt.mutableMapOf:([Lkotlin/Pair;)Ljava/util/Map;
     132: putstatic     #12                 // Field registers:Ljava/util/Map;
     135: return
}


package year_2017.day02

import readInput

fun part1(input: List<String>): Int = input.map { line ->
    line.split(" ").map { it.toInt() }.sortedDescending()
}.sumOf { it.first() - it.last() }

fun part2(input: List<String>): Int = input.map { line ->
    line.split(" ").map { it.toInt() }.sortedDescending()
}.sumOf { line ->
    line.findDivisionResult()
}

fun main() {
    val input = readInput("main/year_2017/day02/Day02")
    println(part1(input))
    println(part2(input))
}

fun List<Int>.findDivisionResult(): Int {
    forEachIndexed { index, candidate ->
        (index + 1 until size).forEach {
            if (candidate % this[it] == 0) return candidate / this[it]
        }
    }
    error("no even division found")
}

Compiled from "day03.kt"
public final class year_2017.day02.Day03Kt {
  public static final int part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #20                 // class java/util/ArrayList
      18: dup
      19: aload_1
      20: bipush        10
      22: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      25: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      28: checkcast     #32                 // class java/util/Collection
      31: astore        4
      33: iconst_0
      34: istore        5
      36: aload_3
      37: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        6
      44: aload         6
      46: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          225
      54: aload         6
      56: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        7
      63: aload         4
      65: aload         7
      67: checkcast     #48                 // class java/lang/String
      70: astore        8
      72: astore        20
      74: iconst_0
      75: istore        9
      77: aload         8
      79: checkcast     #50                 // class java/lang/CharSequence
      82: iconst_1
      83: anewarray     #48                 // class java/lang/String
      86: astore        10
      88: aload         10
      90: iconst_0
      91: ldc           #52                 // String
      93: aastore
      94: aload         10
      96: iconst_0
      97: iconst_0
      98: bipush        6
     100: aconst_null
     101: invokestatic  #58                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     104: checkcast     #18                 // class java/lang/Iterable
     107: astore        10
     109: iconst_0
     110: istore        11
     112: aload         10
     114: astore        12
     116: new           #20                 // class java/util/ArrayList
     119: dup
     120: aload         10
     122: bipush        10
     124: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     127: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     130: checkcast     #32                 // class java/util/Collection
     133: astore        13
     135: iconst_0
     136: istore        14
     138: aload         12
     140: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     145: astore        15
     147: aload         15
     149: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     154: ifeq          201
     157: aload         15
     159: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     164: astore        16
     166: aload         13
     168: aload         16
     170: checkcast     #48                 // class java/lang/String
     173: astore        17
     175: astore        18
     177: iconst_0
     178: istore        19
     180: aload         17
     182: invokestatic  #64                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     185: nop
     186: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     189: aload         18
     191: swap
     192: invokeinterface #72,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     197: pop
     198: goto          147
     201: aload         13
     203: checkcast     #74                 // class java/util/List
     206: nop
     207: checkcast     #18                 // class java/lang/Iterable
     210: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     213: aload         20
     215: swap
     216: invokeinterface #72,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     221: pop
     222: goto          44
     225: aload         4
     227: checkcast     #74                 // class java/util/List
     230: nop
     231: checkcast     #18                 // class java/lang/Iterable
     234: astore_1
     235: iconst_0
     236: istore_2
     237: aload_1
     238: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     243: astore_3
     244: aload_3
     245: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     250: ifeq          308
     253: aload_3
     254: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     259: astore        4
     261: iload_2
     262: aload         4
     264: checkcast     #74                 // class java/util/List
     267: astore        5
     269: istore        20
     271: iconst_0
     272: istore        6
     274: aload         5
     276: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     279: checkcast     #84                 // class java/lang/Number
     282: invokevirtual #88                 // Method java/lang/Number.intValue:()I
     285: aload         5
     287: invokestatic  #91                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     290: checkcast     #84                 // class java/lang/Number
     293: invokevirtual #88                 // Method java/lang/Number.intValue:()I
     296: isub
     297: istore        21
     299: iload         20
     301: iload         21
     303: iadd
     304: istore_2
     305: goto          244
     308: iload_2
     309: ireturn

  public static final int part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #20                 // class java/util/ArrayList
      18: dup
      19: aload_1
      20: bipush        10
      22: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      25: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      28: checkcast     #32                 // class java/util/Collection
      31: astore        4
      33: iconst_0
      34: istore        5
      36: aload_3
      37: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        6
      44: aload         6
      46: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          225
      54: aload         6
      56: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        7
      63: aload         4
      65: aload         7
      67: checkcast     #48                 // class java/lang/String
      70: astore        8
      72: astore        20
      74: iconst_0
      75: istore        9
      77: aload         8
      79: checkcast     #50                 // class java/lang/CharSequence
      82: iconst_1
      83: anewarray     #48                 // class java/lang/String
      86: astore        10
      88: aload         10
      90: iconst_0
      91: ldc           #52                 // String
      93: aastore
      94: aload         10
      96: iconst_0
      97: iconst_0
      98: bipush        6
     100: aconst_null
     101: invokestatic  #58                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     104: checkcast     #18                 // class java/lang/Iterable
     107: astore        10
     109: iconst_0
     110: istore        11
     112: aload         10
     114: astore        12
     116: new           #20                 // class java/util/ArrayList
     119: dup
     120: aload         10
     122: bipush        10
     124: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     127: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     130: checkcast     #32                 // class java/util/Collection
     133: astore        13
     135: iconst_0
     136: istore        14
     138: aload         12
     140: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     145: astore        15
     147: aload         15
     149: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     154: ifeq          201
     157: aload         15
     159: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     164: astore        16
     166: aload         13
     168: aload         16
     170: checkcast     #48                 // class java/lang/String
     173: astore        17
     175: astore        18
     177: iconst_0
     178: istore        19
     180: aload         17
     182: invokestatic  #64                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     185: nop
     186: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     189: aload         18
     191: swap
     192: invokeinterface #72,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     197: pop
     198: goto          147
     201: aload         13
     203: checkcast     #74                 // class java/util/List
     206: nop
     207: checkcast     #18                 // class java/lang/Iterable
     210: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     213: aload         20
     215: swap
     216: invokeinterface #72,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     221: pop
     222: goto          44
     225: aload         4
     227: checkcast     #74                 // class java/util/List
     230: nop
     231: checkcast     #18                 // class java/lang/Iterable
     234: astore_1
     235: iconst_0
     236: istore_2
     237: aload_1
     238: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     243: astore_3
     244: aload_3
     245: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     250: ifeq          290
     253: aload_3
     254: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     259: astore        4
     261: iload_2
     262: aload         4
     264: checkcast     #74                 // class java/util/List
     267: astore        5
     269: istore        20
     271: iconst_0
     272: istore        6
     274: aload         5
     276: invokestatic  #112                // Method findDivisionResult:(Ljava/util/List;)I
     279: istore        21
     281: iload         20
     283: iload         21
     285: iadd
     286: istore_2
     287: goto          244
     290: iload_2
     291: ireturn

  public static final void main();
    Code:
       0: ldc           #119                // String main/year_2017/day02/Day02
       2: invokestatic  #125                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #127                // Method part1:(Ljava/util/List;)I
      10: istore_1
      11: getstatic     #133                // Field java/lang/System.out:Ljava/io/PrintStream;
      14: iload_1
      15: invokevirtual #138                // Method java/io/PrintStream.println:(I)V
      18: aload_0
      19: invokestatic  #140                // Method part2:(Ljava/util/List;)I
      22: istore_1
      23: getstatic     #133                // Field java/lang/System.out:Ljava/io/PrintStream;
      26: iload_1
      27: invokevirtual #138                // Method java/io/PrintStream.println:(I)V
      30: return

  public static final int findDivisionResult(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #143                // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: iconst_0
      14: istore_3
      15: aload_1
      16: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      21: astore        4
      23: aload         4
      25: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          179
      33: aload         4
      35: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      40: astore        5
      42: iload_3
      43: iinc          3, 1
      46: istore        6
      48: iload         6
      50: ifge          56
      53: invokestatic  #146                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      56: iload         6
      58: aload         5
      60: checkcast     #84                 // class java/lang/Number
      63: invokevirtual #88                 // Method java/lang/Number.intValue:()I
      66: istore        7
      68: istore        8
      70: iconst_0
      71: istore        9
      73: iload         8
      75: iconst_1
      76: iadd
      77: aload_0
      78: invokeinterface #149,  1          // InterfaceMethod java/util/List.size:()I
      83: invokestatic  #155                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      86: checkcast     #18                 // class java/lang/Iterable
      89: astore        10
      91: iconst_0
      92: istore        11
      94: aload         10
      96: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     101: astore        12
     103: aload         12
     105: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     110: ifeq          173
     113: aload         12
     115: checkcast     #157                // class kotlin/collections/IntIterator
     118: invokevirtual #160                // Method kotlin/collections/IntIterator.nextInt:()I
     121: istore        13
     123: iload         13
     125: istore        14
     127: iconst_0
     128: istore        15
     130: iload         7
     132: aload_0
     133: iload         14
     135: invokeinterface #164,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     140: checkcast     #84                 // class java/lang/Number
     143: invokevirtual #88                 // Method java/lang/Number.intValue:()I
     146: irem
     147: ifne          168
     150: iload         7
     152: aload_0
     153: iload         14
     155: invokeinterface #164,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     160: checkcast     #84                 // class java/lang/Number
     163: invokevirtual #88                 // Method java/lang/Number.intValue:()I
     166: idiv
     167: ireturn
     168: nop
     169: nop
     170: goto          103
     173: nop
     174: nop
     175: nop
     176: goto          23
     179: nop
     180: new           #166                // class java/lang/IllegalStateException
     183: dup
     184: ldc           #168                // String no even division found
     186: invokevirtual #172                // Method java/lang/Object.toString:()Ljava/lang/String;
     189: invokespecial #175                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     192: athrow

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


package year_2017.day11

import kotlin.math.absoluteValue
import readInput

fun part1(input: List<String>): Int {

    val directions = input.first().split(",")

    val origin = HexPoint(0, 0, 0)
    val endPoint = directions.fold(origin) { point, dir ->
        point.step(dir)
    }
    return origin.distance(endPoint)
}

fun part2(input: List<String>): Int {
    val directions = input.first().split(",")
    val origin = HexPoint(0, 0, 0)
    val steps = mutableListOf(origin)

    directions.forEach { dir ->
        steps.add(steps.last().step(dir))
    }

    return steps.maxOf { it.distance(origin) }

}

fun main() {
    val input = readInput("main/year_2017/day11/Day11")
    println(part1(input))
    println(part2(input))
}

data class HexPoint(val x: Int, val y: Int, val z: Int) {

    fun step(direction: String): HexPoint =
        when (direction) {
            "n" -> HexPoint(x, y + 1, z - 1)
            "s" -> HexPoint(x, y - 1, z + 1)
            "ne" -> HexPoint(x + 1, y, z - 1)
            "nw" -> HexPoint(x - 1, y + 1, z)
            "se" -> HexPoint(x + 1, y - 1, z)
            "sw" -> HexPoint(x - 1, y, z + 1)
            else -> error("illegal direction")
        }

    fun distance(other: HexPoint): Int =
        maxOf(
            (this.x - other.x).absoluteValue,
            (this.y - other.y).absoluteValue,
            (this.z - other.z).absoluteValue
        )
}

Compiled from "day11.kt"
public final class year_2017.day11.Day11Kt {
  public static final int part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      10: checkcast     #24                 // class java/lang/CharSequence
      13: iconst_1
      14: anewarray     #26                 // class java/lang/String
      17: astore_2
      18: aload_2
      19: iconst_0
      20: ldc           #28                 // String ,
      22: aastore
      23: aload_2
      24: iconst_0
      25: iconst_0
      26: bipush        6
      28: aconst_null
      29: invokestatic  #34                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      32: astore_1
      33: new           #36                 // class year_2017/day11/HexPoint
      36: dup
      37: iconst_0
      38: iconst_0
      39: iconst_0
      40: invokespecial #40                 // Method year_2017/day11/HexPoint."<init>":(III)V
      43: astore_2
      44: aload_1
      45: checkcast     #42                 // class java/lang/Iterable
      48: astore        4
      50: iconst_0
      51: istore        5
      53: aload_2
      54: astore        6
      56: aload         4
      58: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        7
      65: aload         7
      67: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          110
      75: aload         7
      77: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: astore        8
      84: aload         6
      86: aload         8
      88: checkcast     #26                 // class java/lang/String
      91: astore        9
      93: astore        10
      95: iconst_0
      96: istore        11
      98: aload         10
     100: aload         9
     102: invokevirtual #60                 // Method year_2017/day11/HexPoint.step:(Ljava/lang/String;)Lyear_2017/day11/HexPoint;
     105: astore        6
     107: goto          65
     110: aload         6
     112: astore_3
     113: aload_2
     114: aload_3
     115: invokevirtual #64                 // Method year_2017/day11/HexPoint.distance:(Lyear_2017/day11/HexPoint;)I
     118: ireturn

  public static final int part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      10: checkcast     #24                 // class java/lang/CharSequence
      13: iconst_1
      14: anewarray     #26                 // class java/lang/String
      17: astore_2
      18: aload_2
      19: iconst_0
      20: ldc           #28                 // String ,
      22: aastore
      23: aload_2
      24: iconst_0
      25: iconst_0
      26: bipush        6
      28: aconst_null
      29: invokestatic  #34                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      32: astore_1
      33: new           #36                 // class year_2017/day11/HexPoint
      36: dup
      37: iconst_0
      38: iconst_0
      39: iconst_0
      40: invokespecial #40                 // Method year_2017/day11/HexPoint."<init>":(III)V
      43: astore_2
      44: iconst_1
      45: anewarray     #36                 // class year_2017/day11/HexPoint
      48: astore        4
      50: aload         4
      52: iconst_0
      53: aload_2
      54: aastore
      55: aload         4
      57: invokestatic  #87                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      60: astore_3
      61: aload_1
      62: checkcast     #42                 // class java/lang/Iterable
      65: astore        4
      67: iconst_0
      68: istore        5
      70: aload         4
      72: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      77: astore        6
      79: aload         6
      81: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      86: ifeq          132
      89: aload         6
      91: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      96: astore        7
      98: aload         7
     100: checkcast     #26                 // class java/lang/String
     103: astore        8
     105: iconst_0
     106: istore        9
     108: aload_3
     109: aload_3
     110: invokestatic  #90                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     113: checkcast     #36                 // class year_2017/day11/HexPoint
     116: aload         8
     118: invokevirtual #60                 // Method year_2017/day11/HexPoint.step:(Ljava/lang/String;)Lyear_2017/day11/HexPoint;
     121: invokeinterface #94,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     126: pop
     127: nop
     128: nop
     129: goto          79
     132: nop
     133: aload_3
     134: checkcast     #42                 // class java/lang/Iterable
     137: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     142: astore        5
     144: aload         5
     146: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     151: ifne          162
     154: new           #96                 // class java/util/NoSuchElementException
     157: dup
     158: invokespecial #99                 // Method java/util/NoSuchElementException."<init>":()V
     161: athrow
     162: aload         5
     164: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     169: checkcast     #36                 // class year_2017/day11/HexPoint
     172: astore        6
     174: iconst_0
     175: istore        7
     177: aload         6
     179: aload_2
     180: invokevirtual #64                 // Method year_2017/day11/HexPoint.distance:(Lyear_2017/day11/HexPoint;)I
     183: istore        6
     185: aload         5
     187: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     192: ifeq          232
     195: aload         5
     197: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     202: checkcast     #36                 // class year_2017/day11/HexPoint
     205: astore        7
     207: iconst_0
     208: istore        8
     210: aload         7
     212: aload_2
     213: invokevirtual #64                 // Method year_2017/day11/HexPoint.distance:(Lyear_2017/day11/HexPoint;)I
     216: istore        7
     218: iload         6
     220: iload         7
     222: if_icmpge     185
     225: iload         7
     227: istore        6
     229: goto          185
     232: iload         6
     234: ireturn

  public static final void main();
    Code:
       0: ldc           #108                // String main/year_2017/day11/Day11
       2: invokestatic  #114                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #116                // Method part1:(Ljava/util/List;)I
      10: istore_1
      11: getstatic     #122                // Field java/lang/System.out:Ljava/io/PrintStream;
      14: iload_1
      15: invokevirtual #128                // Method java/io/PrintStream.println:(I)V
      18: aload_0
      19: invokestatic  #130                // Method part2:(Ljava/util/List;)I
      22: istore_1
      23: getstatic     #122                // Field java/lang/System.out:Ljava/io/PrintStream;
      26: iload_1
      27: invokevirtual #128                // Method java/io/PrintStream.println:(I)V
      30: return

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