package net.sinceat.aoc2020.day16

import kotlin.properties.Delegates

fun main() {
    run {
        val parseResult = parseInput("testinput.txt")
        println(parseResult.calculateScanningErrorRate())
    }
    run {
        val parseResult = parseInput("input.txt")
        println(parseResult.calculateScanningErrorRate())
    }
    run {
        val parseResult = parseInput("testinput2.txt").filterCompletelyInvalid()
        val assignedFields = parseResult.assignFields()
        println(assignedFields)
    }
    run {
        val parseResult = parseInput("input.txt").filterCompletelyInvalid()
        val assignedFields = parseResult.assignFields()
        println(assignedFields)
        val departureFields = assignedFields.filterKeys { it.startsWith("departure") }
        println(departureFields.values.map { index -> parseResult.myTicket[index].toLong() }.reduce { acc, i -> acc * i })
    }
}

fun ParseResult.filterCompletelyInvalid(): ParseResult {
    return ParseResult(
        rules,
        myTicket,
        nearbyTickets.filter { ticket ->
            ticket.all { value -> rules.values.any { rule -> value in rule } }
        }
    )
}

fun ParseResult.assignFields(): Map<String, Int> {
    val ticketColumns = myTicket.indices.map { index ->
        nearbyTickets.map { ticket -> ticket[index] }
    }
    val candidates = ticketColumns.map { columnValues ->
        rules.filter { (_, rule) ->
            columnValues.all { it in rule }
        }.map { it.key }
    }
    val alreadyUsed = mutableSetOf<String>()
    return candidates.withIndex().sortedBy { it.value.size }.associate { (index, values) ->
        val remaining = values.filterNot { it in alreadyUsed }.single()
        alreadyUsed.add(remaining)
        Pair(remaining, index)
    }
}

fun ParseResult.calculateScanningErrorRate(): Int {
    return nearbyTickets.map { ticket ->
        ticket.filterNot { value -> rules.values.any { rule -> value in rule } }.sum()
    }.sum()
}

data class Rule(val range1: IntRange, val range2: IntRange) {
    operator fun contains(value: Int) = value in range1 || value in range2
}

data class ParseResult(val rules: Map<String, Rule>, val myTicket: List<Int>, val nearbyTickets: List<List<Int>>)

private enum class FileSection {
    RULES,
    MY_TICKET,
    OTHER_TICKETS
}

fun parseInput(fileName: String): ParseResult {
    return ClassLoader.getSystemResourceAsStream(fileName)!!.bufferedReader().useLines { lines ->
        var section = FileSection.RULES
        val rules = mutableMapOf<String, Rule>()
        var myTicket by Delegates.notNull<List<Int>>()
        val nearbyTickets = mutableListOf<List<Int>>()
        lines.filter(String::isNotBlank).forEach { line ->
            when (line) {
                "your ticket:" -> section = FileSection.MY_TICKET
                "nearby tickets:" -> section = FileSection.OTHER_TICKETS
                else -> if (section == FileSection.RULES) {
                    val (fieldName, ruleRangesString) = line.split(":").map(String::trim)
                    val rule = ruleRangesString.split(" or ")
                        .map { ruleRangeString ->
                            ruleRangeString.split("-")
                                .map(String::toInt)
                                .let { (start, endInclusive) -> start..endInclusive }
                        }.let { (range1, range2) -> Rule(range1, range2) }
                    rules[fieldName] = rule
                } else {
                    val ticket = line.split(",").map(String::toInt)
                    if (section == FileSection.MY_TICKET) {
                        myTicket = ticket
                    } else {
                        nearbyTickets.add(ticket)
                    }
                }
            }
        }
        ParseResult(rules, myTicket, nearbyTickets)
    }
}

Compiled from "App.kt"
public final class net.sinceat.aoc2020.day16.AppKt {
  static final kotlin.reflect.KProperty<java.lang.Object>[] $$delegatedProperties;

  public static final void main();
    Code:
       0: iconst_0
       1: istore_0
       2: ldc           #8                  // String testinput.txt
       4: invokestatic  #12                 // Method parseInput:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day16/ParseResult;
       7: astore_1
       8: aload_1
       9: invokestatic  #16                 // Method calculateScanningErrorRate:(Lnet/sinceat/aoc2020/day16/ParseResult;)I
      12: istore_2
      13: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      16: iload_2
      17: invokevirtual #28                 // Method java/io/PrintStream.println:(I)V
      20: nop
      21: nop
      22: iconst_0
      23: istore_0
      24: ldc           #30                 // String input.txt
      26: invokestatic  #12                 // Method parseInput:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day16/ParseResult;
      29: astore_1
      30: aload_1
      31: invokestatic  #16                 // Method calculateScanningErrorRate:(Lnet/sinceat/aoc2020/day16/ParseResult;)I
      34: istore_2
      35: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      38: iload_2
      39: invokevirtual #28                 // Method java/io/PrintStream.println:(I)V
      42: nop
      43: nop
      44: iconst_0
      45: istore_0
      46: ldc           #32                 // String testinput2.txt
      48: invokestatic  #12                 // Method parseInput:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day16/ParseResult;
      51: invokestatic  #36                 // Method filterCompletelyInvalid:(Lnet/sinceat/aoc2020/day16/ParseResult;)Lnet/sinceat/aoc2020/day16/ParseResult;
      54: astore_1
      55: aload_1
      56: invokestatic  #40                 // Method assignFields:(Lnet/sinceat/aoc2020/day16/ParseResult;)Ljava/util/Map;
      59: astore_2
      60: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      63: aload_2
      64: invokevirtual #43                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      67: nop
      68: nop
      69: iconst_0
      70: istore_0
      71: ldc           #30                 // String input.txt
      73: invokestatic  #12                 // Method parseInput:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day16/ParseResult;
      76: invokestatic  #36                 // Method filterCompletelyInvalid:(Lnet/sinceat/aoc2020/day16/ParseResult;)Lnet/sinceat/aoc2020/day16/ParseResult;
      79: astore_1
      80: aload_1
      81: invokestatic  #40                 // Method assignFields:(Lnet/sinceat/aoc2020/day16/ParseResult;)Ljava/util/Map;
      84: astore_2
      85: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      88: aload_2
      89: invokevirtual #43                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      92: aload_2
      93: astore_3
      94: iconst_0
      95: istore        4
      97: new           #45                 // class java/util/LinkedHashMap
     100: dup
     101: invokespecial #48                 // Method java/util/LinkedHashMap."<init>":()V
     104: astore        5
     106: aload_3
     107: invokeinterface #54,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     112: invokeinterface #60,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     117: astore        6
     119: aload         6
     121: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     126: ifeq          192
     129: aload         6
     131: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     136: checkcast     #72                 // class java/util/Map$Entry
     139: astore        7
     141: aload         7
     143: invokeinterface #75,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     148: checkcast     #77                 // class java/lang/String
     151: astore        8
     153: iconst_0
     154: istore        9
     156: aload         8
     158: ldc           #79                 // String departure
     160: iconst_0
     161: iconst_2
     162: aconst_null
     163: invokestatic  #85                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     166: ifeq          119
     169: aload         5
     171: aload         7
     173: invokeinterface #75,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     178: aload         7
     180: invokeinterface #88,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     185: invokevirtual #92                 // Method java/util/LinkedHashMap.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     188: pop
     189: goto          119
     192: aload         5
     194: checkcast     #50                 // class java/util/Map
     197: astore        10
     199: aload         10
     201: invokeinterface #96,  1           // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     206: checkcast     #98                 // class java/lang/Iterable
     209: astore_3
     210: iconst_0
     211: istore        4
     213: aload_3
     214: astore        5
     216: new           #100                // class java/util/ArrayList
     219: dup
     220: aload_3
     221: bipush        10
     223: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     226: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     229: checkcast     #110                // class java/util/Collection
     232: astore        6
     234: iconst_0
     235: istore        7
     237: aload         5
     239: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     244: astore        8
     246: aload         8
     248: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     253: ifeq          315
     256: aload         8
     258: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     263: astore        9
     265: aload         6
     267: aload         9
     269: checkcast     #113                // class java/lang/Number
     272: invokevirtual #117                // Method java/lang/Number.intValue:()I
     275: istore        11
     277: astore        12
     279: iconst_0
     280: istore        13
     282: aload_1
     283: invokevirtual #123                // Method net/sinceat/aoc2020/day16/ParseResult.getMyTicket:()Ljava/util/List;
     286: iload         11
     288: invokeinterface #129,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     293: checkcast     #113                // class java/lang/Number
     296: invokevirtual #117                // Method java/lang/Number.intValue:()I
     299: i2l
     300: invokestatic  #135                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     303: aload         12
     305: swap
     306: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     311: pop
     312: goto          246
     315: aload         6
     317: checkcast     #125                // class java/util/List
     320: nop
     321: checkcast     #98                 // class java/lang/Iterable
     324: astore_3
     325: nop
     326: iconst_0
     327: istore        4
     329: aload_3
     330: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     335: astore        5
     337: aload         5
     339: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     344: ifne          357
     347: new           #141                // class java/lang/UnsupportedOperationException
     350: dup
     351: ldc           #143                // String Empty collection can\'t be reduced.
     353: invokespecial #146                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     356: athrow
     357: aload         5
     359: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     364: astore        6
     366: aload         5
     368: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     373: ifeq          417
     376: aload         6
     378: aload         5
     380: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     385: checkcast     #113                // class java/lang/Number
     388: invokevirtual #150                // Method java/lang/Number.longValue:()J
     391: lstore        14
     393: checkcast     #113                // class java/lang/Number
     396: invokevirtual #150                // Method java/lang/Number.longValue:()J
     399: lstore        16
     401: iconst_0
     402: istore        13
     404: lload         16
     406: lload         14
     408: lmul
     409: invokestatic  #135                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     412: astore        6
     414: goto          366
     417: aload         6
     419: checkcast     #113                // class java/lang/Number
     422: invokevirtual #150                // Method java/lang/Number.longValue:()J
     425: lstore        18
     427: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
     430: lload         18
     432: invokevirtual #153                // Method java/io/PrintStream.println:(J)V
     435: nop
     436: nop
     437: return

