import Day10.Type.CLOSE
import Day10.Type.OPEN
import java.io.File
import java.nio.charset.Charset.defaultCharset
import java.util.Stack

object Day10 {
    data class Bracket(val bracketType: BracketType, val type: Type)

    enum class Type { OPEN, CLOSE }

    enum class BracketType(val open: Char, val close: Char, val points: Int, val autoCompleteScore: Int) {
        SQUARE('[', ']', 57, 2),
        ROUND('(', ')', 3, 1),
        BRACE('{', '}', 1197, 3),
        ANGLE('<', '>', 25137, 4);

        fun match(c: Char): Type? = when (c) {
            open -> OPEN
            close -> CLOSE
            else -> null
        }
    }

    fun String.toBrackets() = this.map { c ->
        BracketType.values().firstNotNullOf { b ->
            b.match(c)?.let { Bracket(b, it) }
        }
    }

    object Part1 {
        private fun findInvalid(brackets: List<Bracket>): BracketType? {
            val stack = Stack<Bracket>()
            brackets.forEach {
                if (it.type == CLOSE) {
                    val opening = stack.pop()
                    if (it.bracketType != opening.bracketType) {
                        return it.bracketType
                    }
                } else {
                    stack.push(it)
                }
            }
            return null
        }

        fun run() {
            File("day10/input-real.txt")
                .readLines(defaultCharset())
                .mapNotNull { findInvalid(it.toBrackets()) }
                .map { it.points }
                .reduce(Int::plus)
                .also { println(it) }
        }
    }

    object Part2 {
        private fun complete(brackets: List<Bracket>): Long? {
            val stack = Stack<Bracket>()
            brackets.forEach {
                if (it.type == CLOSE) {
                    val opening = stack.pop()
                    if (it.bracketType != opening.bracketType) {
                        return null
                    }
                } else {
                    stack.push(it)
                }
            }
            if (stack.isEmpty()) {
                return null
            }

            return stack.reversed().fold(0L) { acc, b -> (acc * 5) + b.bracketType.autoCompleteScore }
        }

        fun run() {
            File("day10/input-real.txt").readLines(defaultCharset())
                .mapNotNull { complete(it.toBrackets()) }
                .sorted()
                .also { println(it[it.size/2]) }
        }
    }
}

fun main() {
    Day10.Part1.run()
    Day10.Part2.run()
}

Compiled from "Day10.kt"
public final class Day10$BracketType extends java.lang.Enum<Day10$BracketType> {
  private final char open;

  private final char close;

  private final int points;

  private final int autoCompleteScore;

  public static final Day10$BracketType SQUARE;

  public static final Day10$BracketType ROUND;

  public static final Day10$BracketType BRACE;

  public static final Day10$BracketType ANGLE;

