object Puzzle19 {

    @JvmStatic
    fun main(args: Array<String>) {
        val input = Puzzle19::class.java.getResource("puzzle19.txt").readText()
        val calculatedMatchingStringCount = countMatchingStrings(input,Puzzle19::useSameRules)
        println(calculatedMatchingStringCount)
        val calculatedMatchingStringCountWithModifiedRules = countMatchingStrings(input,Puzzle19::useModifiedRules)
        println(calculatedMatchingStringCountWithModifiedRules)
    }

    fun countMatchingStrings(input: String, modify: (Int, String) -> String): Int {
        val rulesAndStrings = input.split("\n\n")
        val rules = Rules(rulesAndStrings.first().split("\n"), modify)
        val strings = rulesAndStrings.last().split("\n")
        return strings.count { string -> rules.accept(string) }
    }

    fun useSameRules(index: Int, rules: String) = rules
    fun useModifiedRules(index: Int, rules: String) =
        when (index) {
            8 -> "42 | 42 8"
            11 -> "42 31 | 42 11 31"
            else -> rules
        }

    class Rules(ruleStrings: List<String>, modify: (Int, String) -> String) {
        private val regexp: Regex?
        private val ruleCharMap: MutableMap<Int, String>

        init {
            val ruleMap = mutableMapOf<Int, List<List<Int>>>()
            ruleCharMap = mutableMapOf()
            ruleStrings.forEach{ ruleString -> //1: 2 3 | 3 2
                val indexAndRules = ruleString.split(": ")
                val index = indexAndRules.first().toInt() //1
                val originalRules = indexAndRules.last() //2 3 | 3 2
                val rules = modify(index, originalRules)
                if (rules.startsWith("\"")){
                  ruleCharMap[index] = rules[1].toString()
                }else {
                    val rulesArray = mutableListOf<List<Int>>()
                    rules.split(" | ").forEach { r ->
                        rulesArray.add(r.split(" ").map { it.toInt() })
                    }
                    ruleMap[index] = rulesArray
                }
            }
            var couldResolveAnyRules = true
            while (!ruleCharMap.containsKey(0) && couldResolveAnyRules) {
                val resolvableRules = ruleMap.filter { rule ->
                    !ruleCharMap.containsKey(rule.key) && rule.value.all { r ->
                        r.all { r2 ->
                            ruleCharMap.containsKey(r2)
                        }
                    }
                }
                resolvableRules.forEach { resolvableRule ->
                    val key = resolvableRule.key
                    val value = resolvableRule.value
                    val resolvedValue = value.joinToString("|") { l ->
                        "(" + l.map { ruleNumber -> ruleCharMap[ruleNumber] }.joinToString("") + ")"
                    }
                    ruleCharMap[key] = "($resolvedValue)"
                }
                couldResolveAnyRules = resolvableRules.isNotEmpty()
            }
            if (ruleCharMap.containsKey(0)) {
                regexp = ("^" + ruleCharMap[0] + "$").toRegex()
            }else{
                regexp = null
            }
        }

        fun accept(string: String): Boolean {
            if (regexp != null)
                return regexp.matches(string)
            else{
                //0 = 8 11
                //8 = (42)+
                //11 = (42)(31) | 42 42 31 31
                //0 = 42{k+}31{k}
                val regexp42 = ruleCharMap[42]
                val regexp31 = ruleCharMap[31]
                var remainingString = string
                val regexp4231 = "^$regexp42(.+)$regexp31$".toRegex()
                var matchResult = regexp4231.find(remainingString)
                val regexp42CapturingGroupCount = regexp42!!.count { it == '(' } + 1
                while (
                    matchResult?.groups?.get(regexp42CapturingGroupCount) != null
                    && remainingString != matchResult.groups[regexp42CapturingGroupCount]!!.value){
                    remainingString = matchResult.groups[regexp42CapturingGroupCount]!!.value
                    matchResult = regexp4231.find(remainingString)
                }
                val regexp42Plus = "^${ruleCharMap[42]}+$".toRegex()
                return regexp42Plus.matches(remainingString) && remainingString != string
            }
        }
    }
}