  public static final net.sinceat.aoc2020.day16.ParseResult filterCompletelyInvalid(net.sinceat.aoc2020.day16.ParseResult);
    Code:
       0: aload_0
       1: ldc           #195                // String <this>
       3: invokestatic  #201                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #205                // Method net/sinceat/aoc2020/day16/ParseResult.getRules:()Ljava/util/Map;
      10: aload_0
      11: invokevirtual #123                // Method net/sinceat/aoc2020/day16/ParseResult.getMyTicket:()Ljava/util/List;
      14: aload_0
      15: invokevirtual #208                // Method net/sinceat/aoc2020/day16/ParseResult.getNearbyTickets:()Ljava/util/List;
      18: checkcast     #98                 // class java/lang/Iterable
      21: astore_1
      22: astore        23
      24: astore        22
      26: iconst_0
      27: istore_2
      28: aload_1
      29: astore_3
      30: new           #100                // class java/util/ArrayList
      33: dup
      34: invokespecial #209                // Method java/util/ArrayList."<init>":()V
      37: checkcast     #110                // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          279
      63: aload         6
      65: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        7
      72: aload         7
      74: checkcast     #125                // class java/util/List
      77: astore        8
      79: iconst_0
      80: istore        9
      82: aload         8
      84: checkcast     #98                 // class java/lang/Iterable
      87: astore        10
      89: iconst_0
      90: istore        11
      92: aload         10
      94: instanceof    #110                // class java/util/Collection
      97: ifeq          117
     100: aload         10
     102: checkcast     #110                // class java/util/Collection
     105: invokeinterface #212,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     110: ifeq          117
     113: iconst_1
     114: goto          262
     117: aload         10
     119: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     124: astore        12
     126: aload         12
     128: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     133: ifeq          261
     136: aload         12
     138: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     143: astore        13
     145: aload         13
     147: checkcast     #113                // class java/lang/Number
     150: invokevirtual #117                // Method java/lang/Number.intValue:()I
     153: istore        14
     155: iconst_0
     156: istore        15
     158: aload_0
     159: invokevirtual #205                // Method net/sinceat/aoc2020/day16/ParseResult.getRules:()Ljava/util/Map;
     162: invokeinterface #96,  1           // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     167: checkcast     #98                 // class java/lang/Iterable
     170: astore        16
     172: iconst_0
     173: istore        17
     175: aload         16
     177: instanceof    #110                // class java/util/Collection
     180: ifeq          200
     183: aload         16
     185: checkcast     #110                // class java/util/Collection
     188: invokeinterface #212,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     193: ifeq          200
     196: iconst_0
     197: goto          253
     200: aload         16
     202: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     207: astore        18
     209: aload         18
     211: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     216: ifeq          252
     219: aload         18
     221: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     226: astore        19
     228: aload         19
     230: checkcast     #214                // class net/sinceat/aoc2020/day16/Rule
     233: astore        20
     235: iconst_0
     236: istore        21
     238: aload         20
     240: iload         14
     242: invokevirtual #218                // Method net/sinceat/aoc2020/day16/Rule.contains:(I)Z
     245: ifeq          209
     248: iconst_1
     249: goto          253
     252: iconst_0
     253: nop
     254: ifne          126
     257: iconst_0
     258: goto          262
     261: iconst_1
     262: nop
     263: ifeq          53
     266: aload         4
     268: aload         7
     270: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     275: pop
     276: goto          53
     279: aload         4
     281: checkcast     #125                // class java/util/List
     284: nop
     285: astore        24
     287: aload         22
     289: aload         23
     291: aload         24
     293: astore        25
     295: astore        26
     297: astore        27
     299: new           #119                // class net/sinceat/aoc2020/day16/ParseResult
     302: dup
     303: aload         27
     305: aload         26
     307: aload         25
     309: invokespecial #221                // Method net/sinceat/aoc2020/day16/ParseResult."<init>":(Ljava/util/Map;Ljava/util/List;Ljava/util/List;)V
     312: areturn