  private static final Day10$BracketType[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private Day10$BracketType(char, char, int, int);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #11                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: aload_0
       7: iload_3
       8: putfield      #15                 // Field open:C
      11: aload_0
      12: iload         4
      14: putfield      #18                 // Field close:C
      17: aload_0
      18: iload         5
      20: putfield      #22                 // Field points:I
      23: aload_0
      24: iload         6
      26: putfield      #25                 // Field autoCompleteScore:I
      29: return

  public final char getOpen();
    Code:
       0: aload_0
       1: getfield      #15                 // Field open:C
       4: ireturn

  public final char getClose();
    Code:
       0: aload_0
       1: getfield      #18                 // Field close:C
       4: ireturn

  public final int getPoints();
    Code:
       0: aload_0
       1: getfield      #22                 // Field points:I
       4: ireturn

  public final int getAutoCompleteScore();
    Code:
       0: aload_0
       1: getfield      #25                 // Field autoCompleteScore:I
       4: ireturn

  public final Day10$Type match(char);
    Code:
       0: iload_1
       1: istore_2
       2: iload_2
       3: aload_0
       4: getfield      #15                 // Field open:C
       7: if_icmpne     16
      10: getstatic     #45                 // Field Day10$Type.OPEN:LDay10$Type;
      13: goto          31
      16: iload_2
      17: aload_0
      18: getfield      #18                 // Field close:C
      21: if_icmpne     30
      24: getstatic     #48                 // Field Day10$Type.CLOSE:LDay10$Type;
      27: goto          31
      30: aconst_null
      31: areturn

  public static Day10$BracketType[] values();
    Code:
       0: getstatic     #55                 // Field $VALUES:[LDay10$BracketType;
       3: invokevirtual #61                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #62                 // class "[LDay10$BracketType;"
       9: areturn

  public static Day10$BracketType valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class Day10$BracketType
       2: aload_0
       3: invokestatic  #67                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class Day10$BracketType
       9: areturn

  public static kotlin.enums.EnumEntries<Day10$BracketType> getEntries();
    Code:
       0: getstatic     #76                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final Day10$BracketType[] $values();
    Code:
       0: iconst_4
       1: anewarray     #2                  // class Day10$BracketType
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #80                 // Field SQUARE:LDay10$BracketType;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #83                 // Field ROUND:LDay10$BracketType;
      16: aastore
      17: aload_0
      18: iconst_2
      19: getstatic     #86                 // Field BRACE:LDay10$BracketType;
      22: aastore
      23: aload_0
      24: iconst_3
      25: getstatic     #89                 // Field ANGLE:LDay10$BracketType;
      28: aastore
      29: aload_0
      30: areturn

  static {};
    Code:
       0: new           #2                  // class Day10$BracketType
       3: dup
       4: ldc           #92                 // String SQUARE
       6: iconst_0
       7: bipush        91
       9: bipush        93
      11: bipush        57
      13: iconst_2
      14: invokespecial #94                 // Method "<init>":(Ljava/lang/String;ICCII)V
      17: putstatic     #80                 // Field SQUARE:LDay10$BracketType;
      20: new           #2                  // class Day10$BracketType
      23: dup
      24: ldc           #95                 // String ROUND
      26: iconst_1
      27: bipush        40
      29: bipush        41
      31: iconst_3
      32: iconst_1
      33: invokespecial #94                 // Method "<init>":(Ljava/lang/String;ICCII)V
      36: putstatic     #83                 // Field ROUND:LDay10$BracketType;
      39: new           #2                  // class Day10$BracketType
      42: dup
      43: ldc           #96                 // String BRACE
      45: iconst_2
      46: bipush        123
      48: bipush        125
      50: sipush        1197
      53: iconst_3
      54: invokespecial #94                 // Method "<init>":(Ljava/lang/String;ICCII)V
      57: putstatic     #86                 // Field BRACE:LDay10$BracketType;
      60: new           #2                  // class Day10$BracketType
      63: dup
      64: ldc           #97                 // String ANGLE
      66: iconst_3
      67: bipush        60
      69: bipush        62
      71: sipush        25137
      74: iconst_4
      75: invokespecial #94                 // Method "<init>":(Ljava/lang/String;ICCII)V
      78: putstatic     #89                 // Field ANGLE:LDay10$BracketType;
      81: invokestatic  #99                 // Method $values:()[LDay10$BracketType;
      84: putstatic     #55                 // Field $VALUES:[LDay10$BracketType;
      87: getstatic     #55                 // Field $VALUES:[LDay10$BracketType;
      90: checkcast     #101                // class "[Ljava/lang/Enum;"
      93: invokestatic  #107                // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      96: putstatic     #76                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      99: return
}

Compiled from "Day10.kt"
public final class Day10$Bracket {
  private final Day10$BracketType bracketType;

  private final Day10$Type type;

  public Day10$Bracket(Day10$BracketType, Day10$Type);
    Code:
       0: aload_1
       1: ldc           #9                  // String bracketType
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #17                 // String type
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #20                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #23                 // Field bracketType:LDay10$BracketType;
      21: aload_0
      22: aload_2
      23: putfield      #26                 // Field type:LDay10$Type;
      26: return

  public final Day10$BracketType getBracketType();
    Code:
       0: aload_0
       1: getfield      #23                 // Field bracketType:LDay10$BracketType;
       4: areturn

