object Puzzle7 {

    @JvmStatic
    fun main(args: Array<String>) {
        val rules = Rules(Puzzle7::class.java.getResource("puzzle7.txt").readText().split("\n"))
        val sumOfAvailableOuterColors =  rules.countContainingBags("shiny gold")
        println(sumOfAvailableOuterColors)

        val sumOfAvailableInnreColors = rules.countAllInnerBags("shiny gold")
        println(sumOfAvailableInnreColors)

    }

    class Rules {
        val bagRules = HashMap<String, HashMap<String, Int>?>()

        constructor(input: List<String>){
            input.forEach { line ->

                val bagColorRegexp = "^([^ ]+ [^ ]+) bags contain (.+)\\.$".toRegex()
                val bagListRegexp = "^(\\d+) ([^ ]+ [^ ]+) bags?$".toRegex()

                val matchResult = bagColorRegexp.find(line)
                val bagColor = matchResult?.groups?.get(1)?.value!!
                val containingString = matchResult.groups[2]?.value!!

                if (containingString == "no other bags"){
                    bagRules[bagColor] = null
                }else{
                    val bagStringList = containingString.split(", ")
                    bagRules[bagColor] = HashMap()
                    bagStringList.forEach { bagCountString ->
                        val bagMatchResult = bagListRegexp.find(bagCountString)
                        val bagCount = bagMatchResult?.groups?.get(1)?.value?.toInt()!!
                        val innerBagColor = bagMatchResult.groups[2]?.value!!
                        bagRules[bagColor]!![innerBagColor] = bagCount
                    }
                }
            }
        }

        fun countContainingBags(color: String): Int {
            val foundParents = HashSet<String>()
            var count: Int
            var addedCount: Int
            var lookFor: HashSet<String> = hashSetOf(color)
            do {
                count = foundParents.count()
                val parents = bagRules.filter { rule ->
                    if (rule.value != null)
                        lookFor.any { rule.value!!.containsKey(it) }
                    else
                        false
                }
                lookFor = parents.keys.toHashSet()
                foundParents.addAll(lookFor)
                addedCount = foundParents.count() - count
            }while (addedCount > 0)
            return foundParents.count()
        }

        fun countAllInnerBags(color: String) = countInnerBags(color) - 1

        private fun countInnerBags(color: String): Int {
            return if (bagRules[color] == null){
                1
            }else{
                var retVal = 1
                bagRules[color]!!.forEach { c, cnt ->
                    retVal += cnt * countInnerBags(c)
                }
                retVal
            }
        }

    }

}

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

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

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #16                 // String args
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #24                 // class Puzzle7$Rules
       9: dup
      10: ldc           #2                  // class Puzzle7
      12: ldc           #26                 // String puzzle7.txt
      14: invokevirtual #32                 // Method java/lang/Class.getResource:(Ljava/lang/String;)Ljava/net/URL;
      17: dup
      18: ldc           #34                 // String getResource(...)
      20: invokestatic  #37                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      23: astore_2
      24: getstatic     #43                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      27: astore_3
      28: aload_2
      29: invokestatic  #49                 // Method kotlin/io/TextStreamsKt.readBytes:(Ljava/net/URL;)[B
      32: astore        4
      34: new           #51                 // class java/lang/String
      37: dup
      38: aload         4
      40: aload_3
      41: invokespecial #54                 // Method java/lang/String."<init>":([BLjava/nio/charset/Charset;)V
      44: checkcast     #56                 // class java/lang/CharSequence
      47: iconst_1
      48: anewarray     #51                 // class java/lang/String
      51: astore_2
      52: aload_2
      53: iconst_0
      54: ldc           #58                 // String \n
      56: aastore
      57: aload_2
      58: iconst_0
      59: iconst_0
      60: bipush        6
      62: aconst_null
      63: invokestatic  #64                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      66: invokespecial #67                 // Method Puzzle7$Rules."<init>":(Ljava/util/List;)V
      69: astore_1
      70: aload_1
      71: ldc           #69                 // String shiny gold
      73: invokevirtual #73                 // Method Puzzle7$Rules.countContainingBags:(Ljava/lang/String;)I
      76: istore_2
      77: getstatic     #79                 // Field java/lang/System.out:Ljava/io/PrintStream;
      80: iload_2
      81: invokevirtual #85                 // Method java/io/PrintStream.println:(I)V
      84: aload_1
      85: ldc           #69                 // String shiny gold
      87: invokevirtual #88                 // Method Puzzle7$Rules.countAllInnerBags:(Ljava/lang/String;)I
      90: istore_3
      91: getstatic     #79                 // Field java/lang/System.out:Ljava/io/PrintStream;
      94: iload_3
      95: invokevirtual #85                 // Method java/io/PrintStream.println:(I)V
      98: return

  static {};
    Code:
       0: new           #2                  // class Puzzle7
       3: dup
       4: invokespecial #96                 // Method "<init>":()V
       7: putstatic     #99                 // Field INSTANCE:LPuzzle7;
      10: return
}

Compiled from "Puzzle7.kt"
public final class Puzzle7$Rules {
  private final java.util.HashMap<java.lang.String, java.util.HashMap<java.lang.String, java.lang.Integer>> bagRules;

  public final java.util.HashMap<java.lang.String, java.util.HashMap<java.lang.String, java.lang.Integer>> getBagRules();
    Code:
       0: aload_0
       1: getfield      #12                 // Field bagRules:Ljava/util/HashMap;
       4: areturn