  public static final java.util.Map<java.lang.String, java.lang.Integer> assignFields(net.sinceat.aoc2020.day16.ParseResult);
    Code:
       0: aload_0
       1: ldc           #195                // String <this>
       3: invokestatic  #201                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #123                // Method net/sinceat/aoc2020/day16/ParseResult.getMyTicket:()Ljava/util/List;
      10: checkcast     #110                // class java/util/Collection
      13: invokestatic  #245                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
      16: checkcast     #98                 // class java/lang/Iterable
      19: astore_2
      20: iconst_0
      21: istore_3
      22: aload_2
      23: astore        4
      25: new           #100                // class java/util/ArrayList
      28: dup
      29: aload_2
      30: bipush        10
      32: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      35: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
      38: checkcast     #110                // class java/util/Collection
      41: astore        5
      43: iconst_0
      44: istore        6
      46: aload         4
      48: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        7
      55: aload         7
      57: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          215
      65: aload         7
      67: checkcast     #247                // class kotlin/collections/IntIterator
      70: invokevirtual #250                // Method kotlin/collections/IntIterator.nextInt:()I
      73: istore        8
      75: aload         5
      77: iload         8
      79: istore        9
      81: astore        29
      83: iconst_0
      84: istore        10
      86: aload_0
      87: invokevirtual #208                // Method net/sinceat/aoc2020/day16/ParseResult.getNearbyTickets:()Ljava/util/List;
      90: checkcast     #98                 // class java/lang/Iterable
      93: astore        11
      95: iconst_0
      96: istore        12
      98: aload         11
     100: astore        13
     102: new           #100                // class java/util/ArrayList
     105: dup
     106: aload         11
     108: bipush        10
     110: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     113: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     116: checkcast     #110                // class java/util/Collection
     119: astore        14
     121: iconst_0
     122: istore        15
     124: aload         13
     126: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     131: astore        16
     133: aload         16
     135: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     140: ifeq          196
     143: aload         16
     145: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     150: astore        17
     152: aload         14
     154: aload         17
     156: checkcast     #125                // class java/util/List
     159: astore        18
     161: astore        19
     163: iconst_0
     164: istore        20
     166: aload         18
     168: iload         9
     170: invokeinterface #129,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     175: checkcast     #113                // class java/lang/Number
     178: invokevirtual #117                // Method java/lang/Number.intValue:()I
     181: invokestatic  #255                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     184: aload         19
     186: swap
     187: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     192: pop
     193: goto          133
     196: aload         14
     198: checkcast     #125                // class java/util/List
     201: nop
     202: nop
     203: aload         29
     205: swap
     206: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     211: pop
     212: goto          55
     215: aload         5
     217: checkcast     #125                // class java/util/List
     220: nop
     221: astore_1
     222: aload_1
     223: checkcast     #98                 // class java/lang/Iterable
     226: astore_3
     227: iconst_0
     228: istore        4
     230: aload_3
     231: astore        5
     233: new           #100                // class java/util/ArrayList
     236: dup
     237: aload_3
     238: bipush        10
     240: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     243: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     246: checkcast     #110                // class java/util/Collection
     249: astore        6
     251: iconst_0
     252: istore        7
     254: aload         5
     256: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     261: astore        8
     263: aload         8
     265: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     270: ifeq          622
     273: aload         8
     275: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     280: astore        9
     282: aload         6
     284: aload         9
     286: checkcast     #125                // class java/util/List
     289: astore        10
     291: astore        29
     293: iconst_0
     294: istore        11
     296: aload_0
     297: invokevirtual #205                // Method net/sinceat/aoc2020/day16/ParseResult.getRules:()Ljava/util/Map;
     300: astore        12
     302: iconst_0
     303: istore        13
     305: aload         12
     307: astore        14
     309: new           #45                 // class java/util/LinkedHashMap
     312: dup
     313: invokespecial #48                 // Method java/util/LinkedHashMap."<init>":()V
     316: checkcast     #50                 // class java/util/Map
     319: astore        15
     321: iconst_0
     322: istore        16
     324: aload         14
     326: invokeinterface #54,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     331: invokeinterface #60,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     336: astore        17
     338: aload         17
     340: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     345: ifeq          499
     348: aload         17
     350: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     355: checkcast     #72                 // class java/util/Map$Entry
     358: astore        18
     360: aload         18
     362: astore        19
     364: iconst_0
     365: istore        20
     367: aload         19
     369: invokeinterface #88,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     374: checkcast     #214                // class net/sinceat/aoc2020/day16/Rule
     377: astore        21
     379: aload         10
     381: checkcast     #98                 // class java/lang/Iterable
     384: astore        22
     386: iconst_0
     387: istore        23
     389: aload         22
     391: instanceof    #110                // class java/util/Collection
     394: ifeq          414
     397: aload         22
     399: checkcast     #110                // class java/util/Collection
     402: invokeinterface #212,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     407: ifeq          414
     410: iconst_1
     411: goto          470
     414: aload         22
     416: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     421: astore        24
     423: aload         24
     425: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     430: ifeq          469
     433: aload         24
     435: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     440: astore        25
     442: aload         25
     444: checkcast     #113                // class java/lang/Number
     447: invokevirtual #117                // Method java/lang/Number.intValue:()I
     450: istore        26
     452: iconst_0
     453: istore        27
     455: aload         21
     457: iload         26
     459: invokevirtual #218                // Method net/sinceat/aoc2020/day16/Rule.contains:(I)Z
     462: ifne          423
     465: iconst_0
     466: goto          470
     469: iconst_1
     470: nop
     471: ifeq          338
     474: aload         15
     476: aload         18
     478: invokeinterface #75,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     483: aload         18
     485: invokeinterface #88,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     490: invokeinterface #256,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     495: pop
     496: goto          338
     499: aload         15
     501: nop
     502: astore        12
     504: nop
     505: iconst_0
     506: istore        13
     508: aload         12
     510: astore        14
     512: new           #100                // class java/util/ArrayList
     515: dup
     516: aload         12
     518: invokeinterface #259,  1          // InterfaceMethod java/util/Map.size:()I
     523: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     526: checkcast     #110                // class java/util/Collection
     529: astore        15
     531: iconst_0
     532: istore        16
     534: aload         14
     536: invokeinterface #54,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     541: invokeinterface #60,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     546: astore        17
     548: aload         17
     550: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     555: ifeq          603
     558: aload         17
     560: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     565: checkcast     #72                 // class java/util/Map$Entry
     568: astore        18
     570: aload         15
     572: aload         18
     574: astore        19
     576: astore        28
     578: iconst_0
     579: istore        20
     581: aload         19
     583: invokeinterface #75,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     588: checkcast     #77                 // class java/lang/String
     591: aload         28
     593: swap
     594: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     599: pop
     600: goto          548
     603: aload         15
     605: checkcast     #125                // class java/util/List
     608: nop
     609: nop
     610: aload         29
     612: swap
     613: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     618: pop
     619: goto          263
     622: aload         6
     624: checkcast     #125                // class java/util/List
     627: nop
     628: astore_2
     629: new           #261                // class java/util/LinkedHashSet
     632: dup
     633: invokespecial #262                // Method java/util/LinkedHashSet."<init>":()V
     636: checkcast     #56                 // class java/util/Set
     639: astore_3
     640: aload_2
     641: checkcast     #98                 // class java/lang/Iterable
     644: invokestatic  #266                // Method kotlin/collections/CollectionsKt.withIndex:(Ljava/lang/Iterable;)Ljava/lang/Iterable;
     647: astore        4
     649: iconst_0
     650: istore        5
     652: aload         4
     654: new           #268                // class net/sinceat/aoc2020/day16/AppKt$assignFields$$inlined$sortedBy$1
     657: dup
     658: invokespecial #269                // Method net/sinceat/aoc2020/day16/AppKt$assignFields$$inlined$sortedBy$1."<init>":()V
     661: checkcast     #271                // class java/util/Comparator
     664: invokestatic  #275                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     667: checkcast     #98                 // class java/lang/Iterable
     670: astore        4
     672: nop
     673: iconst_0
     674: istore        5
     676: aload         4
     678: bipush        10
     680: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     683: invokestatic  #281                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     686: bipush        16
     688: invokestatic  #287                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     691: istore        6
     693: aload         4
     695: astore        7
     697: new           #45                 // class java/util/LinkedHashMap
     700: dup
     701: iload         6
     703: invokespecial #288                // Method java/util/LinkedHashMap."<init>":(I)V
     706: checkcast     #50                 // class java/util/Map
     709: astore        8
     711: iconst_0
     712: istore        9
     714: aload         7
     716: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     721: astore        10
     723: aload         10
     725: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     730: ifeq          924
     733: aload         10
     735: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     740: astore        11
     742: aload         8
     744: astore        12
     746: aload         11
     748: checkcast     #290                // class kotlin/collections/IndexedValue
     751: astore        13
     753: iconst_0
     754: istore        14
     756: aload         13
     758: invokevirtual #293                // Method kotlin/collections/IndexedValue.component1:()I
     761: istore        15
     763: aload         13
     765: invokevirtual #296                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     768: checkcast     #125                // class java/util/List
     771: astore        16
     773: aload         16
     775: checkcast     #98                 // class java/lang/Iterable
     778: astore        17
     780: iconst_0
     781: istore        18
     783: aload         17
     785: astore        19
     787: new           #100                // class java/util/ArrayList
     790: dup
     791: invokespecial #209                // Method java/util/ArrayList."<init>":()V
     794: checkcast     #110                // class java/util/Collection
     797: astore        20
     799: iconst_0
     800: istore        21
     802: aload         19
     804: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     809: astore        22
     811: aload         22
     813: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     818: ifeq          864
     821: aload         22
     823: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     828: astore        23
     830: aload         23
     832: checkcast     #77                 // class java/lang/String
     835: astore        24
     837: iconst_0
     838: istore        25
     840: aload_3
     841: aload         24
     843: invokeinterface #298,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     848: ifne          811
     851: aload         20
     853: aload         23
     855: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     860: pop
     861: goto          811
     864: aload         20
     866: checkcast     #125                // class java/util/List
     869: nop
     870: invokestatic  #302                // Method kotlin/collections/CollectionsKt.single:(Ljava/util/List;)Ljava/lang/Object;
     873: checkcast     #77                 // class java/lang/String
     876: astore        26
     878: aload_3
     879: aload         26
     881: invokeinterface #303,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     886: pop
     887: new           #305                // class kotlin/Pair
     890: dup
     891: aload         26
     893: iload         15
     895: invokestatic  #255                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     898: invokespecial #308                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     901: astore        13
     903: aload         12
     905: aload         13
     907: invokevirtual #311                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     910: aload         13
     912: invokevirtual #314                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     915: invokeinterface #256,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     920: pop
     921: goto          723
     924: aload         8
     926: nop
     927: areturn