Compiled from "Puzzle19.kt"
final class Puzzle19$main$calculatedMatchingStringCount$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<java.lang.Integer, java.lang.String, java.lang.String> {
  Puzzle19$main$calculatedMatchingStringCount$1(java.lang.Object);
    Code:
       0: aload_0
       1: iconst_2
       2: aload_1
       3: ldc           #11                 // class Puzzle19
       5: ldc           #13                 // String useSameRules
       7: ldc           #15                 // String useSameRules(ILjava/lang/String;)Ljava/lang/String;
       9: iconst_0
      10: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.String invoke(int, java.lang.String);
    Code:
       0: aload_2
       1: ldc           #26                 // String p1
       3: invokestatic  #32                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #34                 // Field receiver:Ljava/lang/Object;
      10: checkcast     #11                 // class Puzzle19
      13: iload_1
      14: aload_2
      15: invokevirtual #36                 // Method Puzzle19.useSameRules:(ILjava/lang/String;)Ljava/lang/String;
      18: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #42                 // class java/lang/Number
       5: invokevirtual #46                 // Method java/lang/Number.intValue:()I
       8: aload_2
       9: checkcast     #48                 // class java/lang/String
      12: invokevirtual #50                 // Method invoke:(ILjava/lang/String;)Ljava/lang/String;
      15: areturn
}

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

  private Puzzle19();
    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 Puzzle19
       8: ldc           #24                 // String puzzle19.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: getstatic     #55                 // Field INSTANCE:LPuzzle19;
      44: aload_1
      45: new           #57                 // class Puzzle19$main$calculatedMatchingStringCount$1
      48: dup
      49: getstatic     #55                 // Field INSTANCE:LPuzzle19;
      52: invokespecial #60                 // Method Puzzle19$main$calculatedMatchingStringCount$1."<init>":(Ljava/lang/Object;)V
      55: checkcast     #62                 // class kotlin/jvm/functions/Function2
      58: invokevirtual #66                 // Method countMatchingStrings:(Ljava/lang/String;Lkotlin/jvm/functions/Function2;)I
      61: istore_2
      62: getstatic     #72                 // Field java/lang/System.out:Ljava/io/PrintStream;
      65: iload_2
      66: invokevirtual #78                 // Method java/io/PrintStream.println:(I)V
      69: getstatic     #55                 // Field INSTANCE:LPuzzle19;
      72: aload_1
      73: new           #80                 // class Puzzle19$main$calculatedMatchingStringCountWithModifiedRules$1
      76: dup
      77: getstatic     #55                 // Field INSTANCE:LPuzzle19;
      80: invokespecial #81                 // Method Puzzle19$main$calculatedMatchingStringCountWithModifiedRules$1."<init>":(Ljava/lang/Object;)V
      83: checkcast     #62                 // class kotlin/jvm/functions/Function2
      86: invokevirtual #66                 // Method countMatchingStrings:(Ljava/lang/String;Lkotlin/jvm/functions/Function2;)I
      89: istore_3
      90: getstatic     #72                 // Field java/lang/System.out:Ljava/io/PrintStream;
      93: iload_3
      94: invokevirtual #78                 // Method java/io/PrintStream.println:(I)V
      97: return

  public final int countMatchingStrings(java.lang.String, kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super java.lang.String, java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #89                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #91                 // String modify
       9: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: checkcast     #93                 // class java/lang/CharSequence
      16: iconst_1
      17: anewarray     #49                 // class java/lang/String
      20: astore        4
      22: aload         4
      24: iconst_0
      25: ldc           #95                 // String \n\n
      27: aastore
      28: aload         4
      30: iconst_0
      31: iconst_0
      32: bipush        6
      34: aconst_null
      35: invokestatic  #101                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      38: astore_3
      39: new           #103                // class Puzzle19$Rules
      42: dup
      43: aload_3
      44: invokestatic  #109                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      47: checkcast     #93                 // class java/lang/CharSequence
      50: iconst_1
      51: anewarray     #49                 // class java/lang/String
      54: astore        5
      56: aload         5
      58: iconst_0
      59: ldc           #111                // String \n
      61: aastore
      62: aload         5
      64: iconst_0
      65: iconst_0
      66: bipush        6
      68: aconst_null
      69: invokestatic  #101                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      72: aload_2
      73: invokespecial #114                // Method Puzzle19$Rules."<init>":(Ljava/util/List;Lkotlin/jvm/functions/Function2;)V
      76: astore        4
      78: aload_3
      79: invokestatic  #117                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      82: checkcast     #93                 // class java/lang/CharSequence
      85: iconst_1
      86: anewarray     #49                 // class java/lang/String
      89: astore        6
      91: aload         6
      93: iconst_0
      94: ldc           #111                // String \n
      96: aastore
      97: aload         6
      99: iconst_0
     100: iconst_0
     101: bipush        6
     103: aconst_null
     104: invokestatic  #101                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     107: astore        5
     109: aload         5
     111: checkcast     #119                // class java/lang/Iterable
     114: astore        6
     116: iconst_0
     117: istore        7
     119: aload         6
     121: instanceof    #121                // class java/util/Collection
     124: ifeq          144
     127: aload         6
     129: checkcast     #121                // class java/util/Collection
     132: invokeinterface #125,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     137: ifeq          144
     140: iconst_0
     141: goto          211
     144: iconst_0
     145: istore        8
     147: aload         6
     149: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     154: astore        9
     156: aload         9
     158: invokeinterface #134,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     163: ifeq          209
     166: aload         9
     168: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     173: astore        10
     175: aload         10
     177: checkcast     #49                 // class java/lang/String
     180: astore        11
     182: iconst_0
     183: istore        12
     185: aload         4
     187: aload         11
     189: invokevirtual #142                // Method Puzzle19$Rules.accept:(Ljava/lang/String;)Z
     192: ifeq          156
     195: iinc          8, 1
     198: iload         8
     200: ifge          156
     203: invokestatic  #145                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     206: goto          156
     209: iload         8
     211: ireturn

  public final java.lang.String useSameRules(int, java.lang.String);
    Code:
       0: aload_2
       1: ldc           #164                // String rules
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: areturn

  public final java.lang.String useModifiedRules(int, java.lang.String);
    Code:
       0: aload_2
       1: ldc           #164                // String rules
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_1
       7: tableswitch   { // 8 to 11
                     8: 36
                     9: 46
                    10: 46
                    11: 41
               default: 46
          }
      36: ldc           #168                // String 42 | 42 8
      38: goto          47
      41: ldc           #170                // String 42 31 | 42 11 31
      43: goto          47
      46: aload_2
      47: areturn

  static {};
    Code:
       0: new           #2                  // class Puzzle19
       3: dup
       4: invokespecial #172                // Method "<init>":()V
       7: putstatic     #55                 // Field INSTANCE:LPuzzle19;
      10: return
}