  public Puzzle7$Rules(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #19                 // String input
       3: invokestatic  #25                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #28                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: new           #30                 // class java/util/HashMap
      14: dup
      15: invokespecial #31                 // Method java/util/HashMap."<init>":()V
      18: putfield      #12                 // Field bagRules:Ljava/util/HashMap;
      21: aload_1
      22: checkcast     #33                 // class java/lang/Iterable
      25: astore_2
      26: iconst_0
      27: istore_3
      28: aload_2
      29: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      34: astore        4
      36: aload         4
      38: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          442
      46: aload         4
      48: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        5
      55: aload         5
      57: checkcast     #49                 // class java/lang/String
      60: astore        6
      62: iconst_0
      63: istore        7
      65: new           #51                 // class kotlin/text/Regex
      68: dup
      69: ldc           #53                 // String ^([^ ]+ [^ ]+) bags contain (.+)\\.$
      71: invokespecial #56                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      74: astore        8
      76: new           #51                 // class kotlin/text/Regex
      79: dup
      80: ldc           #58                 // String ^(\\d+) ([^ ]+ [^ ]+) bags?$
      82: invokespecial #56                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      85: astore        9
      87: aload         8
      89: aload         6
      91: checkcast     #60                 // class java/lang/CharSequence
      94: iconst_0
      95: iconst_2
      96: aconst_null
      97: invokestatic  #64                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     100: astore        10
     102: aload         10
     104: dup
     105: ifnull        133
     108: invokeinterface #70,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     113: dup
     114: ifnull        133
     117: iconst_1
     118: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     123: dup
     124: ifnull        133
     127: invokevirtual #82                 // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     130: goto          135
     133: pop
     134: aconst_null
     135: dup
     136: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     139: astore        11
     141: aload         10
     143: invokeinterface #70,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     148: iconst_2
     149: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     154: dup
     155: ifnull        164
     158: invokevirtual #82                 // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     161: goto          166
     164: pop
     165: aconst_null
     166: dup
     167: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     170: astore        12
     172: aload         12
     174: ldc           #88                 // String no other bags
     176: invokestatic  #92                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     179: ifeq          201
     182: aload_0
     183: getfield      #12                 // Field bagRules:Ljava/util/HashMap;
     186: checkcast     #94                 // class java/util/Map
     189: aload         11
     191: aconst_null
     192: invokeinterface #98,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     197: pop
     198: goto          437
     201: aload         12
     203: checkcast     #60                 // class java/lang/CharSequence
     206: iconst_1
     207: anewarray     #49                 // class java/lang/String
     210: astore        13
     212: aload         13
     214: iconst_0
     215: ldc           #100                // String ,
     217: aastore
     218: aload         13
     220: iconst_0
     221: iconst_0
     222: bipush        6
     224: aconst_null
     225: invokestatic  #106                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     228: astore        14
     230: aload_0
     231: getfield      #12                 // Field bagRules:Ljava/util/HashMap;
     234: checkcast     #94                 // class java/util/Map
     237: aload         11
     239: new           #30                 // class java/util/HashMap
     242: dup
     243: invokespecial #31                 // Method java/util/HashMap."<init>":()V
     246: invokeinterface #98,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     251: pop
     252: aload         14
     254: checkcast     #33                 // class java/lang/Iterable
     257: astore        13
     259: iconst_0
     260: istore        15
     262: aload         13
     264: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     269: astore        16
     271: aload         16
     273: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     278: ifeq          436
     281: aload         16
     283: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     288: astore        17
     290: aload         17
     292: checkcast     #49                 // class java/lang/String
     295: astore        18
     297: iconst_0
     298: istore        19
     300: aload         9
     302: aload         18
     304: checkcast     #60                 // class java/lang/CharSequence
     307: iconst_0
     308: iconst_2
     309: aconst_null
     310: invokestatic  #64                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     313: astore        20
     315: aload         20
     317: dup
     318: ifnull        356
     321: invokeinterface #70,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     326: dup
     327: ifnull        356
     330: iconst_1
     331: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     336: dup
     337: ifnull        356
     340: invokevirtual #82                 // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     343: dup
     344: ifnull        356
     347: invokestatic  #112                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     350: invokestatic  #116                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     353: goto          358
     356: pop
     357: aconst_null
     358: dup
     359: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     362: invokevirtual #120                // Method java/lang/Integer.intValue:()I
     365: istore        21
     367: aload         20
     369: invokeinterface #70,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     374: iconst_2
     375: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     380: dup
     381: ifnull        390
     384: invokevirtual #82                 // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     387: goto          392
     390: pop
     391: aconst_null
     392: dup
     393: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     396: astore        22
     398: iload         21
     400: invokestatic  #116                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     403: astore        23
     405: aload_0
     406: getfield      #12                 // Field bagRules:Ljava/util/HashMap;
     409: aload         11
     411: invokevirtual #123                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     414: dup
     415: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     418: checkcast     #94                 // class java/util/Map
     421: aload         22
     423: aload         23
     425: invokeinterface #98,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     430: pop
     431: nop
     432: nop
     433: goto          271
     436: nop
     437: nop
     438: nop
     439: goto          36
     442: nop
     443: return

  public final int countContainingBags(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #151                // String color
       3: invokestatic  #25                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #153                // class java/util/HashSet
       9: dup
      10: invokespecial #154                // Method java/util/HashSet."<init>":()V
      13: astore_2
      14: iconst_0
      15: istore_3
      16: iconst_0
      17: istore        4
      19: aconst_null
      20: astore        5
      22: iconst_1
      23: anewarray     #49                 // class java/lang/String
      26: astore        6
      28: aload         6
      30: iconst_0
      31: aload_1
      32: aastore
      33: aload         6
      35: invokestatic  #160                // Method kotlin/collections/SetsKt.hashSetOf:([Ljava/lang/Object;)Ljava/util/HashSet;
      38: astore        5
      40: aload_2
      41: checkcast     #162                // class java/util/Collection
      44: invokeinterface #165,  1          // InterfaceMethod java/util/Collection.size:()I
      49: istore_3
      50: aload_0
      51: getfield      #12                 // Field bagRules:Ljava/util/HashMap;
      54: checkcast     #94                 // class java/util/Map
      57: astore        7
      59: iconst_0
      60: istore        8
      62: aload         7
      64: astore        9
      66: new           #167                // class java/util/LinkedHashMap
      69: dup
      70: invokespecial #168                // Method java/util/LinkedHashMap."<init>":()V
      73: checkcast     #94                 // class java/util/Map
      76: astore        10
      78: iconst_0
      79: istore        11
      81: aload         9
      83: invokeinterface #172,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      88: invokeinterface #175,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      93: astore        12
      95: aload         12
      97: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     102: ifeq          266
     105: aload         12
     107: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     112: checkcast     #177                // class java/util/Map$Entry
     115: astore        13
     117: aload         13
     119: astore        14
     121: iconst_0
     122: istore        15
     124: aload         14
     126: invokeinterface #179,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     131: ifnull        237
     134: aload         5
     136: checkcast     #33                 // class java/lang/Iterable
     139: astore        16
     141: iconst_0
     142: istore        17
     144: aload         16
     146: instanceof    #162                // class java/util/Collection
     149: ifeq          169
     152: aload         16
     154: checkcast     #162                // class java/util/Collection
     157: invokeinterface #182,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     162: ifeq          169
     165: iconst_0
     166: goto          238
     169: aload         16
     171: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     176: astore        18
     178: aload         18
     180: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     185: ifeq          233
     188: aload         18
     190: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     195: astore        19
     197: aload         19
     199: checkcast     #49                 // class java/lang/String
     202: astore        20
     204: iconst_0
     205: istore        21
     207: aload         14
     209: invokeinterface #179,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     214: dup
     215: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     218: checkcast     #30                 // class java/util/HashMap
     221: aload         20
     223: invokevirtual #186                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
     226: ifeq          178
     229: iconst_1
     230: goto          238
     233: iconst_0
     234: goto          238
     237: iconst_0
     238: ifeq          95
     241: aload         10
     243: aload         13
     245: invokeinterface #189,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     250: aload         13
     252: invokeinterface #179,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     257: invokeinterface #98,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     262: pop
     263: goto          95
     266: aload         10
     268: nop
     269: astore        6
     271: aload         6
     273: invokeinterface #192,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     278: checkcast     #33                 // class java/lang/Iterable
     281: invokestatic  #198                // Method kotlin/collections/CollectionsKt.toHashSet:(Ljava/lang/Iterable;)Ljava/util/HashSet;
     284: astore        5
     286: aload_2
     287: aload         5
     289: checkcast     #162                // class java/util/Collection
     292: invokevirtual #202                // Method java/util/HashSet.addAll:(Ljava/util/Collection;)Z
     295: pop
     296: aload_2
     297: checkcast     #162                // class java/util/Collection
     300: invokeinterface #165,  1          // InterfaceMethod java/util/Collection.size:()I
     305: iload_3
     306: isub
     307: istore        4
     309: iload         4
     311: ifgt          40
     314: aload_2
     315: checkcast     #162                // class java/util/Collection
     318: invokeinterface #165,  1          // InterfaceMethod java/util/Collection.size:()I
     323: ireturn

  public final int countAllInnerBags(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #151                // String color
       3: invokestatic  #25                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #226                // Method countInnerBags:(Ljava/lang/String;)I
      11: iconst_1
      12: isub
      13: ireturn

  private final int countInnerBags(java.lang.String);
    Code:
       0: aload_0
       1: getfield      #12                 // Field bagRules:Ljava/util/HashMap;
       4: aload_1
       5: invokevirtual #123                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
       8: ifnonnull     15
      11: iconst_1
      12: goto          62
      15: new           #228                // class kotlin/jvm/internal/Ref$IntRef
      18: dup
      19: invokespecial #229                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      22: astore_2
      23: aload_2
      24: iconst_1
      25: putfield      #232                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      28: aload_0
      29: getfield      #12                 // Field bagRules:Ljava/util/HashMap;
      32: aload_1
      33: invokevirtual #123                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      36: dup
      37: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      40: checkcast     #30                 // class java/util/HashMap
      43: aload_2
      44: aload_0
      45: invokedynamic #251,  0            // InvokeDynamic #0:invoke:(Lkotlin/jvm/internal/Ref$IntRef;LPuzzle7$Rules;)Lkotlin/jvm/functions/Function2;
      50: invokedynamic #262,  0            // InvokeDynamic #1:accept:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiConsumer;
      55: invokevirtual #266                // Method java/util/HashMap.forEach:(Ljava/util/function/BiConsumer;)V
      58: aload_2
      59: getfield      #232                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      62: ireturn

  private static final kotlin.Unit countInnerBags$lambda$4(kotlin.jvm.internal.Ref$IntRef, Puzzle7$Rules, java.lang.String, java.lang.Integer);
    Code:
       0: aload_2
       1: ldc_w         #270                // String c
       4: invokestatic  #25                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_3
       8: ldc_w         #272                // String cnt
      11: invokestatic  #25                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_0
      15: aload_0
      16: getfield      #232                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      19: aload_3
      20: invokevirtual #120                // Method java/lang/Integer.intValue:()I
      23: aload_1
      24: aload_2
      25: invokespecial #226                // Method countInnerBags:(Ljava/lang/String;)I
      28: imul
      29: iadd
      30: putfield      #232                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      33: getstatic     #278                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      36: areturn

  private static final void countInnerBags$lambda$5(kotlin.jvm.functions.Function2, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokeinterface #285,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
       8: pop
       9: return
}


import java.math.BigInteger
import kotlin.math.pow

object Puzzle14 {

    @JvmStatic
    fun main(args: Array<String>) {
        val input = Puzzle14::class.java.getResource("puzzle14.txt").readText()
        val program1 = Program(input)
        program1.run()
        println(program1.sumOfUsedMemoryAddresses())
        val program2 = Program(input)
        program2.runV2()
        println(program2.sumOfUsedMemoryAddresses())
    }

    class Program(input: String) {
        private val subPrograms = mutableListOf<SubProgram>()
        private val memory = HashMap<BigInteger, BigInteger>()

        private val memorySetterRegex = "^mem\\[(\\d+)\\] = (\\d+)$".toRegex()

        init {
            input.split("\n").forEach { line ->
                if (line.startsWith("mask = ")){
                    val mask = line.split(" = ")[1]
                    subPrograms.add(SubProgram(mask))
                }else{
                    val matchResult = memorySetterRegex.find(line)
                    val memAddress = matchResult?.groups?.get(1)?.value!!.toInt()
                    val memValue = matchResult.groups[2]?.value!!.toInt()
                    subPrograms.last().addStatement(memAddress, memValue)
                }
            }
        }

        class SubProgram(private val mask: String) {
            private val statements = mutableListOf<Pair<Int, Int>>()
            private val memory = HashMap<BigInteger, BigInteger>()

            fun addStatement(memAddress: Int, memValue: Int){
                statements.add(Pair(memAddress, memValue))
            }

            fun run(): HashMap<BigInteger, BigInteger>{
                statements.forEach { s ->
                    val address = s.first.toBigInteger()
                    val originalValue = s.second.toString(2).padStart(mask.length, '0')
                    val maskedValue = mutableListOf<Char>()
                    for (i in mask.length-1 downTo 0){
                        val maskValue = mask[i]
                        val value =  originalValue[i]
                        maskedValue.add(0, if (maskValue == 'X') value else maskValue)
                    }

                    memory[address] = maskedValue.joinToString("").toBigInteger(2)
                }
                return memory
            }

            fun runV2(): HashMap<BigInteger, BigInteger>{
                statements.forEach { s ->
                    val originalAddress = s.first.toString(2).padStart(mask.length, '0')
                    val value = s.second.toBigInteger()
                    val maskedAddress = mutableListOf<Char>()
                    for (i in mask.length-1 downTo 0){
                        val maskValue = mask[i]
                        val address =  originalAddress[i]
                        maskedAddress.add(0,
                            when (maskValue) {
                                '0' -> address
                                '1' -> '1'
                                else -> 'F'
                            }
                        )
                    }

                    val floatingBitCount = maskedAddress.count { it == 'F' }
                    for (i in 0..(2.toDouble().pow(floatingBitCount.toDouble()).toInt())){
                        val number = i.toString(2).padStart(floatingBitCount, '0')
                        val floatedAddress = mutableListOf<Char>()
                        var numberIndex = 0
                        for (char in maskedAddress){
                            if (char == 'F'){
                                floatedAddress.add(number[numberIndex])
                                numberIndex++
                            }else{
                                floatedAddress.add(char)
                            }
                        }
                        memory[floatedAddress.joinToString("").toBigInteger(2)] = value
                    }

                }
                return memory
            }
        }

        fun run(){
            subPrograms.forEach { subProgram ->
                val subProgramMemory = subProgram.run()
                subProgramMemory.forEach { (address, value) ->
                    memory[address] = value
                }
            }
        }

        fun runV2(){
            subPrograms.forEach { subProgram ->
                val subProgramMemory = subProgram.runV2()
                subProgramMemory.forEach { (address, value) ->
                    memory[address] = value
                }
            }
        }

        fun sumOfUsedMemoryAddresses() = memory.filter { it.value != BigInteger.ZERO }.values.sumOf { it }
    }
}

Compiled from "Puzzle14.kt"
public final class Puzzle14$Program$SubProgram {
  private final java.lang.String mask;

  private final java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>> statements;

  private final java.util.HashMap<java.math.BigInteger, java.math.BigInteger> memory;

  public Puzzle14$Program$SubProgram(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String mask
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #21                 // Field mask:Ljava/lang/String;
      15: aload_0
      16: new           #23                 // class java/util/ArrayList
      19: dup
      20: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      23: checkcast     #26                 // class java/util/List
      26: putfield      #30                 // Field statements:Ljava/util/List;
      29: aload_0
      30: new           #32                 // class java/util/HashMap
      33: dup
      34: invokespecial #33                 // Method java/util/HashMap."<init>":()V
      37: putfield      #37                 // Field memory:Ljava/util/HashMap;
      40: return

  public final void addStatement(int, int);
    Code:
       0: aload_0
       1: getfield      #30                 // Field statements:Ljava/util/List;
       4: new           #43                 // class kotlin/Pair
       7: dup
       8: iload_1
       9: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      12: iload_2
      13: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      16: invokespecial #52                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      19: invokeinterface #56,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      24: pop
      25: return

  public final java.util.HashMap<java.math.BigInteger, java.math.BigInteger> run();
    Code:
       0: aload_0
       1: getfield      #30                 // Field statements:Ljava/util/List;
       4: checkcast     #64                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      16: astore_3
      17: aload_3
      18: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          238
      26: aload_3
      27: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: astore        4
      34: aload         4
      36: checkcast     #43                 // class kotlin/Pair
      39: astore        5
      41: iconst_0
      42: istore        6
      44: aload         5
      46: invokevirtual #81                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      49: checkcast     #83                 // class java/lang/Number
      52: invokevirtual #87                 // Method java/lang/Number.intValue:()I
      55: i2l
      56: invokestatic  #92                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
      59: dup
      60: ldc           #94                 // String valueOf(...)
      62: invokestatic  #97                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      65: astore        7
      67: aload         5
      69: invokevirtual #100                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      72: checkcast     #83                 // class java/lang/Number
      75: invokevirtual #87                 // Method java/lang/Number.intValue:()I
      78: iconst_2
      79: invokestatic  #106                // Method kotlin/text/CharsKt.checkRadix:(I)I
      82: invokestatic  #110                // Method java/lang/Integer.toString:(II)Ljava/lang/String;
      85: dup
      86: ldc           #112                // String toString(...)
      88: invokestatic  #97                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      91: aload_0
      92: getfield      #21                 // Field mask:Ljava/lang/String;
      95: invokevirtual #117                // Method java/lang/String.length:()I
      98: bipush        48
     100: invokestatic  #123                // Method kotlin/text/StringsKt.padStart:(Ljava/lang/String;IC)Ljava/lang/String;
     103: astore        8
     105: new           #23                 // class java/util/ArrayList
     108: dup
     109: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
     112: checkcast     #26                 // class java/util/List
     115: astore        9
     117: aload_0
     118: getfield      #21                 // Field mask:Ljava/lang/String;
     121: invokevirtual #117                // Method java/lang/String.length:()I
     124: iconst_1
     125: isub
     126: istore        10
     128: iconst_m1
     129: iload         10
     131: if_icmpge     185
     134: aload_0
     135: getfield      #21                 // Field mask:Ljava/lang/String;
     138: iload         10
     140: invokevirtual #127                // Method java/lang/String.charAt:(I)C
     143: istore        11
     145: aload         8
     147: iload         10
     149: invokevirtual #127                // Method java/lang/String.charAt:(I)C
     152: istore        12
     154: aload         9
     156: iconst_0
     157: iload         11
     159: bipush        88
     161: if_icmpne     169
     164: iload         12
     166: goto          171
     169: iload         11
     171: invokestatic  #132                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     174: invokeinterface #135,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     179: iinc          10, -1
     182: goto          128
     185: nop
     186: aload_0
     187: getfield      #37                 // Field memory:Ljava/util/HashMap;
     190: checkcast     #137                // class java/util/Map
     193: aload         7
     195: new           #89                 // class java/math/BigInteger
     198: dup
     199: aload         9
     201: checkcast     #64                 // class java/lang/Iterable
     204: ldc           #139                // String
     206: checkcast     #141                // class java/lang/CharSequence
     209: aconst_null
     210: aconst_null
     211: iconst_0
     212: aconst_null
     213: aconst_null
     214: bipush        62
     216: aconst_null
     217: invokestatic  #147                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     220: iconst_2
     221: invokestatic  #106                // Method kotlin/text/CharsKt.checkRadix:(I)I
     224: invokespecial #150                // Method java/math/BigInteger."<init>":(Ljava/lang/String;I)V
     227: invokeinterface #154,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     232: pop
     233: nop
     234: nop
     235: goto          17
     238: nop
     239: aload_0
     240: getfield      #37                 // Field memory:Ljava/util/HashMap;
     243: areturn

  public final java.util.HashMap<java.math.BigInteger, java.math.BigInteger> runV2();
    Code:
       0: aload_0
       1: getfield      #30                 // Field statements:Ljava/util/List;
       4: checkcast     #64                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      16: astore_3
      17: aload_3
      18: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          529
      26: aload_3
      27: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: astore        4
      34: aload         4
      36: checkcast     #43                 // class kotlin/Pair
      39: astore        5
      41: iconst_0
      42: istore        6
      44: aload         5
      46: invokevirtual #81                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      49: checkcast     #83                 // class java/lang/Number
      52: invokevirtual #87                 // Method java/lang/Number.intValue:()I
      55: iconst_2
      56: invokestatic  #106                // Method kotlin/text/CharsKt.checkRadix:(I)I
      59: invokestatic  #110                // Method java/lang/Integer.toString:(II)Ljava/lang/String;
      62: dup
      63: ldc           #112                // String toString(...)
      65: invokestatic  #97                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      68: aload_0
      69: getfield      #21                 // Field mask:Ljava/lang/String;
      72: invokevirtual #117                // Method java/lang/String.length:()I
      75: bipush        48
      77: invokestatic  #123                // Method kotlin/text/StringsKt.padStart:(Ljava/lang/String;IC)Ljava/lang/String;
      80: astore        7
      82: aload         5
      84: invokevirtual #100                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      87: checkcast     #83                 // class java/lang/Number
      90: invokevirtual #87                 // Method java/lang/Number.intValue:()I
      93: i2l
      94: invokestatic  #92                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
      97: dup
      98: ldc           #94                 // String valueOf(...)
     100: invokestatic  #97                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     103: astore        8
     105: new           #23                 // class java/util/ArrayList
     108: dup
     109: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
     112: checkcast     #26                 // class java/util/List
     115: astore        9
     117: aload_0
     118: getfield      #21                 // Field mask:Ljava/lang/String;
     121: invokevirtual #117                // Method java/lang/String.length:()I
     124: iconst_1
     125: isub
     126: istore        10
     128: iconst_m1
     129: iload         10
     131: if_icmpge     206
     134: aload_0
     135: getfield      #21                 // Field mask:Ljava/lang/String;
     138: iload         10
     140: invokevirtual #127                // Method java/lang/String.charAt:(I)C
     143: istore        11
     145: aload         7
     147: iload         10
     149: invokevirtual #127                // Method java/lang/String.charAt:(I)C
     152: istore        12
     154: aload         9
     156: iconst_0
     157: iload         11
     159: tableswitch   { // 48 to 49
                    48: 180
                    49: 185
               default: 190
          }
     180: iload         12
     182: goto          192
     185: bipush        49
     187: goto          192
     190: bipush        70
     192: invokestatic  #132                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     195: invokeinterface #135,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     200: iinc          10, -1
     203: goto          128
     206: aload         9
     208: checkcast     #64                 // class java/lang/Iterable
     211: astore        11
     213: iconst_0
     214: istore        12
     216: aload         11
     218: instanceof    #173                // class java/util/Collection
     221: ifeq          241
     224: aload         11
     226: checkcast     #173                // class java/util/Collection
     229: invokeinterface #176,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     234: ifeq          241
     237: iconst_0
     238: goto          316
     241: iconst_0
     242: istore        13
     244: aload         11
     246: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     251: astore        14
     253: aload         14
     255: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     260: ifeq          314
     263: aload         14
     265: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     270: astore        15
     272: aload         15
     274: checkcast     #129                // class java/lang/Character
     277: invokevirtual #180                // Method java/lang/Character.charValue:()C
     280: istore        16
     282: iconst_0
     283: istore        17
     285: iload         16
     287: bipush        70
     289: if_icmpne     296
     292: iconst_1
     293: goto          297
     296: iconst_0
     297: ifeq          253
     300: iinc          13, 1
     303: iload         13
     305: ifge          253
     308: invokestatic  #183                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     311: goto          253
     314: iload         13
     316: istore        10
     318: iconst_0
     319: istore        11
     321: ldc2_w        #184                // double 2.0d
     324: iload         10
     326: i2d
     327: invokestatic  #191                // Method java/lang/Math.pow:(DD)D
     330: d2i
     331: istore        12
     333: iload         11
     335: iload         12
     337: if_icmpgt     524
     340: iload         11
     342: iconst_2
     343: invokestatic  #106                // Method kotlin/text/CharsKt.checkRadix:(I)I
     346: invokestatic  #110                // Method java/lang/Integer.toString:(II)Ljava/lang/String;
     349: dup
     350: ldc           #112                // String toString(...)
     352: invokestatic  #97                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     355: iload         10
     357: bipush        48
     359: invokestatic  #123                // Method kotlin/text/StringsKt.padStart:(Ljava/lang/String;IC)Ljava/lang/String;
     362: astore        13
     364: new           #23                 // class java/util/ArrayList
     367: dup
     368: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
     371: checkcast     #26                 // class java/util/List
     374: astore        14
     376: iconst_0
     377: istore        15
     379: aload         9
     381: invokeinterface #192,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     386: astore        16
     388: aload         16
     390: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     395: ifeq          463
     398: aload         16
     400: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     405: checkcast     #129                // class java/lang/Character
     408: invokevirtual #180                // Method java/lang/Character.charValue:()C
     411: istore        17
     413: iload         17
     415: bipush        70
     417: if_icmpne     447
     420: aload         14
     422: aload         13
     424: iload         15
     426: invokevirtual #127                // Method java/lang/String.charAt:(I)C
     429: invokestatic  #132                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     432: invokeinterface #56,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     437: pop
     438: iload         15
     440: iinc          15, 1
     443: pop
     444: goto          388
     447: aload         14
     449: iload         17
     451: invokestatic  #132                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     454: invokeinterface #56,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     459: pop
     460: goto          388
     463: nop
     464: aload_0
     465: getfield      #37                 // Field memory:Ljava/util/HashMap;
     468: checkcast     #137                // class java/util/Map
     471: new           #89                 // class java/math/BigInteger
     474: dup
     475: aload         14
     477: checkcast     #64                 // class java/lang/Iterable
     480: ldc           #139                // String
     482: checkcast     #141                // class java/lang/CharSequence
     485: aconst_null
     486: aconst_null
     487: iconst_0
     488: aconst_null
     489: aconst_null
     490: bipush        62
     492: aconst_null
     493: invokestatic  #147                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     496: iconst_2
     497: invokestatic  #106                // Method kotlin/text/CharsKt.checkRadix:(I)I
     500: invokespecial #150                // Method java/math/BigInteger."<init>":(Ljava/lang/String;I)V
     503: aload         8
     505: invokeinterface #154,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     510: pop
     511: iload         11
     513: iload         12
     515: if_icmpeq     524
     518: iinc          11, 1
     521: goto          340
     524: nop
     525: nop
     526: goto          17
     529: nop
     530: aload_0
     531: getfield      #37                 // Field memory:Ljava/util/HashMap;
     534: areturn
}

Compiled from "Puzzle14.kt"
public final class Puzzle14$Program {
  private final java.util.List<Puzzle14$Program$SubProgram> subPrograms;

  private final java.util.HashMap<java.math.BigInteger, java.math.BigInteger> memory;

  private final kotlin.text.Regex memorySetterRegex;

  public Puzzle14$Program(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: new           #20                 // class java/util/ArrayList
      14: dup
      15: invokespecial #21                 // Method java/util/ArrayList."<init>":()V
      18: checkcast     #23                 // class java/util/List
      21: putfield      #27                 // Field subPrograms:Ljava/util/List;
      24: aload_0
      25: new           #29                 // class java/util/HashMap
      28: dup
      29: invokespecial #30                 // Method java/util/HashMap."<init>":()V
      32: putfield      #34                 // Field memory:Ljava/util/HashMap;
      35: aload_0
      36: new           #36                 // class kotlin/text/Regex
      39: dup
      40: ldc           #38                 // String ^mem\\[(\\d+)\\] = (\\d+)$
      42: invokespecial #40                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      45: putfield      #44                 // Field memorySetterRegex:Lkotlin/text/Regex;
      48: nop
      49: aload_1
      50: checkcast     #46                 // class java/lang/CharSequence
      53: iconst_1
      54: anewarray     #48                 // class java/lang/String
      57: astore_2
      58: aload_2
      59: iconst_0
      60: ldc           #50                 // String \n
      62: aastore
      63: aload_2
      64: iconst_0
      65: iconst_0
      66: bipush        6
      68: aconst_null
      69: invokestatic  #56                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      72: checkcast     #58                 // class java/lang/Iterable
      75: astore_2
      76: iconst_0
      77: istore_3
      78: aload_2
      79: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      84: astore        4
      86: aload         4
      88: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      93: ifeq          303
      96: aload         4
      98: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     103: astore        5
     105: aload         5
     107: checkcast     #48                 // class java/lang/String
     110: astore        6
     112: iconst_0
     113: istore        7
     115: aload         6
     117: ldc           #74                 // String mask =
     119: iconst_0
     120: iconst_2
     121: aconst_null
     122: invokestatic  #78                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     125: ifeq          188
     128: aload         6
     130: checkcast     #46                 // class java/lang/CharSequence
     133: iconst_1
     134: anewarray     #48                 // class java/lang/String
     137: astore        8
     139: aload         8
     141: iconst_0
     142: ldc           #80                 // String  =
     144: aastore
     145: aload         8
     147: iconst_0
     148: iconst_0
     149: bipush        6
     151: aconst_null
     152: invokestatic  #56                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     155: iconst_1
     156: invokeinterface #84,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     161: checkcast     #48                 // class java/lang/String
     164: astore        9
     166: aload_0
     167: getfield      #27                 // Field subPrograms:Ljava/util/List;
     170: new           #86                 // class Puzzle14$Program$SubProgram
     173: dup
     174: aload         9
     176: invokespecial #87                 // Method Puzzle14$Program$SubProgram."<init>":(Ljava/lang/String;)V
     179: invokeinterface #91,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     184: pop
     185: goto          298
     188: aload_0
     189: getfield      #44                 // Field memorySetterRegex:Lkotlin/text/Regex;
     192: aload         6
     194: checkcast     #46                 // class java/lang/CharSequence
     197: iconst_0
     198: iconst_2
     199: aconst_null
     200: invokestatic  #95                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     203: astore        9
     205: aload         9
     207: dup
     208: ifnull        236
     211: invokeinterface #101,  1          // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     216: dup
     217: ifnull        236
     220: iconst_1
     221: invokeinterface #106,  2          // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     226: dup
     227: ifnull        236
     230: invokevirtual #112                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     233: goto          238
     236: pop
     237: aconst_null
     238: dup
     239: invokestatic  #116                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     242: invokestatic  #122                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     245: istore        8
     247: aload         9
     249: invokeinterface #101,  1          // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     254: iconst_2
     255: invokeinterface #106,  2          // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     260: dup
     261: ifnull        270
     264: invokevirtual #112                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     267: goto          272
     270: pop
     271: aconst_null
     272: dup
     273: invokestatic  #116                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     276: invokestatic  #122                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     279: istore        10
     281: aload_0
     282: getfield      #27                 // Field subPrograms:Ljava/util/List;
     285: invokestatic  #128                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     288: checkcast     #86                 // class Puzzle14$Program$SubProgram
     291: iload         8
     293: iload         10
     295: invokevirtual #132                // Method Puzzle14$Program$SubProgram.addStatement:(II)V
     298: nop
     299: nop
     300: goto          86
     303: nop
     304: nop
     305: return

  public final void run();
    Code:
       0: aload_0
       1: getfield      #27                 // Field subPrograms:Ljava/util/List;
       4: checkcast     #58                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      16: astore_3
      17: aload_3
      18: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          156
      26: aload_3
      27: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: astore        4
      34: aload         4
      36: checkcast     #86                 // class Puzzle14$Program$SubProgram
      39: astore        5
      41: iconst_0
      42: istore        6
      44: aload         5
      46: invokevirtual #152                // Method Puzzle14$Program$SubProgram.run:()Ljava/util/HashMap;
      49: astore        7
      51: aload         7
      53: checkcast     #154                // class java/util/Map
      56: astore        8
      58: iconst_0
      59: istore        9
      61: aload         8
      63: invokeinterface #158,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      68: invokeinterface #161,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      73: astore        10
      75: aload         10
      77: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      82: ifeq          150
      85: aload         10
      87: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      92: checkcast     #163                // class java/util/Map$Entry
      95: astore        11
      97: aload         11
      99: astore        12
     101: iconst_0
     102: istore        13
     104: aload         12
     106: invokeinterface #166,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     111: checkcast     #168                // class java/math/BigInteger
     114: astore        14
     116: aload         12
     118: invokeinterface #170,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     123: checkcast     #168                // class java/math/BigInteger
     126: astore        15
     128: aload_0
     129: getfield      #34                 // Field memory:Ljava/util/HashMap;
     132: checkcast     #154                // class java/util/Map
     135: aload         14
     137: aload         15
     139: invokeinterface #174,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     144: pop
     145: nop
     146: nop
     147: goto          75
     150: nop
     151: nop
     152: nop
     153: goto          17
     156: nop
     157: return

  public final void runV2();
    Code:
       0: aload_0
       1: getfield      #27                 // Field subPrograms:Ljava/util/List;
       4: checkcast     #58                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      16: astore_3
      17: aload_3
      18: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          156
      26: aload_3
      27: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: astore        4
      34: aload         4
      36: checkcast     #86                 // class Puzzle14$Program$SubProgram
      39: astore        5
      41: iconst_0
      42: istore        6
      44: aload         5
      46: invokevirtual #187                // Method Puzzle14$Program$SubProgram.runV2:()Ljava/util/HashMap;
      49: astore        7
      51: aload         7
      53: checkcast     #154                // class java/util/Map
      56: astore        8
      58: iconst_0
      59: istore        9
      61: aload         8
      63: invokeinterface #158,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      68: invokeinterface #161,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      73: astore        10
      75: aload         10
      77: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      82: ifeq          150
      85: aload         10
      87: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      92: checkcast     #163                // class java/util/Map$Entry
      95: astore        11
      97: aload         11
      99: astore        12
     101: iconst_0
     102: istore        13
     104: aload         12
     106: invokeinterface #166,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     111: checkcast     #168                // class java/math/BigInteger
     114: astore        14
     116: aload         12
     118: invokeinterface #170,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     123: checkcast     #168                // class java/math/BigInteger
     126: astore        15
     128: aload_0
     129: getfield      #34                 // Field memory:Ljava/util/HashMap;
     132: checkcast     #154                // class java/util/Map
     135: aload         14
     137: aload         15
     139: invokeinterface #174,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     144: pop
     145: nop
     146: nop
     147: goto          75
     150: nop
     151: nop
     152: nop
     153: goto          17
     156: nop
     157: return

  public final java.math.BigInteger sumOfUsedMemoryAddresses();
    Code:
       0: aload_0
       1: getfield      #34                 // Field memory:Ljava/util/HashMap;
       4: checkcast     #154                // class java/util/Map
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #193                // class java/util/LinkedHashMap
      15: dup
      16: invokespecial #194                // Method java/util/LinkedHashMap."<init>":()V
      19: checkcast     #154                // class java/util/Map
      22: astore        4
      24: iconst_0
      25: istore        5
      27: aload_3
      28: invokeinterface #158,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      33: invokeinterface #161,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      38: astore        6
      40: aload         6
      42: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          118
      50: aload         6
      52: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: checkcast     #163                // class java/util/Map$Entry
      60: astore        7
      62: aload         7
      64: astore        8
      66: iconst_0
      67: istore        9
      69: aload         8
      71: invokeinterface #170,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      76: getstatic     #197                // Field java/math/BigInteger.ZERO:Ljava/math/BigInteger;
      79: invokestatic  #201                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      82: ifne          89
      85: iconst_1
      86: goto          90
      89: iconst_0
      90: ifeq          40
      93: aload         4
      95: aload         7
      97: invokeinterface #166,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     102: aload         7
     104: invokeinterface #170,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     109: invokeinterface #174,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     114: pop
     115: goto          40
     118: aload         4
     120: nop
     121: invokeinterface #205,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     126: checkcast     #58                 // class java/lang/Iterable
     129: astore_1
     130: lconst_0
     131: invokestatic  #209                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     134: dup
     135: ldc           #211                // String valueOf(...)
     137: invokestatic  #214                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     140: astore_2
     141: aload_1
     142: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     147: astore_3
     148: aload_3
     149: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     154: ifeq          193
     157: aload_3
     158: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     163: aload_2
     164: swap
     165: checkcast     #168                // class java/math/BigInteger
     168: astore        5
     170: astore        10
     172: iconst_0
     173: istore        6
     175: aload         5
     177: aload         10
     179: swap
     180: invokevirtual #217                // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     183: dup
     184: ldc           #219                // String add(...)
     186: invokestatic  #214                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     189: astore_2
     190: goto          148
     193: aload_2
     194: areturn
}

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

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

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #16                 // String args
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #2                  // class Puzzle14
       8: ldc           #24                 // String puzzle14.txt
      10: invokevirtual #30                 // Method java/lang/Class.getResource:(Ljava/lang/String;)Ljava/net/URL;
      13: dup
      14: ldc           #32                 // String getResource(...)
      16: invokestatic  #35                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      19: astore_2
      20: getstatic     #41                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      23: astore_3
      24: aload_2
      25: invokestatic  #47                 // Method kotlin/io/TextStreamsKt.readBytes:(Ljava/net/URL;)[B
      28: astore        4
      30: new           #49                 // class java/lang/String
      33: dup
      34: aload         4
      36: aload_3
      37: invokespecial #52                 // Method java/lang/String."<init>":([BLjava/nio/charset/Charset;)V
      40: astore_1
      41: new           #54                 // class Puzzle14$Program
      44: dup
      45: aload_1
      46: invokespecial #57                 // Method Puzzle14$Program."<init>":(Ljava/lang/String;)V
      49: astore_2
      50: aload_2
      51: invokevirtual #60                 // Method Puzzle14$Program.run:()V
      54: aload_2
      55: invokevirtual #64                 // Method Puzzle14$Program.sumOfUsedMemoryAddresses:()Ljava/math/BigInteger;
      58: getstatic     #70                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: swap
      62: invokevirtual #76                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      65: new           #54                 // class Puzzle14$Program
      68: dup
      69: aload_1
      70: invokespecial #57                 // Method Puzzle14$Program."<init>":(Ljava/lang/String;)V
      73: astore_3
      74: aload_3
      75: invokevirtual #79                 // Method Puzzle14$Program.runV2:()V
      78: aload_3
      79: invokevirtual #64                 // Method Puzzle14$Program.sumOfUsedMemoryAddresses:()Ljava/math/BigInteger;
      82: getstatic     #70                 // Field java/lang/System.out:Ljava/io/PrintStream;
      85: swap
      86: invokevirtual #76                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      89: return

  static {};
    Code:
       0: new           #2                  // class Puzzle14
       3: dup
       4: invokespecial #87                 // Method "<init>":()V
       7: putstatic     #90                 // Field INSTANCE:LPuzzle14;
      10: return
}