  public final Day10$Type getType();
    Code:
       0: aload_0
       1: getfield      #26                 // Field type:LDay10$Type;
       4: areturn

  public final Day10$BracketType component1();
    Code:
       0: aload_0
       1: getfield      #23                 // Field bracketType:LDay10$BracketType;
       4: areturn

  public final Day10$Type component2();
    Code:
       0: aload_0
       1: getfield      #26                 // Field type:LDay10$Type;
       4: areturn

  public final Day10$Bracket copy(Day10$BracketType, Day10$Type);
    Code:
       0: aload_1
       1: ldc           #9                  // String bracketType
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #17                 // String type
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class Day10$Bracket
      15: dup
      16: aload_1
      17: aload_2
      18: invokespecial #38                 // Method "<init>":(LDay10$BracketType;LDay10$Type;)V
      21: areturn

  public static Day10$Bracket copy$default(Day10$Bracket, Day10$BracketType, Day10$Type, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #23                 // Field bracketType:LDay10$BracketType;
      10: astore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #26                 // Field type:LDay10$Type;
      21: astore_2
      22: aload_0
      23: aload_1
      24: aload_2
      25: invokevirtual #42                 // Method copy:(LDay10$BracketType;LDay10$Type;)LDay10$Bracket;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #46                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #47                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #49                 // String Bracket(bracketType=
       9: invokevirtual #53                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #23                 // Field bracketType:LDay10$BracketType;
      16: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: ldc           #58                 // String , type=
      21: invokevirtual #53                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #26                 // Field type:LDay10$Type;
      28: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #61                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #63                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #23                 // Field bracketType:LDay10$BracketType;
       4: invokevirtual #69                 // Method Day10$BracketType.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #26                 // Field type:LDay10$Type;
      16: invokevirtual #72                 // Method Day10$Type.hashCode:()I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class Day10$Bracket
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day10$Bracket
      20: astore_2
      21: aload_0
      22: getfield      #23                 // Field bracketType:LDay10$BracketType;
      25: aload_2
      26: getfield      #23                 // Field bracketType:LDay10$BracketType;
      29: if_acmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #26                 // Field type:LDay10$Type;
      38: aload_2
      39: getfield      #26                 // Field type:LDay10$Type;
      42: if_acmpeq     47
      45: iconst_0
      46: ireturn
      47: iconst_1
      48: ireturn
}

Compiled from "Day10.kt"
public final class Day10 {
  public static final Day10 INSTANCE;

  private Day10();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final java.util.List<Day10$Bracket> toBrackets(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #16                 // String <this>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #24                 // class java/lang/CharSequence
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #26                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: invokeinterface #30,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      26: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #35                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: iconst_0
      38: istore        7
      40: iload         7
      42: aload         4
      44: invokeinterface #30,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      49: if_icmpge     179
      52: aload         4
      54: iload         7
      56: invokeinterface #39,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      61: istore        8
      63: aload         5
      65: iload         8
      67: istore        9
      69: astore        18
      71: iconst_0
      72: istore        10
      74: invokestatic  #45                 // Method Day10$BracketType.values:()[LDay10$BracketType;
      77: astore        11
      79: iconst_0
      80: istore        12
      82: aload         11
      84: arraylength
      85: istore        13
      87: iload         12
      89: iload         13
      91: if_icmpge     147
      94: aload         11
      96: iload         12
      98: aaload
      99: astore        14
     101: iconst_0
     102: istore        15
     104: aload         14
     106: iload         9
     108: invokevirtual #49                 // Method Day10$BracketType.match:(C)LDay10$Type;
     111: dup
     112: ifnull        134
     115: astore        16
     117: iconst_0
     118: istore        17
     120: new           #51                 // class Day10$Bracket
     123: dup
     124: aload         14
     126: aload         16
     128: invokespecial #54                 // Method Day10$Bracket."<init>":(LDay10$BracketType;LDay10$Type;)V
     131: goto          136
     134: pop
     135: aconst_null
     136: dup
     137: ifnonnull     148
     140: pop
     141: iinc          12, 1
     144: goto          87
     147: aconst_null
     148: dup
     149: ifnonnull     163
     152: pop
     153: new           #56                 // class java/util/NoSuchElementException
     156: dup
     157: ldc           #58                 // String No element of the array was transformed to a non-null value.
     159: invokespecial #61                 // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     162: athrow
     163: nop
     164: aload         18
     166: swap
     167: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     172: pop
     173: iinc          7, 1
     176: goto          40
     179: aload         5
     181: checkcast     #67                 // class java/util/List
     184: nop
     185: areturn

  static {};
    Code:
       0: new           #2                  // class Day10
       3: dup
       4: invokespecial #95                 // Method "<init>":()V
       7: putstatic     #98                 // Field INSTANCE:LDay10;
      10: return
}

Compiled from "Day10.kt"
public final class Day10$Part1 {
  public static final Day10$Part1 INSTANCE;

