package io.franmosteiro.aoc2020

/**
 * Advent of Code 2020 - Day 7: Handy Haversacks -
 * Problem Description: http://adventofcode.com/2020/day/7
 */
class Day07(input: List<String>) {

    private val allBags: List<Bag>
    private val MY_BAG = "shiny gold"

    companion object {
        private val bagPattern = """(\w+ \w+) bags contain (.*)""".toRegex()
        private val bagChildsPattern = """(\d+) (\w+ \w+) bags?""".toRegex()

        fun fromString(line: String): Bag {
            val (name, rest) = bagPattern.matchEntire(line)!!.destructured
            val contains = bagChildsPattern.findAll(rest).map { match ->
                val (c, n) = match.destructured
                c.toInt() to Bag(n, emptyList())
            }.toList()
            return Bag(name, contains)
        }
    }

    init {
        val bags = input.map { fromString(it) }

        fun buildRules(name: String): Bag {
            val containedBags = bags.first { it.color == name }.contains.map {
                it.first to buildRules(it.second.color)
            }
            return Bag(name, containedBags)
        }

        allBags = bags.map { buildRules(it.color) }
    }

    fun resolvePartOne(): Int =
            allBags.count { it.canHold(MY_BAG) }

    fun resolvePartTwo(): Int =
            allBags.first { it.color == MY_BAG }.numContains()

    data class Bag(val color : String,
                           val contains : List<Pair<Int, Bag>> = emptyList()){

        fun canHold(what: String): Boolean {
            return contains.any { it.second.color == what || it.second.canHold(what) }
        }

        fun numContains(): Int {
            return contains.sumBy {
                it.first * (it.second.numContains() + 1)
            }
        }

    }
}

Compiled from "Day07.kt"
public final class io.franmosteiro.aoc2020.Day07 {
  public static final io.franmosteiro.aoc2020.Day07$Companion Companion;

  private final java.util.List<io.franmosteiro.aoc2020.Day07$Bag> allBags;

  private final java.lang.String MY_BAG;

  private static final kotlin.text.Regex bagPattern;

  private static final kotlin.text.Regex bagChildsPattern;