  public static final int calculateScanningErrorRate(net.sinceat.aoc2020.day16.ParseResult);
    Code:
       0: aload_0
       1: ldc           #195                // String <this>
       3: invokestatic  #201                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #208                // Method net/sinceat/aoc2020/day16/ParseResult.getNearbyTickets:()Ljava/util/List;
      10: checkcast     #98                 // class java/lang/Iterable
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_1
      17: astore_3
      18: new           #100                // class java/util/ArrayList
      21: dup
      22: aload_1
      23: bipush        10
      25: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      28: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
      31: checkcast     #110                // class java/util/Collection
      34: astore        4
      36: iconst_0
      37: istore        5
      39: aload_3
      40: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        6
      47: aload         6
      49: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          289
      57: aload         6
      59: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        7
      66: aload         4
      68: aload         7
      70: checkcast     #125                // class java/util/List
      73: astore        8
      75: astore        25
      77: iconst_0
      78: istore        9
      80: aload         8
      82: checkcast     #98                 // class java/lang/Iterable
      85: astore        10
      87: iconst_0
      88: istore        11
      90: aload         10
      92: astore        12
      94: new           #100                // class java/util/ArrayList
      97: dup
      98: invokespecial #209                // Method java/util/ArrayList."<init>":()V
     101: checkcast     #110                // class java/util/Collection
     104: astore        13
     106: iconst_0
     107: istore        14
     109: aload         12
     111: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        15
     118: aload         15
     120: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          262
     128: aload         15
     130: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: astore        16
     137: aload         16
     139: checkcast     #113                // class java/lang/Number
     142: invokevirtual #117                // Method java/lang/Number.intValue:()I
     145: istore        17
     147: iconst_0
     148: istore        18
     150: aload_0
     151: invokevirtual #205                // Method net/sinceat/aoc2020/day16/ParseResult.getRules:()Ljava/util/Map;
     154: invokeinterface #96,  1           // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     159: checkcast     #98                 // class java/lang/Iterable
     162: astore        19
     164: iconst_0
     165: istore        20
     167: aload         19
     169: instanceof    #110                // class java/util/Collection
     172: ifeq          192
     175: aload         19
     177: checkcast     #110                // class java/util/Collection
     180: invokeinterface #212,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     185: ifeq          192
     188: iconst_0
     189: goto          245
     192: aload         19
     194: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     199: astore        21
     201: aload         21
     203: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     208: ifeq          244
     211: aload         21
     213: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     218: astore        22
     220: aload         22
     222: checkcast     #214                // class net/sinceat/aoc2020/day16/Rule
     225: astore        23
     227: iconst_0
     228: istore        24
     230: aload         23
     232: iload         17
     234: invokevirtual #218                // Method net/sinceat/aoc2020/day16/Rule.contains:(I)Z
     237: ifeq          201
     240: iconst_1
     241: goto          245
     244: iconst_0
     245: nop
     246: ifne          118
     249: aload         13
     251: aload         16
     253: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     258: pop
     259: goto          118
     262: aload         13
     264: checkcast     #125                // class java/util/List
     267: nop
     268: checkcast     #98                 // class java/lang/Iterable
     271: invokestatic  #344                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     274: invokestatic  #255                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     277: aload         25
     279: swap
     280: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     285: pop
     286: goto          47
     289: aload         4
     291: checkcast     #125                // class java/util/List
     294: nop
     295: checkcast     #98                 // class java/lang/Iterable
     298: invokestatic  #344                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     301: ireturn