Compiled from "Puzzle19.kt"
final class Puzzle19$main$calculatedMatchingStringCountWithModifiedRules$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<java.lang.Integer, java.lang.String, java.lang.String> {
  Puzzle19$main$calculatedMatchingStringCountWithModifiedRules$1(java.lang.Object);
    Code:
       0: aload_0
       1: iconst_2
       2: aload_1
       3: ldc           #11                 // class Puzzle19
       5: ldc           #13                 // String useModifiedRules
       7: ldc           #15                 // String useModifiedRules(ILjava/lang/String;)Ljava/lang/String;
       9: iconst_0
      10: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.String invoke(int, java.lang.String);
    Code:
       0: aload_2
       1: ldc           #26                 // String p1
       3: invokestatic  #32                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #34                 // Field receiver:Ljava/lang/Object;
      10: checkcast     #11                 // class Puzzle19
      13: iload_1
      14: aload_2
      15: invokevirtual #36                 // Method Puzzle19.useModifiedRules:(ILjava/lang/String;)Ljava/lang/String;
      18: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #42                 // class java/lang/Number
       5: invokevirtual #46                 // Method java/lang/Number.intValue:()I
       8: aload_2
       9: checkcast     #48                 // class java/lang/String
      12: invokevirtual #50                 // Method invoke:(ILjava/lang/String;)Ljava/lang/String;
      15: areturn
}