  private Day10$Part1();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  private final Day10$BracketType findInvalid(java.util.List<Day10$Bracket>);
    Code:
       0: new           #15                 // class java/util/Stack
       3: dup
       4: invokespecial #16                 // Method java/util/Stack."<init>":()V
       7: astore_2
       8: aload_1
       9: checkcast     #18                 // class java/lang/Iterable
      12: astore_3
      13: iconst_0
      14: istore        4
      16: aload_3
      17: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore        5
      24: aload         5
      26: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      31: ifeq          104
      34: aload         5
      36: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      41: astore        6
      43: aload         6
      45: checkcast     #34                 // class Day10$Bracket
      48: astore        7
      50: iconst_0
      51: istore        8
      53: aload         7
      55: invokevirtual #38                 // Method Day10$Bracket.getType:()LDay10$Type;
      58: getstatic     #44                 // Field Day10$Type.CLOSE:LDay10$Type;
      61: if_acmpne     92
      64: aload_2
      65: invokevirtual #47                 // Method java/util/Stack.pop:()Ljava/lang/Object;
      68: checkcast     #34                 // class Day10$Bracket
      71: astore        9
      73: aload         7
      75: invokevirtual #51                 // Method Day10$Bracket.getBracketType:()LDay10$BracketType;
      78: aload         9
      80: invokevirtual #51                 // Method Day10$Bracket.getBracketType:()LDay10$BracketType;
      83: if_acmpeq     99
      86: aload         7
      88: invokevirtual #51                 // Method Day10$Bracket.getBracketType:()LDay10$BracketType;
      91: areturn
      92: aload_2
      93: aload         7
      95: invokevirtual #55                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
      98: pop
      99: nop
     100: nop
     101: goto          24
     104: nop
     105: aconst_null
     106: areturn