  public static final net.sinceat.aoc2020.day16.ParseResult parseInput(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #352                // String fileName
       4: invokestatic  #201                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokestatic  #358                // Method java/lang/ClassLoader.getSystemResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
      11: dup
      12: invokestatic  #361                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      15: astore_1
      16: getstatic     #367                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      19: astore_2
      20: new           #369                // class java/io/InputStreamReader
      23: dup
      24: aload_1
      25: aload_2
      26: invokespecial #372                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      29: checkcast     #374                // class java/io/Reader
      32: astore_3
      33: sipush        8192
      36: istore        4
      38: aload_3
      39: instanceof    #376                // class java/io/BufferedReader
      42: ifeq          52
      45: aload_3
      46: checkcast     #376                // class java/io/BufferedReader
      49: goto          62
      52: new           #376                // class java/io/BufferedReader
      55: dup
      56: aload_3
      57: iload         4
      59: invokespecial #379                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      62: checkcast     #374                // class java/io/Reader
      65: astore_1
      66: nop
      67: iconst_0
      68: istore_2
      69: aload_1
      70: astore_3
      71: sipush        8192
      74: istore        4
      76: aload_3
      77: instanceof    #376                // class java/io/BufferedReader
      80: ifeq          90
      83: aload_3
      84: checkcast     #376                // class java/io/BufferedReader
      87: goto          100
      90: new           #376                // class java/io/BufferedReader
      93: dup
      94: aload_3
      95: iload         4
      97: invokespecial #379                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
     100: checkcast     #381                // class java/io/Closeable
     103: astore_3
     104: aconst_null
     105: astore        4
     107: nop
     108: aload_3
     109: checkcast     #376                // class java/io/BufferedReader
     112: astore        5
     114: iconst_0
     115: istore        6
     117: aload         5
     119: invokestatic  #387                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     122: astore        7
     124: iconst_0
     125: istore        8
     127: aconst_null
     128: astore        9
     130: getstatic     #393                // Field net/sinceat/aoc2020/day16/FileSection.RULES:Lnet/sinceat/aoc2020/day16/FileSection;
     133: astore        9
     135: new           #45                 // class java/util/LinkedHashMap
     138: dup
     139: invokespecial #48                 // Method java/util/LinkedHashMap."<init>":()V
     142: checkcast     #50                 // class java/util/Map
     145: astore        10
     147: getstatic     #399                // Field kotlin/properties/Delegates.INSTANCE:Lkotlin/properties/Delegates;
     150: invokevirtual #403                // Method kotlin/properties/Delegates.notNull:()Lkotlin/properties/ReadWriteProperty;
     153: astore        11
     155: new           #100                // class java/util/ArrayList
     158: dup
     159: invokespecial #209                // Method java/util/ArrayList."<init>":()V
     162: checkcast     #125                // class java/util/List
     165: astore        12
     167: aload         7
     169: getstatic     #408                // Field net/sinceat/aoc2020/day16/AppKt$parseInput$1$1.INSTANCE:Lnet/sinceat/aoc2020/day16/AppKt$parseInput$1$1;
     172: checkcast     #410                // class kotlin/jvm/functions/Function1
     175: invokestatic  #416                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     178: astore        13
     180: iconst_0
     181: istore        14
     183: aload         13
     185: invokeinterface #419,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     190: astore        15
     192: aload         15
     194: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     199: ifeq          964
     202: aload         15
     204: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     209: astore        16
     211: aload         16
     213: checkcast     #77                 // class java/lang/String
     216: astore        17
     218: iconst_0
     219: istore        18
     221: aload         17
     223: astore        19
     225: aload         19
     227: ldc_w         #421                // String your ticket:
     230: invokestatic  #425                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     233: ifeq          244
     236: getstatic     #428                // Field net/sinceat/aoc2020/day16/FileSection.MY_TICKET:Lnet/sinceat/aoc2020/day16/FileSection;
     239: astore        9
     241: goto          959
     244: aload         19
     246: ldc_w         #430                // String nearby tickets:
     249: invokestatic  #425                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     252: ifeq          263
     255: getstatic     #433                // Field net/sinceat/aoc2020/day16/FileSection.OTHER_TICKETS:Lnet/sinceat/aoc2020/day16/FileSection;
     258: astore        9
     260: goto          959
     263: aload         9
     265: getstatic     #393                // Field net/sinceat/aoc2020/day16/FileSection.RULES:Lnet/sinceat/aoc2020/day16/FileSection;
     268: if_acmpne     798
     271: aload         17
     273: checkcast     #435                // class java/lang/CharSequence
     276: iconst_1
     277: anewarray     #77                 // class java/lang/String
     280: astore        20
     282: aload         20
     284: iconst_0
     285: ldc_w         #437                // String :
     288: aastore
     289: aload         20
     291: iconst_0
     292: iconst_0
     293: bipush        6
     295: aconst_null
     296: invokestatic  #441                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     299: checkcast     #98                 // class java/lang/Iterable
     302: astore        20
     304: iconst_0
     305: istore        21
     307: aload         20
     309: astore        22
     311: new           #100                // class java/util/ArrayList
     314: dup
     315: aload         20
     317: bipush        10
     319: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     322: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     325: checkcast     #110                // class java/util/Collection
     328: astore        23
     330: iconst_0
     331: istore        24
     333: aload         22
     335: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     340: astore        25
     342: aload         25
     344: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     349: ifeq          399
     352: aload         25
     354: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     359: astore        26
     361: aload         23
     363: aload         26
     365: checkcast     #77                 // class java/lang/String
     368: astore        27
     370: astore        28
     372: iconst_0
     373: istore        29
     375: aload         27
     377: checkcast     #435                // class java/lang/CharSequence
     380: invokestatic  #445                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     383: invokevirtual #449                // Method java/lang/Object.toString:()Ljava/lang/String;
     386: nop
     387: aload         28
     389: swap
     390: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     395: pop
     396: goto          342
     399: aload         23
     401: checkcast     #125                // class java/util/List
     404: nop
     405: astore        30
     407: aload         30
     409: iconst_0
     410: invokeinterface #129,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     415: checkcast     #77                 // class java/lang/String
     418: astore        20
     420: aload         30
     422: iconst_1
     423: invokeinterface #129,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     428: checkcast     #77                 // class java/lang/String
     431: astore        21
     433: aload         21
     435: checkcast     #435                // class java/lang/CharSequence
     438: iconst_1
     439: anewarray     #77                 // class java/lang/String
     442: astore        23
     444: aload         23
     446: iconst_0
     447: ldc_w         #451                // String  or
     450: aastore
     451: aload         23
     453: iconst_0
     454: iconst_0
     455: bipush        6
     457: aconst_null
     458: invokestatic  #441                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     461: checkcast     #98                 // class java/lang/Iterable
     464: astore        23
     466: nop
     467: iconst_0
     468: istore        24
     470: aload         23
     472: astore        25
     474: new           #100                // class java/util/ArrayList
     477: dup
     478: aload         23
     480: bipush        10
     482: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     485: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     488: checkcast     #110                // class java/util/Collection
     491: astore        26
     493: iconst_0
     494: istore        27
     496: aload         25
     498: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     503: astore        29
     505: aload         29
     507: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     512: ifeq          732
     515: aload         29
     517: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     522: astore        31
     524: aload         26
     526: aload         31
     528: checkcast     #77                 // class java/lang/String
     531: astore        32
     533: astore        28
     535: iconst_0
     536: istore        33
     538: aload         32
     540: checkcast     #435                // class java/lang/CharSequence
     543: iconst_1
     544: anewarray     #77                 // class java/lang/String
     547: astore        34
     549: aload         34
     551: iconst_0
     552: ldc_w         #453                // String -
     555: aastore
     556: aload         34
     558: iconst_0
     559: iconst_0
     560: bipush        6
     562: aconst_null
     563: invokestatic  #441                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     566: checkcast     #98                 // class java/lang/Iterable
     569: astore        34
     571: nop
     572: iconst_0
     573: istore        35
     575: aload         34
     577: astore        36
     579: new           #100                // class java/util/ArrayList
     582: dup
     583: aload         34
     585: bipush        10
     587: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     590: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     593: checkcast     #110                // class java/util/Collection
     596: astore        37
     598: iconst_0
     599: istore        38
     601: aload         36
     603: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     608: astore        39
     610: aload         39
     612: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     617: ifeq          664
     620: aload         39
     622: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     627: astore        40
     629: aload         37
     631: aload         40
     633: checkcast     #77                 // class java/lang/String
     636: astore        41
     638: astore        42
     640: iconst_0
     641: istore        43
     643: aload         41
     645: invokestatic  #457                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     648: nop
     649: invokestatic  #255                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     652: aload         42
     654: swap
     655: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     660: pop
     661: goto          610
     664: aload         37
     666: checkcast     #125                // class java/util/List
     669: nop
     670: astore        35
     672: iconst_0
     673: istore        36
     675: aload         35
     677: iconst_0
     678: invokeinterface #129,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     683: checkcast     #113                // class java/lang/Number
     686: invokevirtual #117                // Method java/lang/Number.intValue:()I
     689: istore        37
     691: aload         35
     693: iconst_1
     694: invokeinterface #129,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     699: checkcast     #113                // class java/lang/Number
     702: invokevirtual #117                // Method java/lang/Number.intValue:()I
     705: istore        38
     707: new           #459                // class kotlin/ranges/IntRange
     710: dup
     711: iload         37
     713: iload         38
     715: invokespecial #462                // Method kotlin/ranges/IntRange."<init>":(II)V
     718: nop
     719: nop
     720: aload         28
     722: swap
     723: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     728: pop
     729: goto          505
     732: aload         26
     734: checkcast     #125                // class java/util/List
     737: nop
     738: astore        24
     740: iconst_0
     741: istore        25
     743: aload         24
     745: iconst_0
     746: invokeinterface #129,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     751: checkcast     #459                // class kotlin/ranges/IntRange
     754: astore        26
     756: aload         24
     758: iconst_1
     759: invokeinterface #129,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     764: checkcast     #459                // class kotlin/ranges/IntRange
     767: astore        27
     769: new           #214                // class net/sinceat/aoc2020/day16/Rule
     772: dup
     773: aload         26
     775: aload         27
     777: invokespecial #465                // Method net/sinceat/aoc2020/day16/Rule."<init>":(Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)V
     780: nop
     781: astore        22
     783: aload         10
     785: aload         20
     787: aload         22
     789: invokeinterface #256,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     794: pop
     795: goto          959
     798: aload         17
     800: checkcast     #435                // class java/lang/CharSequence
     803: iconst_1
     804: anewarray     #77                 // class java/lang/String
     807: astore        20
     809: aload         20
     811: iconst_0
     812: ldc_w         #467                // String ,
     815: aastore
     816: aload         20
     818: iconst_0
     819: iconst_0
     820: bipush        6
     822: aconst_null
     823: invokestatic  #441                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     826: checkcast     #98                 // class java/lang/Iterable
     829: astore        20
     831: iconst_0
     832: istore        21
     834: aload         20
     836: astore        22
     838: new           #100                // class java/util/ArrayList
     841: dup
     842: aload         20
     844: bipush        10
     846: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     849: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     852: checkcast     #110                // class java/util/Collection
     855: astore        23
     857: iconst_0
     858: istore        24
     860: aload         22
     862: invokeinterface #111,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     867: astore        25
     869: aload         25
     871: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     876: ifeq          923
     879: aload         25
     881: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     886: astore        26
     888: aload         23
     890: aload         26
     892: checkcast     #77                 // class java/lang/String
     895: astore        27
     897: astore        28
     899: iconst_0
     900: istore        29
     902: aload         27
     904: invokestatic  #457                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     907: nop
     908: invokestatic  #255                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     911: aload         28
     913: swap
     914: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     919: pop
     920: goto          869
     923: aload         23
     925: checkcast     #125                // class java/util/List
     928: nop
     929: astore        30
     931: aload         9
     933: getstatic     #428                // Field net/sinceat/aoc2020/day16/FileSection.MY_TICKET:Lnet/sinceat/aoc2020/day16/FileSection;
     936: if_acmpne     949
     939: aload         11
     941: aload         30
     943: invokestatic  #471                // Method parseInput$lambda$30$lambda$23:(Lkotlin/properties/ReadWriteProperty;Ljava/util/List;)V
     946: goto          959
     949: aload         12
     951: aload         30
     953: invokeinterface #472,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     958: pop
     959: nop
     960: nop
     961: goto          192
     964: nop
     965: new           #119                // class net/sinceat/aoc2020/day16/ParseResult
     968: dup
     969: aload         10
     971: aload         11
     973: invokestatic  #476                // Method parseInput$lambda$30$lambda$22:(Lkotlin/properties/ReadWriteProperty;)Ljava/util/List;
     976: aload         12
     978: invokespecial #221                // Method net/sinceat/aoc2020/day16/ParseResult."<init>":(Ljava/util/Map;Ljava/util/List;Ljava/util/List;)V
     981: astore        5
     983: aload_3
     984: aload         4
     986: invokestatic  #482                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     989: aload         5
     991: goto          1014
     994: astore        6
     996: aload         6
     998: astore        4
    1000: aload         6
    1002: athrow
    1003: astore        6
    1005: aload_3
    1006: aload         4
    1008: invokestatic  #482                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
    1011: aload         6
    1013: athrow
    1014: nop
    1015: areturn
    Exception table:
       from    to  target type
         107   983   994   Class java/lang/Throwable
         107   983  1003   any
         994  1003  1003   any
        1003  1005  1003   any

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

  private static final java.util.List<java.lang.Integer> parseInput$lambda$30$lambda$22(kotlin.properties.ReadWriteProperty<java.lang.Object, java.util.List<java.lang.Integer>>);
    Code:
       0: aload_0
       1: aconst_null
       2: getstatic     #531                // Field $$delegatedProperties:[Lkotlin/reflect/KProperty;
       5: iconst_0
       6: aaload
       7: invokeinterface #534,  3          // InterfaceMethod kotlin/properties/ReadWriteProperty.getValue:(Ljava/lang/Object;Lkotlin/reflect/KProperty;)Ljava/lang/Object;
      12: checkcast     #125                // class java/util/List
      15: areturn

  private static final void parseInput$lambda$30$lambda$23(kotlin.properties.ReadWriteProperty<java.lang.Object, java.util.List<java.lang.Integer>>, java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: aconst_null
       2: getstatic     #531                // Field $$delegatedProperties:[Lkotlin/reflect/KProperty;
       5: iconst_0
       6: aaload
       7: aload_1
       8: invokeinterface #540,  4          // InterfaceMethod kotlin/properties/ReadWriteProperty.setValue:(Ljava/lang/Object;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V
      13: return

  static {};
    Code:
       0: iconst_1
       1: anewarray     #544                // class kotlin/reflect/KProperty
       4: astore_0
       5: aload_0
       6: iconst_0
       7: new           #546                // class kotlin/jvm/internal/MutablePropertyReference0Impl
      10: dup
      11: ldc           #2                  // class net/sinceat/aoc2020/day16/AppKt
      13: ldc_w         #548                // String myTicket
      16: ldc_w         #550                // String <v#0>
      19: iconst_1
      20: invokespecial #553                // Method kotlin/jvm/internal/MutablePropertyReference0Impl."<init>":(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      23: checkcast     #555                // class kotlin/jvm/internal/MutablePropertyReference0
      26: invokestatic  #561                // Method kotlin/jvm/internal/Reflection.mutableProperty0:(Lkotlin/jvm/internal/MutablePropertyReference0;)Lkotlin/reflect/KMutableProperty0;
      29: aastore
      30: aload_0
      31: putstatic     #531                // Field $$delegatedProperties:[Lkotlin/reflect/KProperty;
      34: return
}

Compiled from "App.kt"
final class net.sinceat.aoc2020.day16.AppKt$parseInput$1$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> {
  public static final net.sinceat.aoc2020.day16.AppKt$parseInput$1$1 INSTANCE;

  net.sinceat.aoc2020.day16.AppKt$parseInput$1$1();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class kotlin/text/StringsKt
       4: ldc           #13                 // String isNotBlank
       6: ldc           #15                 // String isNotBlank(Ljava/lang/CharSequence;)Z
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Boolean invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #32                 // class java/lang/CharSequence
      10: invokestatic  #36                 // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
      13: ifne          20
      16: iconst_1
      17: goto          21
      20: iconst_0
      21: invokestatic  #42                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      24: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #46                 // class java/lang/String
       5: invokevirtual #48                 // Method invoke:(Ljava/lang/String;)Ljava/lang/Boolean;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class net/sinceat/aoc2020/day16/AppKt$parseInput$1$1
       3: dup
       4: invokespecial #53                 // Method "<init>":()V
       7: putstatic     #56                 // Field INSTANCE:Lnet/sinceat/aoc2020/day16/AppKt$parseInput$1$1;
      10: return
}

Compiled from "Comparisons.kt"
public final class net.sinceat.aoc2020.day16.AppKt$assignFields$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public net.sinceat.aoc2020.day16.AppKt$assignFields$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class kotlin/collections/IndexedValue
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/collections/IndexedValue.getValue:()Ljava/lang/Object;
      12: checkcast     #29                 // class java/util/List
      15: invokeinterface #33,  1           // InterfaceMethod java/util/List.size:()I
      20: invokestatic  #39                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: checkcast     #41                 // class java/lang/Comparable
      26: aload_2
      27: checkcast     #23                 // class kotlin/collections/IndexedValue
      30: astore_3
      31: astore        5
      33: iconst_0
      34: istore        4
      36: aload_3
      37: invokevirtual #27                 // Method kotlin/collections/IndexedValue.getValue:()Ljava/lang/Object;
      40: checkcast     #29                 // class java/util/List
      43: invokeinterface #33,  1           // InterfaceMethod java/util/List.size:()I
      48: invokestatic  #39                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      51: aload         5
      53: swap
      54: checkcast     #41                 // class java/lang/Comparable
      57: invokestatic  #47                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      60: ireturn
}


package net.sinceat.aoc2020.day11

import kotlin.math.abs
import kotlin.math.sign
import net.sinceat.aoc2020.day11.Part1EvolutionRules.evolveUntilStable

fun main() {
    with (Part1EvolutionRules) {
        run {
            val fullyEvolvedGrid = readGrid("testinput.txt").evolveUntilStable().last()
            Grid.compare(
                readGrid("testoutput.txt"),
                fullyEvolvedGrid
            )
            println(fullyEvolvedGrid.occupiedSeats)
        }
        run {
            val fullyEvolvedGrid = readGrid("input.txt").evolveUntilStable().last()
            println(fullyEvolvedGrid.occupiedSeats)
        }
    }
    with (Part2EvolutionRules) {
        run {
            val fullyEvolvedGrid = readGrid("testinput.txt").evolveUntilStable().last()
            Grid.compare(
                readGrid("testoutputp2.txt"),
                fullyEvolvedGrid
            )
            println(fullyEvolvedGrid.occupiedSeats)
        }
        run {
            val fullyEvolvedGrid = readGrid("input.txt").evolveUntilStable().last()
            println(fullyEvolvedGrid.occupiedSeats)
        }
    }
}

private fun readGrid(fileName: String): Grid {
    return ClassLoader.getSystemResourceAsStream(fileName)!!.bufferedReader().useLines { lines ->
        Grid(lines.filter(String::isNotBlank).map(String::toList).toList())
    }
}

private class Grid(val data: List<List<Char>>) {