Compiled from "Puzzle19.kt"
public final class Puzzle19$Rules {
  private final kotlin.text.Regex regexp;

  private final java.util.Map<java.lang.Integer, java.lang.String> ruleCharMap;

  public Puzzle19$Rules(java.util.List<java.lang.String>, kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super java.lang.String, java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #10                 // String ruleStrings
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String modify
       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: nop
      17: new           #23                 // class java/util/LinkedHashMap
      20: dup
      21: invokespecial #24                 // Method java/util/LinkedHashMap."<init>":()V
      24: checkcast     #26                 // class java/util/Map
      27: astore_3
      28: aload_0
      29: new           #23                 // class java/util/LinkedHashMap
      32: dup
      33: invokespecial #24                 // Method java/util/LinkedHashMap."<init>":()V
      36: checkcast     #26                 // class java/util/Map
      39: putfield      #30                 // Field ruleCharMap:Ljava/util/Map;
      42: aload_1
      43: checkcast     #32                 // class java/lang/Iterable
      46: astore        4
      48: iconst_0
      49: istore        5
      51: aload         4
      53: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        6
      60: aload         6
      62: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          460
      70: aload         6
      72: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        7
      79: aload         7
      81: checkcast     #48                 // class java/lang/String
      84: astore        8
      86: iconst_0
      87: istore        9
      89: aload         8
      91: checkcast     #50                 // class java/lang/CharSequence
      94: iconst_1
      95: anewarray     #48                 // class java/lang/String
      98: astore        10
     100: aload         10
     102: iconst_0
     103: ldc           #52                 // String :
     105: aastore
     106: aload         10
     108: iconst_0
     109: iconst_0
     110: bipush        6
     112: aconst_null
     113: invokestatic  #58                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     116: astore        11
     118: aload         11
     120: invokestatic  #64                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     123: checkcast     #48                 // class java/lang/String
     126: invokestatic  #70                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     129: istore        10
     131: aload         11
     133: invokestatic  #73                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     136: checkcast     #48                 // class java/lang/String
     139: astore        12
     141: aload_2
     142: iload         10
     144: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     147: aload         12
     149: invokeinterface #83,  3           // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     154: checkcast     #48                 // class java/lang/String
     157: astore        13
     159: aload         13
     161: ldc           #85                 // String \"
     163: iconst_0
     164: iconst_2
     165: aconst_null
     166: invokestatic  #89                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     169: ifeq          203
     172: iload         10
     174: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     177: astore        14
     179: aload_0
     180: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
     183: aload         14
     185: aload         13
     187: iconst_1
     188: invokevirtual #93                 // Method java/lang/String.charAt:(I)C
     191: invokestatic  #96                 // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     194: invokeinterface #99,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     199: pop
     200: goto          455
     203: new           #101                // class java/util/ArrayList
     206: dup
     207: invokespecial #102                // Method java/util/ArrayList."<init>":()V
     210: checkcast     #104                // class java/util/List
     213: astore        15
     215: aload         13
     217: checkcast     #50                 // class java/lang/CharSequence
     220: iconst_1
     221: anewarray     #48                 // class java/lang/String
     224: astore        14
     226: aload         14
     228: iconst_0
     229: ldc           #106                // String  |
     231: aastore
     232: aload         14
     234: iconst_0
     235: iconst_0
     236: bipush        6
     238: aconst_null
     239: invokestatic  #58                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     242: checkcast     #32                 // class java/lang/Iterable
     245: astore        14
     247: iconst_0
     248: istore        16
     250: aload         14
     252: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     257: astore        17
     259: aload         17
     261: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     266: ifeq          436
     269: aload         17
     271: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     276: astore        18
     278: aload         18
     280: checkcast     #48                 // class java/lang/String
     283: astore        19
     285: iconst_0
     286: istore        20
     288: aload         15
     290: aload         19
     292: checkcast     #50                 // class java/lang/CharSequence
     295: iconst_1
     296: anewarray     #48                 // class java/lang/String
     299: astore        21
     301: aload         21
     303: iconst_0
     304: ldc           #108                // String
     306: aastore
     307: aload         21
     309: iconst_0
     310: iconst_0
     311: bipush        6
     313: aconst_null
     314: invokestatic  #58                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     317: checkcast     #32                 // class java/lang/Iterable
     320: astore        21
     322: astore        22
     324: iconst_0
     325: istore        23
     327: aload         21
     329: astore        24
     331: new           #101                // class java/util/ArrayList
     334: dup
     335: aload         21
     337: bipush        10
     339: invokestatic  #112                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     342: invokespecial #115                // Method java/util/ArrayList."<init>":(I)V
     345: checkcast     #117                // class java/util/Collection
     348: astore        25
     350: iconst_0
     351: istore        26
     353: aload         24
     355: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     360: astore        27
     362: aload         27
     364: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     369: ifeq          416
     372: aload         27
     374: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     379: astore        28
     381: aload         25
     383: aload         28
     385: checkcast     #48                 // class java/lang/String
     388: astore        29
     390: astore        30
     392: iconst_0
     393: istore        31
     395: aload         29
     397: invokestatic  #70                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     400: nop
     401: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     404: aload         30
     406: swap
     407: invokeinterface #121,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     412: pop
     413: goto          362
     416: aload         25
     418: checkcast     #104                // class java/util/List
     421: nop
     422: aload         22
     424: swap
     425: invokeinterface #122,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     430: pop
     431: nop
     432: nop
     433: goto          259
     436: nop
     437: iload         10
     439: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     442: astore        16
     444: aload_3
     445: aload         16
     447: aload         15
     449: invokeinterface #99,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     454: pop
     455: nop
     456: nop
     457: goto          60
     460: nop
     461: iconst_1
     462: istore        4
     464: aload_0
     465: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
     468: iconst_0
     469: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     472: invokeinterface #125,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     477: ifne          974
     480: iload         4
     482: ifeq          974
     485: aload_3
     486: astore        6
     488: iconst_0
     489: istore        7
     491: aload         6
     493: astore        8
     495: new           #23                 // class java/util/LinkedHashMap
     498: dup
     499: invokespecial #24                 // Method java/util/LinkedHashMap."<init>":()V
     502: checkcast     #26                 // class java/util/Map
     505: astore        9
     507: iconst_0
     508: istore        10
     510: aload         8
     512: invokeinterface #129,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     517: invokeinterface #132,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     522: astore        11
     524: aload         11
     526: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     531: ifeq          794
     534: aload         11
     536: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     541: checkcast     #134                // class java/util/Map$Entry
     544: astore        12
     546: aload         12
     548: astore        13
     550: iconst_0
     551: istore        14
     553: aload_0
     554: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
     557: aload         13
     559: invokeinterface #137,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     564: invokeinterface #125,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     569: ifne          764
     572: aload         13
     574: invokeinterface #140,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     579: checkcast     #32                 // class java/lang/Iterable
     582: astore        15
     584: iconst_0
     585: istore        16
     587: aload         15
     589: instanceof    #117                // class java/util/Collection
     592: ifeq          612
     595: aload         15
     597: checkcast     #117                // class java/util/Collection
     600: invokeinterface #143,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     605: ifeq          612
     608: iconst_1
     609: goto          757
     612: aload         15
     614: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     619: astore        17
     621: aload         17
     623: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     628: ifeq          756
     631: aload         17
     633: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     638: astore        18
     640: aload         18
     642: checkcast     #104                // class java/util/List
     645: astore        19
     647: iconst_0
     648: istore        20
     650: aload         19
     652: checkcast     #32                 // class java/lang/Iterable
     655: astore        21
     657: iconst_0
     658: istore        22
     660: aload         21
     662: instanceof    #117                // class java/util/Collection
     665: ifeq          685
     668: aload         21
     670: checkcast     #117                // class java/util/Collection
     673: invokeinterface #143,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     678: ifeq          685
     681: iconst_1
     682: goto          748
     685: aload         21
     687: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     692: astore        23
     694: aload         23
     696: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     701: ifeq          747
     704: aload         23
     706: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     711: astore        24
     713: aload         24
     715: checkcast     #145                // class java/lang/Number
     718: invokevirtual #149                // Method java/lang/Number.intValue:()I
     721: istore        25
     723: iconst_0
     724: istore        26
     726: aload_0
     727: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
     730: iload         25
     732: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     735: invokeinterface #125,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     740: ifne          694
     743: iconst_0
     744: goto          748
     747: iconst_1
     748: nop
     749: ifne          621
     752: iconst_0
     753: goto          757
     756: iconst_1
     757: ifeq          764
     760: iconst_1
     761: goto          765
     764: iconst_0
     765: nop
     766: ifeq          524
     769: aload         9
     771: aload         12
     773: invokeinterface #137,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     778: aload         12
     780: invokeinterface #140,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     785: invokeinterface #99,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     790: pop
     791: goto          524
     794: aload         9
     796: nop
     797: astore        5
     799: aload         5
     801: astore        6
     803: iconst_0
     804: istore        7
     806: aload         6
     808: invokeinterface #129,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     813: invokeinterface #132,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     818: astore        8
     820: aload         8
     822: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     827: ifeq          953
     830: aload         8
     832: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     837: checkcast     #134                // class java/util/Map$Entry
     840: astore        9
     842: aload         9
     844: astore        10
     846: iconst_0
     847: istore        11
     849: aload         10
     851: invokeinterface #137,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     856: checkcast     #145                // class java/lang/Number
     859: invokevirtual #149                // Method java/lang/Number.intValue:()I
     862: istore        12
     864: aload         10
     866: invokeinterface #140,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     871: checkcast     #104                // class java/util/List
     874: astore        13
     876: aload         13
     878: checkcast     #32                 // class java/lang/Iterable
     881: ldc           #151                // String |
     883: checkcast     #50                 // class java/lang/CharSequence
     886: aconst_null
     887: aconst_null
     888: iconst_0
     889: aconst_null
     890: aload_0
     891: invokedynamic #170,  0            // InvokeDynamic #0:invoke:(LPuzzle19$Rules;)Lkotlin/jvm/functions/Function1;
     896: bipush        30
     898: aconst_null
     899: invokestatic  #174                // 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;
     902: astore        14
     904: iload         12
     906: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     909: astore        15
     911: aload_0
     912: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
     915: aload         15
     917: new           #176                // class java/lang/StringBuilder
     920: dup
     921: invokespecial #177                // Method java/lang/StringBuilder."<init>":()V
     924: bipush        40
     926: invokevirtual #181                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     929: aload         14
     931: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     934: bipush        41
     936: invokevirtual #181                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     939: invokevirtual #188                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     942: invokeinterface #99,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     947: pop
     948: nop
     949: nop
     950: goto          820
     953: nop
     954: aload         5
     956: invokeinterface #189,  1          // InterfaceMethod java/util/Map.isEmpty:()Z
     961: ifne          968
     964: iconst_1
     965: goto          969
     968: iconst_0
     969: istore        4
     971: goto          464
     974: aload_0
     975: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
     978: iconst_0
     979: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     982: invokeinterface #125,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     987: ifeq          1043
     990: aload_0
     991: new           #191                // class kotlin/text/Regex
     994: dup
     995: new           #176                // class java/lang/StringBuilder
     998: dup
     999: invokespecial #177                // Method java/lang/StringBuilder."<init>":()V
    1002: bipush        94
    1004: invokevirtual #181                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
    1007: aload_0
    1008: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
    1011: iconst_0
    1012: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
    1015: invokeinterface #194,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
    1020: checkcast     #48                 // class java/lang/String
    1023: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
    1026: bipush        36
    1028: invokevirtual #181                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
    1031: invokevirtual #188                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
    1034: invokespecial #197                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
    1037: putfield      #201                // Field regexp:Lkotlin/text/Regex;
    1040: goto          1048
    1043: aload_0
    1044: aconst_null
    1045: putfield      #201                // Field regexp:Lkotlin/text/Regex;
    1048: nop
    1049: return

  public final boolean accept(java.lang.String);
    Code:
       0: aload_1
       1: ldc_w         #256                // String string
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: getfield      #201                // Field regexp:Lkotlin/text/Regex;
      11: ifnull        26
      14: aload_0
      15: getfield      #201                // Field regexp:Lkotlin/text/Regex;
      18: aload_1
      19: checkcast     #50                 // class java/lang/CharSequence
      22: invokevirtual #260                // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
      25: ireturn
      26: aload_0
      27: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
      30: bipush        42
      32: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: invokeinterface #194,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      40: checkcast     #48                 // class java/lang/String
      43: astore_2
      44: aload_0
      45: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
      48: bipush        31
      50: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      53: invokeinterface #194,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      58: checkcast     #48                 // class java/lang/String
      61: astore_3
      62: aload_1
      63: astore        4
      65: new           #191                // class kotlin/text/Regex
      68: dup
      69: new           #176                // class java/lang/StringBuilder
      72: dup
      73: invokespecial #177                // Method java/lang/StringBuilder."<init>":()V
      76: bipush        94
      78: invokevirtual #181                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      81: aload_2
      82: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      85: ldc_w         #262                // String (.+)
      88: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      91: aload_3
      92: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      95: bipush        36
      97: invokevirtual #181                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     100: invokevirtual #188                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     103: invokespecial #197                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     106: astore        5
     108: aload         5
     110: aload         4
     112: checkcast     #50                 // class java/lang/CharSequence
     115: iconst_0
     116: iconst_2
     117: aconst_null
     118: invokestatic  #266                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     121: astore        6
     123: aload_2
     124: dup
     125: invokestatic  #270                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     128: checkcast     #50                 // class java/lang/CharSequence
     131: astore        8
     133: iconst_0
     134: istore        9
     136: iconst_0
     137: istore        10
     139: iconst_0
     140: istore        11
     142: iload         11
     144: aload         8
     146: invokeinterface #273,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     151: if_icmpge     196
     154: aload         8
     156: iload         11
     158: invokeinterface #274,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     163: istore        12
     165: iload         12
     167: istore        13
     169: iconst_0
     170: istore        14
     172: iload         13
     174: bipush        40
     176: if_icmpne     183
     179: iconst_1
     180: goto          184
     183: iconst_0
     184: ifeq          190
     187: iinc          10, 1
     190: iinc          11, 1
     193: goto          142
     196: iload         10
     198: iconst_1
     199: iadd
     200: istore        7
     202: aload         6
     204: dup
     205: ifnull        227
     208: invokeinterface #280,  1          // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     213: dup
     214: ifnull        227
     217: iload         7
     219: invokeinterface #285,  2          // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     224: goto          229
     227: pop
     228: aconst_null
     229: ifnull        302
     232: aload         4
     234: aload         6
     236: invokeinterface #280,  1          // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     241: iload         7
     243: invokeinterface #285,  2          // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     248: dup
     249: invokestatic  #270                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     252: invokevirtual #289                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     255: invokestatic  #293                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     258: ifne          302
     261: aload         6
     263: invokeinterface #280,  1          // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     268: iload         7
     270: invokeinterface #285,  2          // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     275: dup
     276: invokestatic  #270                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     279: invokevirtual #289                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     282: astore        4
     284: aload         5
     286: aload         4
     288: checkcast     #50                 // class java/lang/CharSequence
     291: iconst_0
     292: iconst_2
     293: aconst_null
     294: invokestatic  #266                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     297: astore        6
     299: goto          202
     302: new           #191                // class kotlin/text/Regex
     305: dup
     306: new           #176                // class java/lang/StringBuilder
     309: dup
     310: invokespecial #177                // Method java/lang/StringBuilder."<init>":()V
     313: bipush        94
     315: invokevirtual #181                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     318: aload_0
     319: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
     322: bipush        42
     324: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     327: invokeinterface #194,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     332: checkcast     #48                 // class java/lang/String
     335: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     338: ldc_w         #295                // String +$
     341: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     344: invokevirtual #188                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     347: invokespecial #197                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     350: astore        8
     352: aload         8
     354: aload         4
     356: checkcast     #50                 // class java/lang/CharSequence
     359: invokevirtual #260                // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
     362: ifeq          378
     365: aload         4
     367: aload_1
     368: invokestatic  #293                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     371: ifne          378
     374: iconst_1
     375: goto          379
     378: iconst_0
     379: ireturn

  private static final java.lang.CharSequence lambda$8$lambda$7(Puzzle19$Rules, java.util.List);
    Code:
       0: aload_1
       1: ldc_w         #311                // String l
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #176                // class java/lang/StringBuilder
      10: dup
      11: invokespecial #177                // Method java/lang/StringBuilder."<init>":()V
      14: bipush        40
      16: invokevirtual #181                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      19: aload_1
      20: checkcast     #32                 // class java/lang/Iterable
      23: astore_2
      24: astore        11
      26: iconst_0
      27: istore_3
      28: aload_2
      29: astore        4
      31: new           #101                // class java/util/ArrayList
      34: dup
      35: aload_2
      36: bipush        10
      38: invokestatic  #112                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      41: invokespecial #115                // Method java/util/ArrayList."<init>":(I)V
      44: checkcast     #117                // class java/util/Collection
      47: astore        5
      49: iconst_0
      50: istore        6
      52: aload         4
      54: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      59: astore        7
      61: aload         7
      63: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      68: ifeq          126
      71: aload         7
      73: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      78: astore        8
      80: aload         5
      82: aload         8
      84: checkcast     #145                // class java/lang/Number
      87: invokevirtual #149                // Method java/lang/Number.intValue:()I
      90: istore        9
      92: astore        12
      94: iconst_0
      95: istore        10
      97: aload_0
      98: getfield      #30                 // Field ruleCharMap:Ljava/util/Map;
     101: iload         9
     103: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: invokeinterface #194,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     111: checkcast     #48                 // class java/lang/String
     114: aload         12
     116: swap
     117: invokeinterface #121,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     122: pop
     123: goto          61
     126: aload         5
     128: checkcast     #104                // class java/util/List
     131: nop
     132: aload         11
     134: swap
     135: checkcast     #32                 // class java/lang/Iterable
     138: ldc_w         #313                // String
     141: checkcast     #50                 // class java/lang/CharSequence
     144: aconst_null
     145: aconst_null
     146: iconst_0
     147: aconst_null
     148: aconst_null
     149: bipush        62
     151: aconst_null
     152: invokestatic  #174                // 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;
     155: invokevirtual #184                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     158: bipush        41
     160: invokevirtual #181                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     163: invokevirtual #188                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     166: checkcast     #50                 // class java/lang/CharSequence
     169: areturn
}