  public final void run();
    Code:
       0: new           #74                 // class java/io/File
       3: dup
       4: ldc           #76                 // String day10/input-real.txt
       6: invokespecial #79                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: invokestatic  #85                 // Method java/nio/charset/Charset.defaultCharset:()Ljava/nio/charset/Charset;
      12: dup
      13: ldc           #87                 // String defaultCharset(...)
      15: invokestatic  #93                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      18: invokestatic  #99                 // Method kotlin/io/FilesKt.readLines:(Ljava/io/File;Ljava/nio/charset/Charset;)Ljava/util/List;
      21: checkcast     #18                 // class java/lang/Iterable
      24: astore_1
      25: nop
      26: iconst_0
      27: istore_2
      28: aload_1
      29: astore_3
      30: new           #101                // class java/util/ArrayList
      33: dup
      34: invokespecial #102                // Method java/util/ArrayList."<init>":()V
      37: checkcast     #104                // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: astore        6
      48: iconst_0
      49: istore        7
      51: aload         6
      53: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        8
      60: aload         8
      62: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          137
      70: aload         8
      72: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        9
      79: aload         9
      81: astore        10
      83: iconst_0
      84: istore        11
      86: aload         10
      88: checkcast     #106                // class java/lang/String
      91: astore        12
      93: iconst_0
      94: istore        13
      96: getstatic     #109                // Field INSTANCE:LDay10$Part1;
      99: getstatic     #114                // Field Day10.INSTANCE:LDay10;
     102: aload         12
     104: invokevirtual #118                // Method Day10.toBrackets:(Ljava/lang/String;)Ljava/util/List;
     107: invokespecial #120                // Method findInvalid:(Ljava/util/List;)LDay10$BracketType;
     110: dup
     111: ifnull        132
     114: astore        14
     116: iconst_0
     117: istore        15
     119: aload         4
     121: aload         14
     123: invokeinterface #124,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     128: pop
     129: goto          133
     132: pop
     133: nop
     134: goto          60
     137: nop
     138: aload         4
     140: checkcast     #71                 // class java/util/List
     143: nop
     144: checkcast     #18                 // class java/lang/Iterable
     147: astore_1
     148: nop
     149: iconst_0
     150: istore_2
     151: aload_1
     152: astore_3
     153: new           #101                // class java/util/ArrayList
     156: dup
     157: aload_1
     158: bipush        10
     160: invokestatic  #130                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     163: invokespecial #133                // Method java/util/ArrayList."<init>":(I)V
     166: checkcast     #104                // class java/util/Collection
     169: astore        4
     171: iconst_0
     172: istore        5
     174: aload_3
     175: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     180: astore        6
     182: aload         6
     184: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     189: ifeq          235
     192: aload         6
     194: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     199: astore        7
     201: aload         4
     203: aload         7
     205: checkcast     #135                // class Day10$BracketType
     208: astore        8
     210: astore        16
     212: iconst_0
     213: istore        9
     215: aload         8
     217: invokevirtual #139                // Method Day10$BracketType.getPoints:()I
     220: invokestatic  #145                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     223: aload         16
     225: swap
     226: invokeinterface #124,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     231: pop
     232: goto          182
     235: aload         4
     237: checkcast     #71                 // class java/util/List
     240: nop
     241: checkcast     #18                 // class java/lang/Iterable
     244: astore_1
     245: nop
     246: iconst_0
     247: istore_2
     248: aload_1
     249: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     254: astore_3
     255: aload_3
     256: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     261: ifne          274
     264: new           #147                // class java/lang/UnsupportedOperationException
     267: dup
     268: ldc           #149                // String Empty collection can\'t be reduced.
     270: invokespecial #150                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     273: athrow
     274: aload_3
     275: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     280: astore        4
     282: aload_3
     283: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     288: ifeq          331
     291: aload         4
     293: aload_3
     294: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     299: checkcast     #152                // class java/lang/Number
     302: invokevirtual #155                // Method java/lang/Number.intValue:()I
     305: istore        5
     307: checkcast     #152                // class java/lang/Number
     310: invokevirtual #155                // Method java/lang/Number.intValue:()I
     313: istore        6
     315: iconst_0
     316: istore        7
     318: iload         6
     320: iload         5
     322: iadd
     323: invokestatic  #145                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     326: astore        4
     328: goto          282
     331: aload         4
     333: astore_1
     334: aload_1
     335: checkcast     #152                // class java/lang/Number
     338: invokevirtual #155                // Method java/lang/Number.intValue:()I
     341: istore_2
     342: iconst_0
     343: istore_3
     344: getstatic     #161                // Field java/lang/System.out:Ljava/io/PrintStream;
     347: iload_2
     348: invokevirtual #166                // Method java/io/PrintStream.println:(I)V
     351: nop
     352: nop
     353: return

  static {};
    Code:
       0: new           #2                  // class Day10$Part1
       3: dup
       4: invokespecial #198                // Method "<init>":()V
       7: putstatic     #109                // Field INSTANCE:LDay10$Part1;
      10: return
}

Compiled from "Day10.kt"
public final class Day10$Type extends java.lang.Enum<Day10$Type> {
  public static final Day10$Type OPEN;

  public static final Day10$Type CLOSE;