    companion object {
        fun compare(grid1: Grid, grid2: Grid) {
            if (grid1.width != grid2.width || grid1.data.size != grid2.data.size) {
                println("grid dimensions not equal")
                return
            }
            for ((a, b) in grid1.data.zip(grid2.data)) {
                val aString = a.joinToString("")
                val bString = b.joinToString("")
                println("$aString  $bString  ${if (aString == bString) "OK" else "ERROR"}")
            }
        }
    }

    val width = data[0].size

    val occupiedSeats by lazy {
        data.sumBy { row -> row.count { it == '#' } }
    }

    override fun toString(): String {
        return data.joinToString("\n") { it.joinToString("") }
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is Grid) return false

        if (width != other.width) return false
        if (data != other.data) return false

        return true
    }

    override fun hashCode(): Int {
        var result = data.hashCode()
        result = 31 * result + width
        return result
    }
}

private data class Point(val row: Int, val column: Int) {
    operator fun plus(v: Vector) = Point(row + v.rowDir, column + v.colDir)
}

private data class Vector(val rowDir: Int, val colDir: Int) {
    fun extend(): Vector {
        return Vector(
            rowDir.sign * (abs(rowDir) + 1),
            colDir.sign * (abs(colDir) + 1)
        )
    }
}

private abstract class GridEvolutionRules {