  public io.franmosteiro.aoc2020.Day07(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       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: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: ldc           #21                 // String shiny gold
      13: putfield      #25                 // Field MY_BAG:Ljava/lang/String;
      16: nop
      17: aload_1
      18: checkcast     #27                 // class java/lang/Iterable
      21: astore_3
      22: iconst_0
      23: istore        4
      25: aload_3
      26: astore        5
      28: new           #29                 // class java/util/ArrayList
      31: dup
      32: aload_3
      33: bipush        10
      35: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      38: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
      41: checkcast     #40                 // class java/util/Collection
      44: astore        6
      46: iconst_0
      47: istore        7
      49: aload         5
      51: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        8
      58: aload         8
      60: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          111
      68: aload         8
      70: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        9
      77: aload         6
      79: aload         9
      81: checkcast     #56                 // class java/lang/String
      84: astore        10
      86: astore        12
      88: iconst_0
      89: istore        11
      91: getstatic     #60                 // Field Companion:Lio/franmosteiro/aoc2020/Day07$Companion;
      94: aload         10
      96: invokevirtual #66                 // Method io/franmosteiro/aoc2020/Day07$Companion.fromString:(Ljava/lang/String;)Lio/franmosteiro/aoc2020/Day07$Bag;
      99: aload         12
     101: swap
     102: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     107: pop
     108: goto          58
     111: aload         6
     113: checkcast     #72                 // class java/util/List
     116: nop
     117: astore_2
     118: aload_0
     119: aload_2
     120: checkcast     #27                 // class java/lang/Iterable
     123: astore_3
     124: astore        12
     126: iconst_0
     127: istore        4
     129: aload_3
     130: astore        5
     132: new           #29                 // class java/util/ArrayList
     135: dup
     136: aload_3
     137: bipush        10
     139: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     142: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     145: checkcast     #40                 // class java/util/Collection
     148: astore        6
     150: iconst_0
     151: istore        7
     153: aload         5
     155: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     160: astore        8
     162: aload         8
     164: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     169: ifeq          216
     172: aload         8
     174: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     179: astore        9
     181: aload         6
     183: aload         9
     185: checkcast     #74                 // class io/franmosteiro/aoc2020/Day07$Bag
     188: astore        10
     190: astore        13
     192: iconst_0
     193: istore        11
     195: aload_2
     196: aload         10
     198: invokevirtual #78                 // Method io/franmosteiro/aoc2020/Day07$Bag.getColor:()Ljava/lang/String;
     201: invokestatic  #82                 // Method _init_$buildRules:(Ljava/util/List;Ljava/lang/String;)Lio/franmosteiro/aoc2020/Day07$Bag;
     204: aload         13
     206: swap
     207: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     212: pop
     213: goto          162
     216: aload         6
     218: checkcast     #72                 // class java/util/List
     221: nop
     222: aload         12
     224: swap
     225: putfield      #86                 // Field allBags:Ljava/util/List;
     228: nop
     229: return

  public final int resolvePartOne();
    Code:
       0: aload_0
       1: getfield      #86                 // Field allBags:Ljava/util/List;
       4: checkcast     #27                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: instanceof    #40                 // class java/util/Collection
      14: ifeq          33
      17: aload_1
      18: checkcast     #40                 // class java/util/Collection
      21: invokeinterface #108,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      26: ifeq          33
      29: iconst_0
      30: goto          98
      33: iconst_0
      34: istore_3
      35: aload_1
      36: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore        4
      43: aload         4
      45: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          97
      53: aload         4
      55: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        5
      62: aload         5
      64: checkcast     #74                 // class io/franmosteiro/aoc2020/Day07$Bag
      67: astore        6
      69: iconst_0
      70: istore        7
      72: aload         6
      74: aload_0
      75: getfield      #25                 // Field MY_BAG:Ljava/lang/String;
      78: invokevirtual #112                // Method io/franmosteiro/aoc2020/Day07$Bag.canHold:(Ljava/lang/String;)Z
      81: ifeq          43
      84: iinc          3, 1
      87: iload_3
      88: ifge          43
      91: invokestatic  #115                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
      94: goto          43
      97: iload_3
      98: ireturn

  public final int resolvePartTwo();
    Code:
       0: aload_0
       1: getfield      #86                 // Field allBags:Ljava/util/List;
       4: checkcast     #27                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      16: astore_3
      17: aload_3
      18: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          64
      26: aload_3
      27: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: astore        4
      34: aload         4
      36: checkcast     #74                 // class io/franmosteiro/aoc2020/Day07$Bag
      39: astore        5
      41: iconst_0
      42: istore        6
      44: aload         5
      46: invokevirtual #78                 // Method io/franmosteiro/aoc2020/Day07$Bag.getColor:()Ljava/lang/String;
      49: aload_0
      50: getfield      #25                 // Field MY_BAG:Ljava/lang/String;
      53: invokestatic  #125                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      56: ifeq          17
      59: aload         4
      61: goto          74
      64: new           #127                // class java/util/NoSuchElementException
      67: dup
      68: ldc           #129                // String Collection contains no element matching the predicate.
      70: invokespecial #132                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
      73: athrow
      74: checkcast     #74                 // class io/franmosteiro/aoc2020/Day07$Bag
      77: invokevirtual #135                // Method io/franmosteiro/aoc2020/Day07$Bag.numContains:()I
      80: ireturn

  private static final io.franmosteiro.aoc2020.Day07$Bag _init_$buildRules(java.util.List<io.franmosteiro.aoc2020.Day07$Bag>, java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #27                 // class java/lang/Iterable
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      14: astore        5
      16: aload         5
      18: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          62
      26: aload         5
      28: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: astore        6
      35: aload         6
      37: checkcast     #74                 // class io/franmosteiro/aoc2020/Day07$Bag
      40: astore        7
      42: iconst_0
      43: istore        8
      45: aload         7
      47: invokevirtual #78                 // Method io/franmosteiro/aoc2020/Day07$Bag.getColor:()Ljava/lang/String;
      50: aload_1
      51: invokestatic  #125                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      54: ifeq          16
      57: aload         6
      59: goto          72
      62: new           #127                // class java/util/NoSuchElementException
      65: dup
      66: ldc           #129                // String Collection contains no element matching the predicate.
      68: invokespecial #132                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
      71: athrow
      72: checkcast     #74                 // class io/franmosteiro/aoc2020/Day07$Bag
      75: invokevirtual #143                // Method io/franmosteiro/aoc2020/Day07$Bag.getContains:()Ljava/util/List;
      78: checkcast     #27                 // class java/lang/Iterable
      81: astore_3
      82: iconst_0
      83: istore        4
      85: aload_3
      86: astore        5
      88: new           #29                 // class java/util/ArrayList
      91: dup
      92: aload_3
      93: bipush        10
      95: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      98: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     101: checkcast     #40                 // class java/util/Collection
     104: astore        6
     106: iconst_0
     107: istore        7
     109: aload         5
     111: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        8
     118: aload         8
     120: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          186
     128: aload         8
     130: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: astore        9
     137: aload         6
     139: aload         9
     141: checkcast     #145                // class kotlin/Pair
     144: astore        10
     146: astore        12
     148: iconst_0
     149: istore        11
     151: aload         10
     153: invokevirtual #148                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     156: aload_0
     157: aload         10
     159: invokevirtual #151                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     162: checkcast     #74                 // class io/franmosteiro/aoc2020/Day07$Bag
     165: invokevirtual #78                 // Method io/franmosteiro/aoc2020/Day07$Bag.getColor:()Ljava/lang/String;
     168: invokestatic  #82                 // Method _init_$buildRules:(Ljava/util/List;Ljava/lang/String;)Lio/franmosteiro/aoc2020/Day07$Bag;
     171: invokestatic  #157                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     174: aload         12
     176: swap
     177: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     182: pop
     183: goto          118
     186: aload         6
     188: checkcast     #72                 // class java/util/List
     191: nop
     192: astore_2
     193: new           #74                 // class io/franmosteiro/aoc2020/Day07$Bag
     196: dup
     197: aload_1
     198: aload_2
     199: invokespecial #160                // Method io/franmosteiro/aoc2020/Day07$Bag."<init>":(Ljava/lang/String;Ljava/util/List;)V
     202: areturn

  public static final kotlin.text.Regex access$getBagPattern$cp();
    Code:
       0: getstatic     #171                // Field bagPattern:Lkotlin/text/Regex;
       3: areturn

  public static final kotlin.text.Regex access$getBagChildsPattern$cp();
    Code:
       0: getstatic     #175                // Field bagChildsPattern:Lkotlin/text/Regex;
       3: areturn

  static {};
    Code:
       0: new           #62                 // class io/franmosteiro/aoc2020/Day07$Companion
       3: dup
       4: aconst_null
       5: invokespecial #179                // Method io/franmosteiro/aoc2020/Day07$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #60                 // Field Companion:Lio/franmosteiro/aoc2020/Day07$Companion;
      11: new           #181                // class kotlin/text/Regex
      14: dup
      15: ldc           #183                // String (\\w+ \\w+) bags contain (.*)
      17: invokespecial #184                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      20: putstatic     #171                // Field bagPattern:Lkotlin/text/Regex;
      23: new           #181                // class kotlin/text/Regex
      26: dup
      27: ldc           #186                // String (\\d+) (\\w+ \\w+) bags?
      29: invokespecial #184                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      32: putstatic     #175                // Field bagChildsPattern:Lkotlin/text/Regex;
      35: return
}

Compiled from "Day07.kt"
public final class io.franmosteiro.aoc2020.Day07$Bag {
  private final java.lang.String color;

  private final java.util.List<kotlin.Pair<java.lang.Integer, io.franmosteiro.aoc2020.Day07$Bag>> contains;

  public io.franmosteiro.aoc2020.Day07$Bag(java.lang.String, java.util.List<kotlin.Pair<java.lang.Integer, io.franmosteiro.aoc2020.Day07$Bag>>);
    Code:
       0: aload_1
       1: ldc           #10                 // String color
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String contains
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #21                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #24                 // Field color:Ljava/lang/String;
      21: aload_0
      22: aload_2
      23: putfield      #27                 // Field contains:Ljava/util/List;
      26: return

  public io.franmosteiro.aoc2020.Day07$Bag(java.lang.String, java.util.List, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          10
       6: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
       9: astore_2
      10: aload_0
      11: aload_1
      12: aload_2
      13: invokespecial #38                 // Method "<init>":(Ljava/lang/String;Ljava/util/List;)V
      16: return

  public final java.lang.String getColor();
    Code:
       0: aload_0
       1: getfield      #24                 // Field color:Ljava/lang/String;
       4: areturn

  public final java.util.List<kotlin.Pair<java.lang.Integer, io.franmosteiro.aoc2020.Day07$Bag>> getContains();
    Code:
       0: aload_0
       1: getfield      #27                 // Field contains:Ljava/util/List;
       4: areturn

  public final boolean canHold(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #46                 // String what
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #27                 // Field contains:Ljava/util/List;
      10: checkcast     #48                 // class java/lang/Iterable
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_2
      17: instanceof    #50                 // class java/util/Collection
      20: ifeq          39
      23: aload_2
      24: checkcast     #50                 // class java/util/Collection
      27: invokeinterface #54,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      32: ifeq          39
      35: iconst_0
      36: goto          122
      39: aload_2
      40: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        4
      47: aload         4
      49: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          121
      57: aload         4
      59: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        5
      66: aload         5
      68: checkcast     #69                 // class kotlin/Pair
      71: astore        6
      73: iconst_0
      74: istore        7
      76: aload         6
      78: invokevirtual #72                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      81: checkcast     #2                  // class io/franmosteiro/aoc2020/Day07$Bag
      84: getfield      #24                 // Field color:Ljava/lang/String;
      87: aload_1
      88: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      91: ifne          109
      94: aload         6
      96: invokevirtual #72                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      99: checkcast     #2                  // class io/franmosteiro/aoc2020/Day07$Bag
     102: aload_1
     103: invokevirtual #78                 // Method canHold:(Ljava/lang/String;)Z
     106: ifeq          113
     109: iconst_1
     110: goto          114
     113: iconst_0
     114: ifeq          47
     117: iconst_1
     118: goto          122
     121: iconst_0
     122: ireturn

  public final int numContains();
    Code:
       0: aload_0
       1: getfield      #27                 // Field contains:Ljava/util/List;
       4: checkcast     #48                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: iconst_0
      11: istore_3
      12: aload_1
      13: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      18: astore        4
      20: aload         4
      22: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      27: ifeq          88
      30: aload         4
      32: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      37: astore        5
      39: iload_3
      40: aload         5
      42: checkcast     #69                 // class kotlin/Pair
      45: astore        6
      47: istore        8
      49: iconst_0
      50: istore        7
      52: aload         6
      54: invokevirtual #94                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      57: checkcast     #96                 // class java/lang/Number
      60: invokevirtual #99                 // Method java/lang/Number.intValue:()I
      63: aload         6
      65: invokevirtual #72                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      68: checkcast     #2                  // class io/franmosteiro/aoc2020/Day07$Bag
      71: invokevirtual #101                // Method numContains:()I
      74: iconst_1
      75: iadd
      76: imul
      77: istore        9
      79: iload         8
      81: iload         9
      83: iadd
      84: istore_3
      85: goto          20
      88: iload_3
      89: ireturn

  public final java.lang.String component1();
    Code:
       0: aload_0
       1: getfield      #24                 // Field color:Ljava/lang/String;
       4: areturn

  public final java.util.List<kotlin.Pair<java.lang.Integer, io.franmosteiro.aoc2020.Day07$Bag>> component2();
    Code:
       0: aload_0
       1: getfield      #27                 // Field contains:Ljava/util/List;
       4: areturn

  public final io.franmosteiro.aoc2020.Day07$Bag copy(java.lang.String, java.util.List<kotlin.Pair<java.lang.Integer, io.franmosteiro.aoc2020.Day07$Bag>>);
    Code:
       0: aload_1
       1: ldc           #10                 // String color
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String contains
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class io/franmosteiro/aoc2020/Day07$Bag
      15: dup
      16: aload_1
      17: aload_2
      18: invokespecial #38                 // Method "<init>":(Ljava/lang/String;Ljava/util/List;)V
      21: areturn

  public static io.franmosteiro.aoc2020.Day07$Bag copy$default(io.franmosteiro.aoc2020.Day07$Bag, java.lang.String, java.util.List, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #24                 // Field color:Ljava/lang/String;
      10: astore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #27                 // Field contains:Ljava/util/List;
      21: astore_2
      22: aload_0
      23: aload_1
      24: aload_2
      25: invokevirtual #114                // Method copy:(Ljava/lang/String;Ljava/util/List;)Lio/franmosteiro/aoc2020/Day07$Bag;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #117                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #118                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #120                // String Bag(color=
       9: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #24                 // Field color:Ljava/lang/String;
      16: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      19: ldc           #126                // String , contains=
      21: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #27                 // Field contains:Ljava/util/List;
      28: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #132                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #134                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #24                 // Field color:Ljava/lang/String;
       4: invokevirtual #137                // Method java/lang/String.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #27                 // Field contains:Ljava/util/List;
      16: invokevirtual #138                // Method java/lang/Object.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 io/franmosteiro/aoc2020/Day07$Bag
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class io/franmosteiro/aoc2020/Day07$Bag
      20: astore_2
      21: aload_0
      22: getfield      #24                 // Field color:Ljava/lang/String;
      25: aload_2
      26: getfield      #24                 // Field color:Ljava/lang/String;
      29: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #27                 // Field contains:Ljava/util/List;
      41: aload_2
      42: getfield      #27                 // Field contains:Ljava/util/List;
      45: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      48: ifne          53
      51: iconst_0
      52: ireturn
      53: iconst_1
      54: ireturn
}

Compiled from "Day07.kt"
public final class io.franmosteiro.aoc2020.Day07$Companion {
  private io.franmosteiro.aoc2020.Day07$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final io.franmosteiro.aoc2020.Day07$Bag fromString(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String line
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: invokestatic  #27                 // Method io/franmosteiro/aoc2020/Day07.access$getBagPattern$cp:()Lkotlin/text/Regex;
       9: aload_1
      10: checkcast     #29                 // class java/lang/CharSequence
      13: invokevirtual #35                 // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
      16: dup
      17: invokestatic  #39                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      20: invokeinterface #45,  1           // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      25: astore_2
      26: aload_2
      27: invokevirtual #51                 // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      30: invokeinterface #55,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      35: iconst_1
      36: invokeinterface #61,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      41: checkcast     #63                 // class java/lang/String
      44: astore_3
      45: aload_2
      46: invokevirtual #51                 // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      49: invokeinterface #55,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      54: iconst_2
      55: invokeinterface #61,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #63                 // class java/lang/String
      63: astore        4
      65: invokestatic  #66                 // Method io/franmosteiro/aoc2020/Day07.access$getBagChildsPattern$cp:()Lkotlin/text/Regex;
      68: aload         4
      70: checkcast     #29                 // class java/lang/CharSequence
      73: iconst_0
      74: iconst_2
      75: aconst_null
      76: invokestatic  #70                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      79: invokedynamic #89,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      84: invokestatic  #95                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      87: invokestatic  #99                 // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      90: astore        5
      92: new           #101                // class io/franmosteiro/aoc2020/Day07$Bag
      95: dup
      96: aload_3
      97: aload         5
      99: invokespecial #104                // Method io/franmosteiro/aoc2020/Day07$Bag."<init>":(Ljava/lang/String;Ljava/util/List;)V
     102: areturn

  private static final kotlin.Pair fromString$lambda$0(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc           #111                // String match
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #45,  1           // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      12: astore_1
      13: aload_1
      14: invokevirtual #51                 // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      17: invokeinterface #55,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      22: iconst_1
      23: invokeinterface #61,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      28: checkcast     #63                 // class java/lang/String
      31: astore_2
      32: aload_1
      33: invokevirtual #51                 // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      36: invokeinterface #55,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      41: iconst_2
      42: invokeinterface #61,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      47: checkcast     #63                 // class java/lang/String
      50: astore_3
      51: aload_2
      52: invokestatic  #117                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      55: invokestatic  #121                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      58: new           #101                // class io/franmosteiro/aoc2020/Day07$Bag
      61: dup
      62: aload_3
      63: invokestatic  #126                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      66: invokespecial #104                // Method io/franmosteiro/aoc2020/Day07$Bag."<init>":(Ljava/lang/String;Ljava/util/List;)V
      69: invokestatic  #132                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      72: areturn

  public io.franmosteiro.aoc2020.Day07$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #137                // Method "<init>":()V
       4: return
}


package io.franmosteiro.aoc2020

/**
 * Advent of Code 2020 - Day 4: Passport Processing -
 * Problem Description: http://adventofcode.com/2020/day/4
 */
class Day04(input: String) {

    private val passports = input.split("\\n\\n".toRegex()).map { line ->
        line.split("\\s".toRegex()).associate {
            val (field, value) = it.split(":")
            field to value
        }
    }

    fun resolvePartOne(): Int {

        val requiredFields = listOf("byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid")

        return passports.count { passport -> requiredFields.all { it in passport } }
    }

    fun resolvePartTwo(): Int = passports.count { valid(it) }

    private fun valid(field: Map<String, String>): Boolean {

        return field["byr"]?.toIntOrNull() in 1920..2002 &&
                field["iyr"]?.toIntOrNull() in 2010..2020 &&
                field["eyr"]?.toIntOrNull() in 2020..2030 &&
                field["ecl"] in listOf("amb", "blu", "brn", "gry", "grn", "hzl", "oth") &&
                field["pid"]?.matches("\\d{9}".toRegex()) == true &&
                field["hcl"]?.matches("#[0-9a-f]{6}".toRegex()) == true &&
                when (field["hgt"]?.takeLast(2)) {
                    "cm" -> field["hgt"]?.dropLast(2)?.toIntOrNull() in 150..193
                    "in" -> field["hgt"]?.dropLast(2)?.toIntOrNull() in 59..76
                    else -> false
                }
    }

}

Compiled from "Day04.kt"
public final class io.franmosteiro.aoc2020.Day04 {
  private final java.util.List<java.util.Map<java.lang.String, java.lang.String>> passports;

  public io.franmosteiro.aoc2020.Day04(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: checkcast     #20                 // class java/lang/CharSequence
      15: astore_2
      16: new           #22                 // class kotlin/text/Regex
      19: dup
      20: ldc           #24                 // String \\n\\n
      22: invokespecial #26                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      25: astore_3
      26: iconst_0
      27: istore        4
      29: aload_3
      30: aload_2
      31: iload         4
      33: invokevirtual #30                 // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      36: checkcast     #32                 // class java/lang/Iterable
      39: astore_2
      40: astore        25
      42: iconst_0
      43: istore_3
      44: aload_2
      45: astore        4
      47: new           #34                 // class java/util/ArrayList
      50: dup
      51: aload_2
      52: bipush        10
      54: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      57: invokespecial #43                 // Method java/util/ArrayList."<init>":(I)V
      60: checkcast     #45                 // class java/util/Collection
      63: astore        5
      65: iconst_0
      66: istore        6
      68: aload         4
      70: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      75: astore        7
      77: aload         7
      79: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      84: ifeq          330
      87: aload         7
      89: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      94: astore        8
      96: aload         5
      98: aload         8
     100: checkcast     #61                 // class java/lang/String
     103: astore        9
     105: astore        26
     107: iconst_0
     108: istore        10
     110: aload         9
     112: checkcast     #20                 // class java/lang/CharSequence
     115: astore        11
     117: new           #22                 // class kotlin/text/Regex
     120: dup
     121: ldc           #63                 // String \\s
     123: invokespecial #26                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     126: astore        12
     128: iconst_0
     129: istore        13
     131: aload         12
     133: aload         11
     135: iload         13
     137: invokevirtual #30                 // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
     140: checkcast     #32                 // class java/lang/Iterable
     143: astore        11
     145: nop
     146: iconst_0
     147: istore        12
     149: aload         11
     151: bipush        10
     153: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     156: invokestatic  #69                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     159: bipush        16
     161: invokestatic  #75                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     164: istore        13
     166: aload         11
     168: astore        14
     170: new           #77                 // class java/util/LinkedHashMap
     173: dup
     174: iload         13
     176: invokespecial #78                 // Method java/util/LinkedHashMap."<init>":(I)V
     179: checkcast     #80                 // class java/util/Map
     182: astore        15
     184: iconst_0
     185: istore        16
     187: aload         14
     189: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     194: astore        17
     196: aload         17
     198: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     203: ifeq          314
     206: aload         17
     208: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     213: astore        18
     215: aload         15
     217: astore        19
     219: aload         18
     221: checkcast     #61                 // class java/lang/String
     224: astore        20
     226: iconst_0
     227: istore        21
     229: aload         20
     231: checkcast     #20                 // class java/lang/CharSequence
     234: iconst_1
     235: anewarray     #61                 // class java/lang/String
     238: astore        22
     240: aload         22
     242: iconst_0
     243: ldc           #82                 // String :
     245: aastore
     246: aload         22
     248: iconst_0
     249: iconst_0
     250: bipush        6
     252: aconst_null
     253: invokestatic  #88                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     256: astore        23
     258: aload         23
     260: iconst_0
     261: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     266: checkcast     #61                 // class java/lang/String
     269: astore        22
     271: aload         23
     273: iconst_1
     274: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     279: checkcast     #61                 // class java/lang/String
     282: astore        24
     284: aload         22
     286: aload         24
     288: invokestatic  #100                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     291: astore        20
     293: aload         19
     295: aload         20
     297: invokevirtual #105                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     300: aload         20
     302: invokevirtual #108                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     305: invokeinterface #112,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     310: pop
     311: goto          196
     314: aload         15
     316: nop
     317: nop
     318: aload         26
     320: swap
     321: invokeinterface #116,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     326: pop
     327: goto          77
     330: aload         5
     332: checkcast     #90                 // class java/util/List
     335: nop
     336: aload         25
     338: swap
     339: putfield      #120                // Field passports:Ljava/util/List;
     342: return

  public final int resolvePartOne();
    Code:
       0: bipush        7
       2: anewarray     #61                 // class java/lang/String
       5: astore_2
       6: aload_2
       7: iconst_0
       8: ldc           #150                // String byr
      10: aastore
      11: aload_2
      12: iconst_1
      13: ldc           #152                // String iyr
      15: aastore
      16: aload_2
      17: iconst_2
      18: ldc           #154                // String eyr
      20: aastore
      21: aload_2
      22: iconst_3
      23: ldc           #156                // String hgt
      25: aastore
      26: aload_2
      27: iconst_4
      28: ldc           #158                // String hcl
      30: aastore
      31: aload_2
      32: iconst_5
      33: ldc           #160                // String ecl
      35: aastore
      36: aload_2
      37: bipush        6
      39: ldc           #162                // String pid
      41: aastore
      42: aload_2
      43: invokestatic  #166                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      46: astore_1
      47: aload_0
      48: getfield      #120                // Field passports:Ljava/util/List;
      51: checkcast     #32                 // class java/lang/Iterable
      54: astore_2
      55: iconst_0
      56: istore_3
      57: aload_2
      58: instanceof    #45                 // class java/util/Collection
      61: ifeq          80
      64: aload_2
      65: checkcast     #45                 // class java/util/Collection
      68: invokeinterface #169,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      73: ifeq          80
      76: iconst_0
      77: goto          230
      80: iconst_0
      81: istore        4
      83: aload_2
      84: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      89: astore        5
      91: aload         5
      93: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      98: ifeq          228
     101: aload         5
     103: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     108: astore        6
     110: aload         6
     112: checkcast     #80                 // class java/util/Map
     115: astore        7
     117: iconst_0
     118: istore        8
     120: aload_1
     121: checkcast     #32                 // class java/lang/Iterable
     124: astore        9
     126: iconst_0
     127: istore        10
     129: aload         9
     131: instanceof    #45                 // class java/util/Collection
     134: ifeq          154
     137: aload         9
     139: checkcast     #45                 // class java/util/Collection
     142: invokeinterface #169,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     147: ifeq          154
     150: iconst_1
     151: goto          210
     154: aload         9
     156: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     161: astore        11
     163: aload         11
     165: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     170: ifeq          209
     173: aload         11
     175: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     180: astore        12
     182: aload         12
     184: checkcast     #61                 // class java/lang/String
     187: astore        13
     189: iconst_0
     190: istore        14
     192: aload         7
     194: aload         13
     196: invokeinterface #172,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     201: nop
     202: ifne          163
     205: iconst_0
     206: goto          210
     209: iconst_1
     210: nop
     211: ifeq          91
     214: iinc          4, 1
     217: iload         4
     219: ifge          91
     222: invokestatic  #175                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     225: goto          91
     228: iload         4
     230: ireturn

  public final int resolvePartTwo();
    Code:
       0: aload_0
       1: getfield      #120                // Field passports:Ljava/util/List;
       4: checkcast     #32                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: instanceof    #45                 // class java/util/Collection
      14: ifeq          33
      17: aload_1
      18: checkcast     #45                 // class java/util/Collection
      21: invokeinterface #169,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      26: ifeq          33
      29: iconst_0
      30: goto          95
      33: iconst_0
      34: istore_3
      35: aload_1
      36: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore        4
      43: aload         4
      45: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          94
      53: aload         4
      55: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        5
      62: aload         5
      64: checkcast     #80                 // class java/util/Map
      67: astore        6
      69: iconst_0
      70: istore        7
      72: aload_0
      73: aload         6
      75: invokespecial #190                // Method valid:(Ljava/util/Map;)Z
      78: ifeq          43
      81: iinc          3, 1
      84: iload_3
      85: ifge          43
      88: invokestatic  #175                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
      91: goto          43
      94: iload_3
      95: ireturn

  private final boolean valid(java.util.Map<java.lang.String, java.lang.String>);
    Code:
       0: new           #194                // class kotlin/ranges/IntRange
       3: dup
       4: sipush        1920
       7: sipush        2002
      10: invokespecial #197                // Method kotlin/ranges/IntRange."<init>":(II)V
      13: astore_2
      14: aload_1
      15: ldc           #150                // String byr
      17: invokeinterface #200,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      22: checkcast     #61                 // class java/lang/String
      25: dup
      26: ifnull        35
      29: invokestatic  #204                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
      32: goto          37
      35: pop
      36: aconst_null
      37: astore_3
      38: aload_3
      39: ifnull        57
      42: aload_2
      43: aload_3
      44: invokevirtual #209                // Method java/lang/Integer.intValue:()I
      47: invokevirtual #213                // Method kotlin/ranges/IntRange.contains:(I)Z
      50: ifeq          57
      53: iconst_1
      54: goto          58
      57: iconst_0
      58: ifeq          537
      61: new           #194                // class kotlin/ranges/IntRange
      64: dup
      65: sipush        2010
      68: sipush        2020
      71: invokespecial #197                // Method kotlin/ranges/IntRange."<init>":(II)V
      74: astore_2
      75: aload_1
      76: ldc           #152                // String iyr
      78: invokeinterface #200,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      83: checkcast     #61                 // class java/lang/String
      86: dup
      87: ifnull        96
      90: invokestatic  #204                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
      93: goto          98
      96: pop
      97: aconst_null
      98: astore_3
      99: aload_3
     100: ifnull        118
     103: aload_2
     104: aload_3
     105: invokevirtual #209                // Method java/lang/Integer.intValue:()I
     108: invokevirtual #213                // Method kotlin/ranges/IntRange.contains:(I)Z
     111: ifeq          118
     114: iconst_1
     115: goto          119
     118: iconst_0
     119: ifeq          537
     122: new           #194                // class kotlin/ranges/IntRange
     125: dup
     126: sipush        2020
     129: sipush        2030
     132: invokespecial #197                // Method kotlin/ranges/IntRange."<init>":(II)V
     135: astore_2
     136: aload_1
     137: ldc           #154                // String eyr
     139: invokeinterface #200,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     144: checkcast     #61                 // class java/lang/String
     147: dup
     148: ifnull        157
     151: invokestatic  #204                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
     154: goto          159
     157: pop
     158: aconst_null
     159: astore_3
     160: aload_3
     161: ifnull        179
     164: aload_2
     165: aload_3
     166: invokevirtual #209                // Method java/lang/Integer.intValue:()I
     169: invokevirtual #213                // Method kotlin/ranges/IntRange.contains:(I)Z
     172: ifeq          179
     175: iconst_1
     176: goto          180
     179: iconst_0
     180: ifeq          537
     183: bipush        7
     185: anewarray     #61                 // class java/lang/String
     188: astore_2
     189: aload_2
     190: iconst_0
     191: ldc           #215                // String amb
     193: aastore
     194: aload_2
     195: iconst_1
     196: ldc           #217                // String blu
     198: aastore
     199: aload_2
     200: iconst_2
     201: ldc           #219                // String brn
     203: aastore
     204: aload_2
     205: iconst_3
     206: ldc           #221                // String gry
     208: aastore
     209: aload_2
     210: iconst_4
     211: ldc           #223                // String grn
     213: aastore
     214: aload_2
     215: iconst_5
     216: ldc           #225                // String hzl
     218: aastore
     219: aload_2
     220: bipush        6
     222: ldc           #227                // String oth
     224: aastore
     225: aload_2
     226: invokestatic  #166                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     229: checkcast     #32                 // class java/lang/Iterable
     232: aload_1
     233: ldc           #160                // String ecl
     235: invokeinterface #200,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     240: invokestatic  #230                // Method kotlin/collections/CollectionsKt.contains:(Ljava/lang/Iterable;Ljava/lang/Object;)Z
     243: ifeq          537
     246: aload_1
     247: ldc           #162                // String pid
     249: invokeinterface #200,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     254: checkcast     #61                 // class java/lang/String
     257: dup
     258: ifnull        290
     261: checkcast     #20                 // class java/lang/CharSequence
     264: astore_3
     265: new           #22                 // class kotlin/text/Regex
     268: dup
     269: ldc           #232                // String \\d{9}
     271: invokespecial #26                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     274: aload_3
     275: invokevirtual #236                // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
     278: iconst_1
     279: if_icmpne     286
     282: iconst_1
     283: goto          292
     286: iconst_0
     287: goto          292
     290: pop
     291: iconst_0
     292: ifeq          537
     295: aload_1
     296: ldc           #158                // String hcl
     298: invokeinterface #200,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     303: checkcast     #61                 // class java/lang/String
     306: dup
     307: ifnull        339
     310: checkcast     #20                 // class java/lang/CharSequence
     313: astore_3
     314: new           #22                 // class kotlin/text/Regex
     317: dup
     318: ldc           #238                // String #[0-9a-f]{6}
     320: invokespecial #26                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     323: aload_3
     324: invokevirtual #236                // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
     327: iconst_1
     328: if_icmpne     335
     331: iconst_1
     332: goto          341
     335: iconst_0
     336: goto          341
     339: pop
     340: iconst_0
     341: ifeq          537
     344: aload_1
     345: ldc           #156                // String hgt
     347: invokeinterface #200,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     352: checkcast     #61                 // class java/lang/String
     355: dup
     356: ifnull        366
     359: iconst_2
     360: invokestatic  #242                // Method kotlin/text/StringsKt.takeLast:(Ljava/lang/String;I)Ljava/lang/String;
     363: goto          368
     366: pop
     367: aconst_null
     368: astore_2
     369: aload_2
     370: ldc           #244                // String cm
     372: invokestatic  #248                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     375: ifeq          450
     378: new           #194                // class kotlin/ranges/IntRange
     381: dup
     382: sipush        150
     385: sipush        193
     388: invokespecial #197                // Method kotlin/ranges/IntRange."<init>":(II)V
     391: astore_3
     392: aload_1
     393: ldc           #156                // String hgt
     395: invokeinterface #200,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     400: checkcast     #61                 // class java/lang/String
     403: dup
     404: ifnull        421
     407: iconst_2
     408: invokestatic  #251                // Method kotlin/text/StringsKt.dropLast:(Ljava/lang/String;I)Ljava/lang/String;
     411: dup
     412: ifnull        421
     415: invokestatic  #204                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
     418: goto          423
     421: pop
     422: aconst_null
     423: astore        4
     425: aload         4
     427: ifnull        446
     430: aload_3
     431: aload         4
     433: invokevirtual #209                // Method java/lang/Integer.intValue:()I
     436: invokevirtual #213                // Method kotlin/ranges/IntRange.contains:(I)Z
     439: ifeq          446
     442: iconst_1
     443: goto          530
     446: iconst_0
     447: goto          530
     450: aload_2
     451: ldc           #253                // String in
     453: invokestatic  #248                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     456: ifeq          529
     459: new           #194                // class kotlin/ranges/IntRange
     462: dup
     463: bipush        59
     465: bipush        76
     467: invokespecial #197                // Method kotlin/ranges/IntRange."<init>":(II)V
     470: astore_3
     471: aload_1
     472: ldc           #156                // String hgt
     474: invokeinterface #200,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     479: checkcast     #61                 // class java/lang/String
     482: dup
     483: ifnull        500
     486: iconst_2
     487: invokestatic  #251                // Method kotlin/text/StringsKt.dropLast:(Ljava/lang/String;I)Ljava/lang/String;
     490: dup
     491: ifnull        500
     494: invokestatic  #204                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
     497: goto          502
     500: pop
     501: aconst_null
     502: astore        4
     504: aload         4
     506: ifnull        525
     509: aload_3
     510: aload         4
     512: invokevirtual #209                // Method java/lang/Integer.intValue:()I
     515: invokevirtual #213                // Method kotlin/ranges/IntRange.contains:(I)Z
     518: ifeq          525
     521: iconst_1
     522: goto          530
     525: iconst_0
     526: goto          530
     529: iconst_0
     530: ifeq          537
     533: iconst_1
     534: goto          538
     537: iconst_0
     538: ireturn
}


package com.adventofcode

import com.adventofcode.Figure.*
import com.adventofcode.Game.game
import com.adventofcode.Game.rightScores
import com.adventofcode.Round.*

enum class Round(val scores: Long) {
  Win(6),
  Lose(0),
  Draw(3),
}

enum class Figure(val scores: Long) {

  Rock(1) {
    override fun roundWith(other: Figure): Round {
      return when (other) {
        Rock -> Draw
        Scissors -> Win
        Paper -> Lose
      }
    }
  },

  Paper(2) {
    override fun roundWith(other: Figure): Round {
      return when (other) {
        Paper -> Draw
        Rock -> Win
        Scissors -> Lose
      }
    }
  },

  Scissors(3) {
    override fun roundWith(other: Figure): Round {
      return when (other) {
        Scissors -> Draw
        Rock -> Lose
        Paper -> Win
      }
    }
  };

  abstract fun roundWith(other: Figure): Round
}

fun parseFigure(s: String): Figure {
  return when (s) {
    "A" -> Rock
    "B" -> Paper
    "C" -> Scissors
    else -> throw IllegalStateException()
  }
}

object Game {

  var leftScores = 0L; private set

  var rightScores = 0L; private set

  fun game(left: Figure, right: Figure) {
    leftScores += left.scores
    leftScores += left.roundWith(right).scores
    rightScores += right.scores
    rightScores += right.roundWith(left).scores
  }
}

fun tryBruteforceGame(other: Figure, needScores: Long): Figure {
  for (me in setOf(Rock, Paper, Scissors)) {
    if (me.roundWith(other).scores == needScores) {
      return me
    }
  }
  throw IllegalStateException()
}

fun tryWin(other: Figure): Figure {
  return tryBruteforceGame(other, Win.scores)
}

fun tryLose(other: Figure): Figure {
  return tryBruteforceGame(other, Lose.scores)
}

fun tryDraw(other: Figure): Figure {
  return tryBruteforceGame(other, Draw.scores)
}

fun selectRightFigure(left: Figure, prompt: String): Figure {
  return when (prompt) {
    "X" -> tryLose(left)
    "Y" -> tryDraw(left)
    "Z" -> tryWin(left)
    else -> throw IllegalStateException()
  }
}

fun process(line: String) {
  val (leftMarker, rightPrompt) = line.split(' ')
  val left = parseFigure(leftMarker)
  val right = selectRightFigure(left, rightPrompt)
  game(left, right)
}

fun solution(): Long {
  return rightScores
}

fun main() {
  ::main
    .javaClass
    .getResourceAsStream("/input")!!
    .bufferedReader()
    .forEachLine(::process)
  println(solution())
}

Compiled from "Day.kt"
final class com.adventofcode.DayKt$main$2 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, kotlin.Unit> {
  public static final com.adventofcode.DayKt$main$2 INSTANCE;

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

  public final void invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #32                 // Method com/adventofcode/DayKt.process:(Ljava/lang/String;)V
      10: return

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #36                 // class java/lang/String
       5: invokevirtual #38                 // Method invoke:(Ljava/lang/String;)V
       8: getstatic     #44                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      11: areturn

  static {};
    Code:
       0: new           #2                  // class com/adventofcode/DayKt$main$2
       3: dup
       4: invokespecial #49                 // Method "<init>":()V
       7: putstatic     #51                 // Field INSTANCE:Lcom/adventofcode/DayKt$main$2;
      10: return
}

Compiled from "Day.kt"
public final class com.adventofcode.DayKt {
  public static final com.adventofcode.Figure parseFigure(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String s
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore_1
       8: aload_1
       9: invokevirtual #21                 // Method java/lang/String.hashCode:()I
      12: tableswitch   { // 65 to 67
                    65: 40
                    66: 52
                    67: 64
               default: 94
          }
      40: aload_1
      41: ldc           #23                 // String A
      43: invokevirtual #27                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      46: ifne          76
      49: goto          94
      52: aload_1
      53: ldc           #29                 // String B
      55: invokevirtual #27                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      58: ifne          82
      61: goto          94
      64: aload_1
      65: ldc           #31                 // String C
      67: invokevirtual #27                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      70: ifne          88
      73: goto          94
      76: getstatic     #37                 // Field com/adventofcode/Figure.Rock:Lcom/adventofcode/Figure;
      79: goto          102
      82: getstatic     #40                 // Field com/adventofcode/Figure.Paper:Lcom/adventofcode/Figure;
      85: goto          102
      88: getstatic     #43                 // Field com/adventofcode/Figure.Scissors:Lcom/adventofcode/Figure;
      91: goto          102
      94: new           #45                 // class java/lang/IllegalStateException
      97: dup
      98: invokespecial #49                 // Method java/lang/IllegalStateException."<init>":()V
     101: athrow
     102: areturn

  public static final com.adventofcode.Figure tryBruteforceGame(com.adventofcode.Figure, long);
    Code:
       0: aload_0
       1: ldc           #54                 // String other
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_3
       7: anewarray     #33                 // class com/adventofcode/Figure
      10: astore        4
      12: aload         4
      14: iconst_0
      15: getstatic     #37                 // Field com/adventofcode/Figure.Rock:Lcom/adventofcode/Figure;
      18: aastore
      19: aload         4
      21: iconst_1
      22: getstatic     #40                 // Field com/adventofcode/Figure.Paper:Lcom/adventofcode/Figure;
      25: aastore
      26: aload         4
      28: iconst_2
      29: getstatic     #43                 // Field com/adventofcode/Figure.Scissors:Lcom/adventofcode/Figure;
      32: aastore
      33: aload         4
      35: invokestatic  #60                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      38: invokeinterface #66,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      43: astore_3
      44: aload_3
      45: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          81
      53: aload_3
      54: invokeinterface #76,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: checkcast     #33                 // class com/adventofcode/Figure
      62: astore        4
      64: aload         4
      66: aload_0
      67: invokevirtual #80                 // Method com/adventofcode/Figure.roundWith:(Lcom/adventofcode/Figure;)Lcom/adventofcode/Round;
      70: invokevirtual #86                 // Method com/adventofcode/Round.getScores:()J
      73: lload_1
      74: lcmp
      75: ifne          44
      78: aload         4
      80: areturn
      81: new           #45                 // class java/lang/IllegalStateException
      84: dup
      85: invokespecial #49                 // Method java/lang/IllegalStateException."<init>":()V
      88: athrow

  public static final com.adventofcode.Figure tryWin(com.adventofcode.Figure);
    Code:
       0: aload_0
       1: ldc           #54                 // String other
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getstatic     #95                 // Field com/adventofcode/Round.Win:Lcom/adventofcode/Round;
      10: invokevirtual #86                 // Method com/adventofcode/Round.getScores:()J
      13: invokestatic  #97                 // Method tryBruteforceGame:(Lcom/adventofcode/Figure;J)Lcom/adventofcode/Figure;
      16: areturn

  public static final com.adventofcode.Figure tryLose(com.adventofcode.Figure);
    Code:
       0: aload_0
       1: ldc           #54                 // String other
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getstatic     #101                // Field com/adventofcode/Round.Lose:Lcom/adventofcode/Round;
      10: invokevirtual #86                 // Method com/adventofcode/Round.getScores:()J
      13: invokestatic  #97                 // Method tryBruteforceGame:(Lcom/adventofcode/Figure;J)Lcom/adventofcode/Figure;
      16: areturn

  public static final com.adventofcode.Figure tryDraw(com.adventofcode.Figure);
    Code:
       0: aload_0
       1: ldc           #54                 // String other
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getstatic     #105                // Field com/adventofcode/Round.Draw:Lcom/adventofcode/Round;
      10: invokevirtual #86                 // Method com/adventofcode/Round.getScores:()J
      13: invokestatic  #97                 // Method tryBruteforceGame:(Lcom/adventofcode/Figure;J)Lcom/adventofcode/Figure;
      16: areturn

  public static final com.adventofcode.Figure selectRightFigure(com.adventofcode.Figure, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #109                // String left
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #111                // String prompt
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: astore_2
      14: aload_2
      15: invokevirtual #21                 // Method java/lang/String.hashCode:()I
      18: tableswitch   { // 88 to 90
                    88: 44
                    89: 56
                    90: 68
               default: 101
          }
      44: aload_2
      45: ldc           #113                // String X
      47: invokevirtual #27                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      50: ifne          80
      53: goto          101
      56: aload_2
      57: ldc           #115                // String Y
      59: invokevirtual #27                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      62: ifne          87
      65: goto          101
      68: aload_2
      69: ldc           #117                // String Z
      71: invokevirtual #27                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      74: ifne          94
      77: goto          101
      80: aload_0
      81: invokestatic  #119                // Method tryLose:(Lcom/adventofcode/Figure;)Lcom/adventofcode/Figure;
      84: goto          109
      87: aload_0
      88: invokestatic  #121                // Method tryDraw:(Lcom/adventofcode/Figure;)Lcom/adventofcode/Figure;
      91: goto          109
      94: aload_0
      95: invokestatic  #123                // Method tryWin:(Lcom/adventofcode/Figure;)Lcom/adventofcode/Figure;
      98: goto          109
     101: new           #45                 // class java/lang/IllegalStateException
     104: dup
     105: invokespecial #49                 // Method java/lang/IllegalStateException."<init>":()V
     108: athrow
     109: areturn

  public static final void process(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #127                // String line
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #129                // class java/lang/CharSequence
      10: iconst_1
      11: newarray       char
      13: astore_2
      14: aload_2
      15: iconst_0
      16: bipush        32
      18: castore
      19: aload_2
      20: iconst_0
      21: iconst_0
      22: bipush        6
      24: aconst_null
      25: invokestatic  #135                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
      28: astore_1
      29: aload_1
      30: iconst_0
      31: invokeinterface #141,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      36: checkcast     #17                 // class java/lang/String
      39: astore_2
      40: aload_1
      41: iconst_1
      42: invokeinterface #141,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      47: checkcast     #17                 // class java/lang/String
      50: astore_3
      51: aload_2
      52: invokestatic  #143                // Method parseFigure:(Ljava/lang/String;)Lcom/adventofcode/Figure;
      55: astore        4
      57: aload         4
      59: aload_3
      60: invokestatic  #145                // Method selectRightFigure:(Lcom/adventofcode/Figure;Ljava/lang/String;)Lcom/adventofcode/Figure;
      63: astore        5
      65: getstatic     #151                // Field com/adventofcode/Game.INSTANCE:Lcom/adventofcode/Game;
      68: aload         4
      70: aload         5
      72: invokevirtual #155                // Method com/adventofcode/Game.game:(Lcom/adventofcode/Figure;Lcom/adventofcode/Figure;)V
      75: return

  public static final long solution();
    Code:
       0: getstatic     #151                // Field com/adventofcode/Game.INSTANCE:Lcom/adventofcode/Game;
       3: invokevirtual #162                // Method com/adventofcode/Game.getRightScores:()J
       6: lreturn

  public static final void main();
    Code:
       0: getstatic     #168                // Field com/adventofcode/DayKt$main$1.INSTANCE:Lcom/adventofcode/DayKt$main$1;
       3: invokevirtual #172                // Method java/lang/Object.getClass:()Ljava/lang/Class;
       6: ldc           #174                // String /input
       8: invokevirtual #180                // Method java/lang/Class.getResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
      11: dup
      12: invokestatic  #184                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      15: astore_0
      16: getstatic     #190                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      19: astore_1
      20: new           #192                // class java/io/InputStreamReader
      23: dup
      24: aload_0
      25: aload_1
      26: invokespecial #195                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      29: checkcast     #197                // class java/io/Reader
      32: astore_2
      33: sipush        8192
      36: istore_3
      37: aload_2
      38: instanceof    #199                // class java/io/BufferedReader
      41: ifeq          51
      44: aload_2
      45: checkcast     #199                // class java/io/BufferedReader
      48: goto          60
      51: new           #199                // class java/io/BufferedReader
      54: dup
      55: aload_2
      56: iload_3
      57: invokespecial #202                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      60: checkcast     #197                // class java/io/Reader
      63: getstatic     #207                // Field com/adventofcode/DayKt$main$2.INSTANCE:Lcom/adventofcode/DayKt$main$2;
      66: checkcast     #209                // class kotlin/jvm/functions/Function1
      69: invokestatic  #215                // Method kotlin/io/TextStreamsKt.forEachLine:(Ljava/io/Reader;Lkotlin/jvm/functions/Function1;)V
      72: invokestatic  #217                // Method solution:()J
      75: lstore_0
      76: getstatic     #223                // Field java/lang/System.out:Ljava/io/PrintStream;
      79: lload_0
      80: invokevirtual #229                // Method java/io/PrintStream.println:(J)V
      83: return

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

Compiled from "Day.kt"
final class com.adventofcode.DayKt$main$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function0<kotlin.Unit> {
  public static final com.adventofcode.DayKt$main$1 INSTANCE;

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

  public final void invoke();
    Code:
       0: invokestatic  #23                 // Method com/adventofcode/DayKt.main:()V
       3: return

  public java.lang.Object invoke();
    Code:
       0: aload_0
       1: invokevirtual #26                 // Method invoke:()V
       4: getstatic     #32                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
       7: areturn

  static {};
    Code:
       0: new           #2                  // class com/adventofcode/DayKt$main$1
       3: dup
       4: invokespecial #35                 // Method "<init>":()V
       7: putstatic     #37                 // Field INSTANCE:Lcom/adventofcode/DayKt$main$1;
      10: return
}


package treesandgraphs

private data class Vertex(val name: String, val edges: MutableList<Pair<Vertex, Double>>) {
    var visited = false
}

class EvaluateDivision {
    private val vertexes = mutableMapOf<String, Vertex>()

    private fun dfs(v: Vertex, target: Vertex, value: Double): Pair<Boolean, Double> {
        v.visited = true
        if (v === target) {
            return true to value
        }
        for (e in v.edges) {
            if (!e.first.visited) {
                val r = dfs(e.first, target, value * e.second)
                if (r.first) {
                    return r
                }
            }
        }
        return false to -1.0
    }

    fun calcEquation(equations: List<List<String>>, values: DoubleArray, queries: List<List<String>>): DoubleArray {
        for (i in equations.indices) {
            val v1 = vertexes[equations[i][0]] ?: Vertex(equations[i][0], mutableListOf())
            val v2 = vertexes[equations[i][1]] ?: Vertex(equations[i][1], mutableListOf())
            v1.edges.add(v2 to values[i])
            v2.edges.add(v1 to 1.0 / values[i])

            vertexes[v1.name] = v1
            vertexes[v2.name] = v2
        }

        val ret = DoubleArray(queries.size) { -1.0 }
        for ((i, q) in queries.withIndex()) {
            var v1 = vertexes[q[0]]
            var v2 = vertexes[q[1]]

            if (v1 != null && v2 != null) {
                for (entry in vertexes.entries) {
                    entry.value.visited = false
                }
                ret[i] = dfs(v1, v2, 1.0).second
            }
        }
        return ret
    }
}

Compiled from "EvaluateDivision.kt"
public final class treesandgraphs.EvaluateDivision {
  private final java.util.Map<java.lang.String, treesandgraphs.Vertex> vertexes;

  public treesandgraphs.EvaluateDivision();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: new           #10                 // class java/util/LinkedHashMap
       8: dup
       9: invokespecial #11                 // Method java/util/LinkedHashMap."<init>":()V
      12: checkcast     #13                 // class java/util/Map
      15: putfield      #17                 // Field vertexes:Ljava/util/Map;
      18: return

  private final kotlin.Pair<java.lang.Boolean, java.lang.Double> dfs(treesandgraphs.Vertex, treesandgraphs.Vertex, double);
    Code:
       0: aload_1
       1: iconst_1
       2: invokevirtual #28                 // Method treesandgraphs/Vertex.setVisited:(Z)V
       5: aload_1
       6: aload_2
       7: if_acmpne     22
      10: iconst_1
      11: invokestatic  #34                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      14: dload_3
      15: invokestatic  #39                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      18: invokestatic  #45                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      21: areturn
      22: aload_1
      23: invokevirtual #49                 // Method treesandgraphs/Vertex.getEdges:()Ljava/util/List;
      26: invokeinterface #55,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      31: astore        5
      33: aload         5
      35: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifeq          114
      43: aload         5
      45: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      50: checkcast     #67                 // class kotlin/Pair
      53: astore        6
      55: aload         6
      57: invokevirtual #70                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      60: checkcast     #24                 // class treesandgraphs/Vertex
      63: invokevirtual #73                 // Method treesandgraphs/Vertex.getVisited:()Z
      66: ifne          33
      69: aload_0
      70: aload         6
      72: invokevirtual #70                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      75: checkcast     #24                 // class treesandgraphs/Vertex
      78: aload_2
      79: dload_3
      80: aload         6
      82: invokevirtual #76                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      85: checkcast     #78                 // class java/lang/Number
      88: invokevirtual #82                 // Method java/lang/Number.doubleValue:()D
      91: dmul
      92: invokespecial #84                 // Method dfs:(Ltreesandgraphs/Vertex;Ltreesandgraphs/Vertex;D)Lkotlin/Pair;
      95: astore        7
      97: aload         7
      99: invokevirtual #70                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     102: checkcast     #30                 // class java/lang/Boolean
     105: invokevirtual #87                 // Method java/lang/Boolean.booleanValue:()Z
     108: ifeq          33
     111: aload         7
     113: areturn
     114: iconst_0
     115: invokestatic  #34                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     118: ldc2_w        #88                 // double -1.0d
     121: invokestatic  #39                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     124: invokestatic  #45                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     127: areturn

  public final double[] calcEquation(java.util.List<? extends java.util.List<java.lang.String>>, double[], java.util.List<? extends java.util.List<java.lang.String>>);
    Code:
       0: aload_1
       1: ldc           #103                // String equations
       3: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #111                // String values
       9: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #113                // String queries
      15: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: iconst_0
      19: istore        4
      21: aload_1
      22: checkcast     #115                // class java/util/Collection
      25: invokeinterface #119,  1          // InterfaceMethod java/util/Collection.size:()I
      30: istore        5
      32: iload         4
      34: iload         5
      36: if_icmpge     273
      39: aload_0
      40: getfield      #17                 // Field vertexes:Ljava/util/Map;
      43: aload_1
      44: iload         4
      46: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      51: checkcast     #51                 // class java/util/List
      54: iconst_0
      55: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: invokeinterface #126,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      65: checkcast     #24                 // class treesandgraphs/Vertex
      68: dup
      69: ifnonnull     110
      72: pop
      73: new           #24                 // class treesandgraphs/Vertex
      76: dup
      77: aload_1
      78: iload         4
      80: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      85: checkcast     #51                 // class java/util/List
      88: iconst_0
      89: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      94: checkcast     #128                // class java/lang/String
      97: new           #130                // class java/util/ArrayList
     100: dup
     101: invokespecial #131                // Method java/util/ArrayList."<init>":()V
     104: checkcast     #51                 // class java/util/List
     107: invokespecial #134                // Method treesandgraphs/Vertex."<init>":(Ljava/lang/String;Ljava/util/List;)V
     110: astore        6
     112: aload_0
     113: getfield      #17                 // Field vertexes:Ljava/util/Map;
     116: aload_1
     117: iload         4
     119: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     124: checkcast     #51                 // class java/util/List
     127: iconst_1
     128: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     133: invokeinterface #126,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     138: checkcast     #24                 // class treesandgraphs/Vertex
     141: dup
     142: ifnonnull     183
     145: pop
     146: new           #24                 // class treesandgraphs/Vertex
     149: dup
     150: aload_1
     151: iload         4
     153: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     158: checkcast     #51                 // class java/util/List
     161: iconst_1
     162: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     167: checkcast     #128                // class java/lang/String
     170: new           #130                // class java/util/ArrayList
     173: dup
     174: invokespecial #131                // Method java/util/ArrayList."<init>":()V
     177: checkcast     #51                 // class java/util/List
     180: invokespecial #134                // Method treesandgraphs/Vertex."<init>":(Ljava/lang/String;Ljava/util/List;)V
     183: astore        7
     185: aload         6
     187: invokevirtual #49                 // Method treesandgraphs/Vertex.getEdges:()Ljava/util/List;
     190: aload         7
     192: aload_2
     193: iload         4
     195: daload
     196: invokestatic  #39                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     199: invokestatic  #45                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     202: invokeinterface #138,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     207: pop
     208: aload         7
     210: invokevirtual #49                 // Method treesandgraphs/Vertex.getEdges:()Ljava/util/List;
     213: aload         6
     215: dconst_1
     216: aload_2
     217: iload         4
     219: daload
     220: ddiv
     221: invokestatic  #39                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     224: invokestatic  #45                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     227: invokeinterface #138,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     232: pop
     233: aload_0
     234: getfield      #17                 // Field vertexes:Ljava/util/Map;
     237: aload         6
     239: invokevirtual #142                // Method treesandgraphs/Vertex.getName:()Ljava/lang/String;
     242: aload         6
     244: invokeinterface #146,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     249: pop
     250: aload_0
     251: getfield      #17                 // Field vertexes:Ljava/util/Map;
     254: aload         7
     256: invokevirtual #142                // Method treesandgraphs/Vertex.getName:()Ljava/lang/String;
     259: aload         7
     261: invokeinterface #146,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     266: pop
     267: iinc          4, 1
     270: goto          32
     273: iconst_0
     274: istore        5
     276: aload_3
     277: invokeinterface #147,  1          // InterfaceMethod java/util/List.size:()I
     282: istore        6
     284: iload         6
     286: newarray       double
     288: astore        7
     290: iload         5
     292: iload         6
     294: if_icmpge     315
     297: iload         5
     299: istore        8
     301: aload         7
     303: iload         8
     305: ldc2_w        #88                 // double -1.0d
     308: dastore
     309: iinc          5, 1
     312: goto          290
     315: aload         7
     317: astore        4
     319: aload_3
     320: checkcast     #149                // class java/lang/Iterable
     323: invokeinterface #150,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     328: astore        5
     330: iconst_0
     331: istore        6
     333: aload         5
     335: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     340: ifeq          500
     343: iload         6
     345: istore        7
     347: iload         6
     349: iconst_1
     350: iadd
     351: istore        6
     353: aload         5
     355: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     360: checkcast     #51                 // class java/util/List
     363: astore        8
     365: aload_0
     366: getfield      #17                 // Field vertexes:Ljava/util/Map;
     369: aload         8
     371: iconst_0
     372: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     377: invokeinterface #126,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     382: checkcast     #24                 // class treesandgraphs/Vertex
     385: astore        9
     387: aload_0
     388: getfield      #17                 // Field vertexes:Ljava/util/Map;
     391: aload         8
     393: iconst_1
     394: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     399: invokeinterface #126,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     404: checkcast     #24                 // class treesandgraphs/Vertex
     407: astore        10
     409: aload         9
     411: ifnull        333
     414: aload         10
     416: ifnull        333
     419: aload_0
     420: getfield      #17                 // Field vertexes:Ljava/util/Map;
     423: invokeinterface #154,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     428: invokeinterface #157,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     433: astore        11
     435: aload         11
     437: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     442: ifeq          474
     445: aload         11
     447: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     452: checkcast     #159                // class java/util/Map$Entry
     455: astore        12
     457: aload         12
     459: invokeinterface #162,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     464: checkcast     #24                 // class treesandgraphs/Vertex
     467: iconst_0
     468: invokevirtual #28                 // Method treesandgraphs/Vertex.setVisited:(Z)V
     471: goto          435
     474: aload         4
     476: iload         7
     478: aload_0
     479: aload         9
     481: aload         10
     483: dconst_1
     484: invokespecial #84                 // Method dfs:(Ltreesandgraphs/Vertex;Ltreesandgraphs/Vertex;D)Lkotlin/Pair;
     487: invokevirtual #76                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     490: checkcast     #78                 // class java/lang/Number
     493: invokevirtual #82                 // Method java/lang/Number.doubleValue:()D
     496: dastore
     497: goto          333
     500: aload         4
     502: areturn
}