  private static final Day10$Type[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private Day10$Type();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #10                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: return

  public static Day10$Type[] values();
    Code:
       0: getstatic     #22                 // Field $VALUES:[LDay10$Type;
       3: invokevirtual #28                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #29                 // class "[LDay10$Type;"
       9: areturn

  public static Day10$Type valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class Day10$Type
       2: aload_0
       3: invokestatic  #34                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class Day10$Type
       9: areturn

  public static kotlin.enums.EnumEntries<Day10$Type> getEntries();
    Code:
       0: getstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final Day10$Type[] $values();
    Code:
       0: iconst_2
       1: anewarray     #2                  // class Day10$Type
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #47                 // Field OPEN:LDay10$Type;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #50                 // Field CLOSE:LDay10$Type;
      16: aastore
      17: aload_0
      18: areturn

  static {};
    Code:
       0: new           #2                  // class Day10$Type
       3: dup
       4: ldc           #52                 // String OPEN
       6: iconst_0
       7: invokespecial #53                 // Method "<init>":(Ljava/lang/String;I)V
      10: putstatic     #47                 // Field OPEN:LDay10$Type;
      13: new           #2                  // class Day10$Type
      16: dup
      17: ldc           #54                 // String CLOSE
      19: iconst_1
      20: invokespecial #53                 // Method "<init>":(Ljava/lang/String;I)V
      23: putstatic     #50                 // Field CLOSE:LDay10$Type;
      26: invokestatic  #56                 // Method $values:()[LDay10$Type;
      29: putstatic     #22                 // Field $VALUES:[LDay10$Type;
      32: getstatic     #22                 // Field $VALUES:[LDay10$Type;
      35: checkcast     #58                 // class "[Ljava/lang/Enum;"
      38: invokestatic  #64                 // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      41: putstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      44: return
}

Compiled from "Day10.kt"
public final class Day10Kt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field Day10$Part1.INSTANCE:LDay10$Part1;
       3: invokevirtual #15                 // Method Day10$Part1.run:()V
       6: getstatic     #20                 // Field Day10$Part2.INSTANCE:LDay10$Part2;
       9: invokevirtual #21                 // Method Day10$Part2.run:()V
      12: return

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

Compiled from "Day10.kt"
public final class Day10$Part2 {
  public static final Day10$Part2 INSTANCE;

  private Day10$Part2();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  private final java.lang.Long complete(java.util.List<Day10$Bracket>);
    Code:
       0: new           #15                 // class java/util/Stack
       3: dup
       4: invokespecial #16                 // Method java/util/Stack."<init>":()V
       7: astore_2
       8: aload_1
       9: checkcast     #18                 // class java/lang/Iterable
      12: astore_3
      13: iconst_0
      14: istore        4
      16: aload_3
      17: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore        5
      24: aload         5
      26: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      31: ifeq          100
      34: aload         5
      36: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      41: astore        6
      43: aload         6
      45: checkcast     #34                 // class Day10$Bracket
      48: astore        7
      50: iconst_0
      51: istore        8
      53: aload         7
      55: invokevirtual #38                 // Method Day10$Bracket.getType:()LDay10$Type;
      58: getstatic     #44                 // Field Day10$Type.CLOSE:LDay10$Type;
      61: if_acmpne     88
      64: aload_2
      65: invokevirtual #47                 // Method java/util/Stack.pop:()Ljava/lang/Object;
      68: checkcast     #34                 // class Day10$Bracket
      71: astore        9
      73: aload         7
      75: invokevirtual #51                 // Method Day10$Bracket.getBracketType:()LDay10$BracketType;
      78: aload         9
      80: invokevirtual #51                 // Method Day10$Bracket.getBracketType:()LDay10$BracketType;
      83: if_acmpeq     95
      86: aconst_null
      87: areturn
      88: aload_2
      89: aload         7
      91: invokevirtual #55                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
      94: pop
      95: nop
      96: nop
      97: goto          24
     100: nop
     101: aload_2
     102: invokevirtual #58                 // Method java/util/Stack.isEmpty:()Z
     105: ifeq          110
     108: aconst_null
     109: areturn
     110: aload_2
     111: checkcast     #18                 // class java/lang/Iterable
     114: invokestatic  #64                 // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     117: checkcast     #18                 // class java/lang/Iterable
     120: astore_3
     121: lconst_0
     122: invokestatic  #70                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     125: astore        4
     127: iconst_0
     128: istore        5
     130: aload         4
     132: astore        6
     134: aload_3
     135: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     140: astore        7
     142: aload         7
     144: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     149: ifeq          204
     152: aload         7
     154: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     159: astore        8
     161: aload         6
     163: aload         8
     165: checkcast     #34                 // class Day10$Bracket
     168: astore        9
     170: checkcast     #72                 // class java/lang/Number
     173: invokevirtual #76                 // Method java/lang/Number.longValue:()J
     176: lstore        10
     178: iconst_0
     179: istore        12
     181: lload         10
     183: iconst_5
     184: i2l
     185: lmul
     186: aload         9
     188: invokevirtual #51                 // Method Day10$Bracket.getBracketType:()LDay10$BracketType;
     191: invokevirtual #82                 // Method Day10$BracketType.getAutoCompleteScore:()I
     194: i2l
     195: ladd
     196: invokestatic  #70                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     199: astore        6
     201: goto          142
     204: aload         6
     206: areturn