    protected abstract val acceptableNeighbors: Int

    protected abstract fun Grid.hasVisibleNeighbor(start: Point, vector: Vector): Boolean

    private fun Grid.countNeighbors(rowNr: Int, columnNr: Int): Int {
        val vectors = listOf(
            Vector(-1, -1),
            Vector(-1, 0),
            Vector(-1, 1),
            Vector(0, -1),
            Vector(0, 1),
            Vector(1, -1),
            Vector(1, 0),
            Vector(1, 1),
        )
        val p = Point(rowNr, columnNr)
        return vectors.count { vector -> hasVisibleNeighbor(p, vector) }
    }

    fun Grid.evolve(): Grid {
        return Grid(
            List(data.size) { rowNr ->
                List(width) { columnNr ->
                    val status = data[rowNr][columnNr]
                    if (status == '.') {
                        '.'
                    } else {
                        val neighbors = countNeighbors(rowNr, columnNr)
                        when {
                            neighbors == 0 -> '#'
                            neighbors > acceptableNeighbors -> 'L'
                            else -> status
                        }
                    }
                }
            }
        )
    }

    fun Grid.evolveUntilStable(): Sequence<Grid> = sequence {
        var current = this@evolveUntilStable
        while (true) {
            val next = current.evolve()
            if (current == next) {
                break
            }
            current = next
            yield(current)
        }
    }
}

private object Part1EvolutionRules : GridEvolutionRules() {

    override val acceptableNeighbors: Int = 3

    override fun Grid.hasVisibleNeighbor(start: Point, vector: Vector): Boolean {
        val p = start + vector
        if (p.row !in data.indices || p.column !in 0 until width) {
            return false
        }
        return when (data[p.row][p.column]) {
            '#' -> true
            else -> false
        }
    }
}

private object Part2EvolutionRules : GridEvolutionRules() {

    override val acceptableNeighbors: Int = 4

    override tailrec fun Grid.hasVisibleNeighbor(start: Point, vector: Vector): Boolean {
        val p = start + vector
        if (p.row !in data.indices || p.column !in 0 until width) {
            return false
        }
        return when (data[p.row][p.column]) {
            '#' -> true
            'L' -> false
            else -> hasVisibleNeighbor(start, vector.extend())
        }
    }
}