  public final void run();
    Code:
       0: new           #109                // class java/io/File
       3: dup
       4: ldc           #111                // String day10/input-real.txt
       6: invokespecial #114                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: invokestatic  #120                // Method java/nio/charset/Charset.defaultCharset:()Ljava/nio/charset/Charset;
      12: dup
      13: ldc           #122                // String defaultCharset(...)
      15: invokestatic  #128                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      18: invokestatic  #134                // Method kotlin/io/FilesKt.readLines:(Ljava/io/File;Ljava/nio/charset/Charset;)Ljava/util/List;
      21: checkcast     #18                 // class java/lang/Iterable
      24: astore_1
      25: nop
      26: iconst_0
      27: istore_2
      28: aload_1
      29: astore_3
      30: new           #136                // class java/util/ArrayList
      33: dup
      34: invokespecial #137                // Method java/util/ArrayList."<init>":()V
      37: checkcast     #139                // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: astore        6
      48: iconst_0
      49: istore        7
      51: aload         6
      53: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        8
      60: aload         8
      62: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          137
      70: aload         8
      72: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        9
      79: aload         9
      81: astore        10
      83: iconst_0
      84: istore        11
      86: aload         10
      88: checkcast     #141                // class java/lang/String
      91: astore        12
      93: iconst_0
      94: istore        13
      96: getstatic     #144                // Field INSTANCE:LDay10$Part2;
      99: getstatic     #149                // Field Day10.INSTANCE:LDay10;
     102: aload         12
     104: invokevirtual #153                // Method Day10.toBrackets:(Ljava/lang/String;)Ljava/util/List;
     107: invokespecial #155                // Method complete:(Ljava/util/List;)Ljava/lang/Long;
     110: dup
     111: ifnull        132
     114: astore        14
     116: iconst_0
     117: istore        15
     119: aload         4
     121: aload         14
     123: invokeinterface #159,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     128: pop
     129: goto          133
     132: pop
     133: nop
     134: goto          60
     137: nop
     138: aload         4
     140: checkcast     #106                // class java/util/List
     143: nop
     144: checkcast     #18                 // class java/lang/Iterable
     147: invokestatic  #162                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     150: astore_1
     151: aload_1
     152: astore_2
     153: iconst_0
     154: istore_3
     155: aload_2
     156: aload_2
     157: invokeinterface #165,  1          // InterfaceMethod java/util/List.size:()I
     162: iconst_2
     163: idiv
     164: invokeinterface #169,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     169: checkcast     #72                 // class java/lang/Number
     172: invokevirtual #76                 // Method java/lang/Number.longValue:()J
     175: lstore        4
     177: getstatic     #175                // Field java/lang/System.out:Ljava/io/PrintStream;
     180: lload         4
     182: invokevirtual #181                // Method java/io/PrintStream.println:(J)V
     185: nop
     186: nop
     187: return

  static {};
    Code:
       0: new           #2                  // class Day10$Part2
       3: dup
       4: invokespecial #198                // Method "<init>":()V
       7: putstatic     #144                // Field INSTANCE:LDay10$Part2;
      10: return
}