Compiled from "App.kt"
public final class net.sinceat.aoc2020.day11.AppKt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field net/sinceat/aoc2020/day11/Part1EvolutionRules.INSTANCE:Lnet/sinceat/aoc2020/day11/Part1EvolutionRules;
       3: astore_0
       4: iconst_0
       5: istore_1
       6: aload_0
       7: astore_2
       8: iconst_0
       9: istore_3
      10: aload_2
      11: ldc           #14                 // String testinput.txt
      13: invokestatic  #18                 // Method readGrid:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day11/Grid;
      16: invokevirtual #22                 // Method net/sinceat/aoc2020/day11/Part1EvolutionRules.evolveUntilStable:(Lnet/sinceat/aoc2020/day11/Grid;)Lkotlin/sequences/Sequence;
      19: invokestatic  #28                 // Method kotlin/sequences/SequencesKt.last:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
      22: checkcast     #30                 // class net/sinceat/aoc2020/day11/Grid
      25: astore        4
      27: getstatic     #34                 // Field net/sinceat/aoc2020/day11/Grid.Companion:Lnet/sinceat/aoc2020/day11/Grid$Companion;
      30: ldc           #36                 // String testoutput.txt
      32: invokestatic  #18                 // Method readGrid:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day11/Grid;
      35: aload         4
      37: invokevirtual #42                 // Method net/sinceat/aoc2020/day11/Grid$Companion.compare:(Lnet/sinceat/aoc2020/day11/Grid;Lnet/sinceat/aoc2020/day11/Grid;)V
      40: aload         4
      42: invokevirtual #46                 // Method net/sinceat/aoc2020/day11/Grid.getOccupiedSeats:()I
      45: istore        5
      47: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      50: iload         5
      52: invokevirtual #58                 // Method java/io/PrintStream.println:(I)V
      55: nop
      56: nop
      57: aload_0
      58: astore_2
      59: iconst_0
      60: istore_3
      61: aload_2
      62: ldc           #60                 // String input.txt
      64: invokestatic  #18                 // Method readGrid:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day11/Grid;
      67: invokevirtual #22                 // Method net/sinceat/aoc2020/day11/Part1EvolutionRules.evolveUntilStable:(Lnet/sinceat/aoc2020/day11/Grid;)Lkotlin/sequences/Sequence;
      70: invokestatic  #28                 // Method kotlin/sequences/SequencesKt.last:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
      73: checkcast     #30                 // class net/sinceat/aoc2020/day11/Grid
      76: astore        4
      78: aload         4
      80: invokevirtual #46                 // Method net/sinceat/aoc2020/day11/Grid.getOccupiedSeats:()I
      83: istore        5
      85: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      88: iload         5
      90: invokevirtual #58                 // Method java/io/PrintStream.println:(I)V
      93: nop
      94: nop
      95: nop
      96: nop
      97: getstatic     #65                 // Field net/sinceat/aoc2020/day11/Part2EvolutionRules.INSTANCE:Lnet/sinceat/aoc2020/day11/Part2EvolutionRules;
     100: astore_0
     101: iconst_0
     102: istore_1
     103: aload_0
     104: astore_2
     105: iconst_0
     106: istore_3
     107: aload_2
     108: ldc           #14                 // String testinput.txt
     110: invokestatic  #18                 // Method readGrid:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day11/Grid;
     113: invokevirtual #66                 // Method net/sinceat/aoc2020/day11/Part2EvolutionRules.evolveUntilStable:(Lnet/sinceat/aoc2020/day11/Grid;)Lkotlin/sequences/Sequence;
     116: invokestatic  #28                 // Method kotlin/sequences/SequencesKt.last:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
     119: checkcast     #30                 // class net/sinceat/aoc2020/day11/Grid
     122: astore        4
     124: getstatic     #34                 // Field net/sinceat/aoc2020/day11/Grid.Companion:Lnet/sinceat/aoc2020/day11/Grid$Companion;
     127: ldc           #68                 // String testoutputp2.txt
     129: invokestatic  #18                 // Method readGrid:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day11/Grid;
     132: aload         4
     134: invokevirtual #42                 // Method net/sinceat/aoc2020/day11/Grid$Companion.compare:(Lnet/sinceat/aoc2020/day11/Grid;Lnet/sinceat/aoc2020/day11/Grid;)V
     137: aload         4
     139: invokevirtual #46                 // Method net/sinceat/aoc2020/day11/Grid.getOccupiedSeats:()I
     142: istore        5
     144: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
     147: iload         5
     149: invokevirtual #58                 // Method java/io/PrintStream.println:(I)V
     152: nop
     153: nop
     154: aload_0
     155: astore_2
     156: iconst_0
     157: istore_3
     158: aload_2
     159: ldc           #60                 // String input.txt
     161: invokestatic  #18                 // Method readGrid:(Ljava/lang/String;)Lnet/sinceat/aoc2020/day11/Grid;
     164: invokevirtual #66                 // Method net/sinceat/aoc2020/day11/Part2EvolutionRules.evolveUntilStable:(Lnet/sinceat/aoc2020/day11/Grid;)Lkotlin/sequences/Sequence;
     167: invokestatic  #28                 // Method kotlin/sequences/SequencesKt.last:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
     170: checkcast     #30                 // class net/sinceat/aoc2020/day11/Grid
     173: astore        4
     175: aload         4
     177: invokevirtual #46                 // Method net/sinceat/aoc2020/day11/Grid.getOccupiedSeats:()I
     180: istore        5
     182: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
     185: iload         5
     187: invokevirtual #58                 // Method java/io/PrintStream.println:(I)V
     190: nop
     191: nop
     192: nop
     193: nop
     194: return

  private static final net.sinceat.aoc2020.day11.Grid readGrid(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #91                 // Method java/lang/ClassLoader.getSystemResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
       4: dup
       5: invokestatic  #97                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       8: astore_1
       9: getstatic     #103                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      12: astore_2
      13: new           #105                // class java/io/InputStreamReader
      16: dup
      17: aload_1
      18: aload_2
      19: invokespecial #109                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      22: checkcast     #111                // class java/io/Reader
      25: astore_3
      26: sipush        8192
      29: istore        4
      31: aload_3
      32: instanceof    #113                // class java/io/BufferedReader
      35: ifeq          45
      38: aload_3
      39: checkcast     #113                // class java/io/BufferedReader
      42: goto          55
      45: new           #113                // class java/io/BufferedReader
      48: dup
      49: aload_3
      50: iload         4
      52: invokespecial #116                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      55: checkcast     #111                // class java/io/Reader
      58: astore_1
      59: nop
      60: iconst_0
      61: istore_2
      62: aload_1
      63: astore_3
      64: sipush        8192
      67: istore        4
      69: aload_3
      70: instanceof    #113                // class java/io/BufferedReader
      73: ifeq          83
      76: aload_3
      77: checkcast     #113                // class java/io/BufferedReader
      80: goto          93
      83: new           #113                // class java/io/BufferedReader
      86: dup
      87: aload_3
      88: iload         4
      90: invokespecial #116                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      93: checkcast     #118                // class java/io/Closeable
      96: astore_3
      97: aconst_null
      98: astore        4
     100: nop
     101: aload_3
     102: checkcast     #113                // class java/io/BufferedReader
     105: astore        5
     107: iconst_0
     108: istore        6
     110: aload         5
     112: invokestatic  #124                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     115: astore        7
     117: iconst_0
     118: istore        8
     120: new           #30                 // class net/sinceat/aoc2020/day11/Grid
     123: dup
     124: aload         7
     126: getstatic     #129                // Field net/sinceat/aoc2020/day11/AppKt$readGrid$1$1.INSTANCE:Lnet/sinceat/aoc2020/day11/AppKt$readGrid$1$1;
     129: checkcast     #131                // class kotlin/jvm/functions/Function1
     132: invokestatic  #135                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     135: getstatic     #140                // Field net/sinceat/aoc2020/day11/AppKt$readGrid$1$2.INSTANCE:Lnet/sinceat/aoc2020/day11/AppKt$readGrid$1$2;
     138: checkcast     #131                // class kotlin/jvm/functions/Function1
     141: invokestatic  #143                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     144: invokestatic  #147                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     147: invokespecial #150                // Method net/sinceat/aoc2020/day11/Grid."<init>":(Ljava/util/List;)V
     150: astore        5
     152: aload_3
     153: aload         4
     155: invokestatic  #156                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     158: aload         5
     160: goto          183
     163: astore        6
     165: aload         6
     167: astore        4
     169: aload         6
     171: athrow
     172: astore        6
     174: aload_3
     175: aload         4
     177: invokestatic  #156                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     180: aload         6
     182: athrow
     183: nop
     184: areturn
    Exception table:
       from    to  target type
         100   152   163   Class java/lang/Throwable
         100   152   172   any
         163   172   172   any
         172   174   172   any

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

Compiled from "App.kt"
final class net.sinceat.aoc2020.day11.AppKt$readGrid$1$2 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, java.util.List<? extends java.lang.Character>> {
  public static final net.sinceat.aoc2020.day11.AppKt$readGrid$1$2 INSTANCE;

  net.sinceat.aoc2020.day11.AppKt$readGrid$1$2();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class kotlin/text/StringsKt
       4: ldc           #13                 // String toList
       6: ldc           #15                 // String toList(Ljava/lang/CharSequence;)Ljava/util/List;
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.util.List<java.lang.Character> invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #25                 // String p0
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #33                 // class java/lang/CharSequence
      10: invokestatic  #36                 // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #40                 // class java/lang/String
       5: invokevirtual #42                 // Method invoke:(Ljava/lang/String;)Ljava/util/List;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class net/sinceat/aoc2020/day11/AppKt$readGrid$1$2
       3: dup
       4: invokespecial #47                 // Method "<init>":()V
       7: putstatic     #50                 // Field INSTANCE:Lnet/sinceat/aoc2020/day11/AppKt$readGrid$1$2;
      10: return
}

Compiled from "App.kt"
final class net.sinceat.aoc2020.day11.AppKt$readGrid$1$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> {
  public static final net.sinceat.aoc2020.day11.AppKt$readGrid$1$1 INSTANCE;

  net.sinceat.aoc2020.day11.AppKt$readGrid$1$1();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class kotlin/text/StringsKt
       4: ldc           #13                 // String isNotBlank
       6: ldc           #15                 // String isNotBlank(Ljava/lang/CharSequence;)Z
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Boolean invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #32                 // class java/lang/CharSequence
      10: invokestatic  #36                 // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
      13: ifne          20
      16: iconst_1
      17: goto          21
      20: iconst_0
      21: invokestatic  #42                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      24: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #46                 // class java/lang/String
       5: invokevirtual #48                 // Method invoke:(Ljava/lang/String;)Ljava/lang/Boolean;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class net/sinceat/aoc2020/day11/AppKt$readGrid$1$1
       3: dup
       4: invokespecial #53                 // Method "<init>":()V
       7: putstatic     #56                 // Field INSTANCE:Lnet/sinceat/aoc2020/day11/AppKt$readGrid$1$1;
      10: return
}