package com.marcdenning.adventofcode.day16

import java.io.File
import java.util.regex.Pattern

fun main(args: Array<String>) {
    val inputLines = File(args[0]).readLines()
    val separatorLineIndex = inputLines.indexOf("")
    val rules = inputLines.subList(0, separatorLineIndex).map { line ->
        parseRule(line)
    }

    println("Ticket scanning error rate: ${getTicketScanningErrorRate(rules, inputLines)}")
}

fun getTicketScanningErrorRate(rules: List<Rule>, inputLines: List<String>): Int {
    val nearbyTicketsLineIndex = inputLines.indexOf("nearby tickets:") + 1

    return inputLines.subList(nearbyTicketsLineIndex, inputLines.size).flatMap { ticket ->
        ticket.split(',').map { value -> value.toInt() }
    }.filter { value ->
        rules.all { rule -> !(rule as Rule).isNumberValid(value) }
    }.sum()
}

fun parseRule(ruleString: String): Rule {
    val matcher = Pattern.compile("([\\w\\s]+):\\s(\\d+)\\-(\\d+)\\sor\\s(\\d+)\\-(\\d+)").matcher(ruleString)

    if (!matcher.matches()) {
        throw Exception()
    }
    return Rule(
        matcher.group(1),
        matcher.group(2).toInt()..matcher.group(3).toInt(),
        matcher.group(4).toInt()..matcher.group(5).toInt()
    )
}

data class Rule(
    val fieldName: String,
    val range1: IntRange,
    val range2: IntRange
) {
    fun isNumberValid(int: Int): Boolean {
        return range1.contains(int) || range2.contains(int)
    }
}

Compiled from "Day16a.kt"
public final class com.marcdenning.adventofcode.day16.Day16aKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class java/io/File
       9: dup
      10: aload_0
      11: iconst_0
      12: aaload
      13: invokespecial #21                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      16: aconst_null
      17: iconst_1
      18: aconst_null
      19: invokestatic  #27                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      22: astore_1
      23: aload_1
      24: ldc           #29                 // String
      26: invokeinterface #35,  2           // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
      31: istore_2
      32: aload_1
      33: iconst_0
      34: iload_2
      35: invokeinterface #39,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      40: checkcast     #41                 // class java/lang/Iterable
      43: astore        4
      45: iconst_0
      46: istore        5
      48: aload         4
      50: astore        6
      52: new           #43                 // class java/util/ArrayList
      55: dup
      56: aload         4
      58: bipush        10
      60: invokestatic  #49                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      63: invokespecial #52                 // Method java/util/ArrayList."<init>":(I)V
      66: checkcast     #54                 // class java/util/Collection
      69: astore        7
      71: iconst_0
      72: istore        8
      74: aload         6
      76: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      81: astore        9
      83: aload         9
      85: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      90: ifeq          133
      93: aload         9
      95: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     100: astore        10
     102: aload         7
     104: aload         10
     106: checkcast     #70                 // class java/lang/String
     109: astore        11
     111: astore        13
     113: iconst_0
     114: istore        12
     116: aload         11
     118: invokestatic  #74                 // Method parseRule:(Ljava/lang/String;)Lcom/marcdenning/adventofcode/day16/Rule;
     121: aload         13
     123: swap
     124: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     129: pop
     130: goto          83
     133: aload         7
     135: checkcast     #31                 // class java/util/List
     138: nop
     139: astore_3
     140: new           #80                 // class java/lang/StringBuilder
     143: dup
     144: invokespecial #83                 // Method java/lang/StringBuilder."<init>":()V
     147: ldc           #85                 // String Ticket scanning error rate:
     149: invokevirtual #89                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     152: aload_3
     153: aload_1
     154: invokestatic  #93                 // Method getTicketScanningErrorRate:(Ljava/util/List;Ljava/util/List;)I
     157: invokevirtual #96                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     160: invokevirtual #100                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     163: getstatic     #106                // Field java/lang/System.out:Ljava/io/PrintStream;
     166: swap
     167: invokevirtual #112                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     170: return

  public static final int getTicketScanningErrorRate(java.util.List<com.marcdenning.adventofcode.day16.Rule>, java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #133                // String rules
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #134                // String inputLines
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: ldc           #136                // String nearby tickets:
      15: invokeinterface #35,  2           // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
      20: iconst_1
      21: iadd
      22: istore_2
      23: aload_1
      24: iload_2
      25: aload_1
      26: invokeinterface #140,  1          // InterfaceMethod java/util/List.size:()I
      31: invokeinterface #39,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      36: checkcast     #41                 // class java/lang/Iterable
      39: astore_3
      40: iconst_0
      41: istore        4
      43: aload_3
      44: astore        5
      46: new           #43                 // class java/util/ArrayList
      49: dup
      50: invokespecial #141                // Method java/util/ArrayList."<init>":()V
      53: checkcast     #54                 // class java/util/Collection
      56: astore        6
      58: iconst_0
      59: istore        7
      61: aload         5
      63: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      68: astore        8
      70: aload         8
      72: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      77: ifeq          245
      80: aload         8
      82: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      87: astore        9
      89: aload         9
      91: checkcast     #70                 // class java/lang/String
      94: astore        10
      96: iconst_0
      97: istore        11
      99: aload         10
     101: checkcast     #143                // class java/lang/CharSequence
     104: iconst_1
     105: newarray       char
     107: astore        12
     109: aload         12
     111: iconst_0
     112: bipush        44
     114: castore
     115: aload         12
     117: iconst_0
     118: iconst_0
     119: bipush        6
     121: aconst_null
     122: invokestatic  #149                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     125: checkcast     #41                 // class java/lang/Iterable
     128: astore        12
     130: iconst_0
     131: istore        13
     133: aload         12
     135: astore        14
     137: new           #43                 // class java/util/ArrayList
     140: dup
     141: aload         12
     143: bipush        10
     145: invokestatic  #49                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     148: invokespecial #52                 // Method java/util/ArrayList."<init>":(I)V
     151: checkcast     #54                 // class java/util/Collection
     154: astore        15
     156: iconst_0
     157: istore        16
     159: aload         14
     161: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     166: astore        17
     168: aload         17
     170: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     175: ifeq          222
     178: aload         17
     180: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     185: astore        18
     187: aload         15
     189: aload         18
     191: checkcast     #70                 // class java/lang/String
     194: astore        19
     196: astore        20
     198: iconst_0
     199: istore        21
     201: aload         19
     203: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     206: nop
     207: invokestatic  #159                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     210: aload         20
     212: swap
     213: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     218: pop
     219: goto          168
     222: aload         15
     224: checkcast     #31                 // class java/util/List
     227: nop
     228: checkcast     #41                 // class java/lang/Iterable
     231: nop
     232: astore        10
     234: aload         6
     236: aload         10
     238: invokestatic  #163                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     241: pop
     242: goto          70
     245: aload         6
     247: checkcast     #31                 // class java/util/List
     250: nop
     251: checkcast     #41                 // class java/lang/Iterable
     254: astore_3
     255: nop
     256: iconst_0
     257: istore        4
     259: aload_3
     260: astore        5
     262: new           #43                 // class java/util/ArrayList
     265: dup
     266: invokespecial #141                // Method java/util/ArrayList."<init>":()V
     269: checkcast     #54                 // class java/util/Collection
     272: astore        6
     274: iconst_0
     275: istore        7
     277: aload         5
     279: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     284: astore        8
     286: aload         8
     288: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     293: ifeq          437
     296: aload         8
     298: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     303: astore        9
     305: aload         9
     307: checkcast     #165                // class java/lang/Number
     310: invokevirtual #168                // Method java/lang/Number.intValue:()I
     313: istore        10
     315: iconst_0
     316: istore        11
     318: aload_0
     319: checkcast     #41                 // class java/lang/Iterable
     322: astore        12
     324: iconst_0
     325: istore        13
     327: aload         12
     329: instanceof    #54                 // class java/util/Collection
     332: ifeq          352
     335: aload         12
     337: checkcast     #54                 // class java/util/Collection
     340: invokeinterface #171,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     345: ifeq          352
     348: iconst_1
     349: goto          420
     352: aload         12
     354: invokeinterface #58,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     359: astore        14
     361: aload         14
     363: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     368: ifeq          419
     371: aload         14
     373: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     378: astore        15
     380: aload         15
     382: checkcast     #173                // class com/marcdenning/adventofcode/day16/Rule
     385: astore        16
     387: iconst_0
     388: istore        17
     390: aload         16
     392: ldc           #175                // String null cannot be cast to non-null type com.marcdenning.adventofcode.day16.Rule
     394: invokestatic  #178                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
     397: aload         16
     399: iload         10
     401: invokevirtual #182                // Method com/marcdenning/adventofcode/day16/Rule.isNumberValid:(I)Z
     404: ifne          411
     407: iconst_1
     408: goto          412
     411: iconst_0
     412: ifne          361
     415: iconst_0
     416: goto          420
     419: iconst_1
     420: nop
     421: ifeq          286
     424: aload         6
     426: aload         9
     428: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     433: pop
     434: goto          286
     437: aload         6
     439: checkcast     #31                 // class java/util/List
     442: nop
     443: checkcast     #41                 // class java/lang/Iterable
     446: invokestatic  #186                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     449: ireturn

  public static final com.marcdenning.adventofcode.day16.Rule parseRule(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #210                // String ruleString
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #212                // String ([\\w\\s]+):\\s(\\d+)\\-(\\d+)\\sor\\s(\\d+)\\-(\\d+)
       8: invokestatic  #218                // Method java/util/regex/Pattern.compile:(Ljava/lang/String;)Ljava/util/regex/Pattern;
      11: aload_0
      12: checkcast     #143                // class java/lang/CharSequence
      15: invokevirtual #222                // Method java/util/regex/Pattern.matcher:(Ljava/lang/CharSequence;)Ljava/util/regex/Matcher;
      18: astore_1
      19: aload_1
      20: invokevirtual #227                // Method java/util/regex/Matcher.matches:()Z
      23: ifne          34
      26: new           #229                // class java/lang/Exception
      29: dup
      30: invokespecial #230                // Method java/lang/Exception."<init>":()V
      33: athrow
      34: new           #173                // class com/marcdenning/adventofcode/day16/Rule
      37: dup
      38: aload_1
      39: iconst_1
      40: invokevirtual #234                // Method java/util/regex/Matcher.group:(I)Ljava/lang/String;
      43: dup
      44: ldc           #236                // String group(...)
      46: invokestatic  #239                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      49: new           #241                // class kotlin/ranges/IntRange
      52: dup
      53: aload_1
      54: iconst_2
      55: invokevirtual #234                // Method java/util/regex/Matcher.group:(I)Ljava/lang/String;
      58: dup
      59: ldc           #236                // String group(...)
      61: invokestatic  #239                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      64: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      67: aload_1
      68: iconst_3
      69: invokevirtual #234                // Method java/util/regex/Matcher.group:(I)Ljava/lang/String;
      72: dup
      73: ldc           #236                // String group(...)
      75: invokestatic  #239                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      78: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      81: invokespecial #244                // Method kotlin/ranges/IntRange."<init>":(II)V
      84: new           #241                // class kotlin/ranges/IntRange
      87: dup
      88: aload_1
      89: iconst_4
      90: invokevirtual #234                // Method java/util/regex/Matcher.group:(I)Ljava/lang/String;
      93: dup
      94: ldc           #236                // String group(...)
      96: invokestatic  #239                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      99: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     102: aload_1
     103: iconst_5
     104: invokevirtual #234                // Method java/util/regex/Matcher.group:(I)Ljava/lang/String;
     107: dup
     108: ldc           #236                // String group(...)
     110: invokestatic  #239                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     113: invokestatic  #155                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     116: invokespecial #244                // Method kotlin/ranges/IntRange."<init>":(II)V
     119: invokespecial #247                // Method com/marcdenning/adventofcode/day16/Rule."<init>":(Ljava/lang/String;Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)V
     122: areturn
}


package com.marcdenning.adventofcode.day11

import java.io.File

private const val FLOOR = '.'
private const val EMPTY = 'L'
private const val OCCUPIED = '#'

fun main(args: Array<String>) {
    val floorPlanMatrix = File(args[0]).readLines().map { it.toCharArray() }.toTypedArray()

    println("Number of occupied seats: ${countSeats(findSteadyFloorPlanByVisibility(floorPlanMatrix), OCCUPIED)}")

}

fun fillSeatsByVisibility(floorPlanMatrix: Array<CharArray>): Array<CharArray> {
    val outputFloorPlanMatrix = floorPlanMatrix.map { it.copyOf() }.toTypedArray()

    for ((rowIndex, row) in floorPlanMatrix.withIndex()) {
        for ((columnIndex, seat) in row.withIndex()) {
            if (seat == EMPTY && countVisibleSeats(floorPlanMatrix, rowIndex, columnIndex, OCCUPIED) == 0) {
                outputFloorPlanMatrix[rowIndex][columnIndex] = OCCUPIED
            }
        }
    }
    return outputFloorPlanMatrix
}

fun emptySeatsByVisibility(floorPlanMatrix: Array<CharArray>): Array<CharArray> {
    val outputFloorPlanMatrix = floorPlanMatrix.map { it.copyOf() }.toTypedArray()

    for ((rowIndex, row) in floorPlanMatrix.withIndex()) {
        for ((columnIndex, seat) in row.withIndex()) {
            if (seat == OCCUPIED && countVisibleSeats(floorPlanMatrix, rowIndex, columnIndex, OCCUPIED) >= 5) {
                outputFloorPlanMatrix[rowIndex][columnIndex] = EMPTY
            }
        }
    }
    return outputFloorPlanMatrix
}

fun findSteadyFloorPlanByVisibility(floorPlanMatrix: Array<CharArray>): Array<CharArray> {
    var lastFloorPlan = Array(floorPlanMatrix.size) { CharArray(floorPlanMatrix[0].size) }
    var currentFloorPlan = floorPlanMatrix.copyOf()
    var isFillTurn = true

    while (!lastFloorPlan.contentDeepEquals(currentFloorPlan)) {
        lastFloorPlan = currentFloorPlan
        if (isFillTurn) {
            currentFloorPlan = fillSeatsByVisibility(currentFloorPlan)
            isFillTurn = false
        } else {
            currentFloorPlan = emptySeatsByVisibility(currentFloorPlan)
            isFillTurn = true
        }
    }
    return currentFloorPlan
}

fun countVisibleSeats(floorPlanMatrix: Array<CharArray>, rowIndex: Int, columnIndex: Int, targetSeat: Char): Int {
    val directions = listOf(
        Pair(-1, 0),
        Pair(-1, 1),
        Pair(0, 1),
        Pair(1, 1),
        Pair(1, 0),
        Pair(1, -1),
        Pair(0, -1),
        Pair(-1, -1)
    )
    var countOfSeats = 0

    for (directionPair in directions) {
        if (findVisibleSeatInDirection(floorPlanMatrix, rowIndex, columnIndex, directionPair.first, directionPair.second) == targetSeat) {
            countOfSeats++
        }
    }
    return countOfSeats
}

fun findVisibleSeatInDirection(floorPlanMatrix: Array<CharArray>, rowIndex: Int, columnIndex: Int, rowIncrement: Int, columnIncrement: Int): Char {
    if (rowIndex + rowIncrement < 0 || rowIndex + rowIncrement >= floorPlanMatrix.size ||
            columnIndex + columnIncrement < 0 || columnIndex + columnIncrement >= floorPlanMatrix[rowIndex].size) {
        return ' '
    }

    val cell = floorPlanMatrix[rowIndex + rowIncrement][columnIndex + columnIncrement]

    if (cell == EMPTY || cell == OCCUPIED) {
        return cell
    }
    return findVisibleSeatInDirection(floorPlanMatrix, rowIndex + rowIncrement, columnIndex + columnIncrement, rowIncrement, columnIncrement)
}

Compiled from "Day11b.kt"
public final class com.marcdenning.adventofcode.day11.Day11bKt {
  private static final char FLOOR;

  private static final char EMPTY;

  private static final char OCCUPIED;

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class java/io/File
       9: dup
      10: aload_0
      11: iconst_0
      12: aaload
      13: invokespecial #21                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      16: aconst_null
      17: iconst_1
      18: aconst_null
      19: invokestatic  #27                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      22: checkcast     #29                 // class java/lang/Iterable
      25: astore_2
      26: iconst_0
      27: istore_3
      28: aload_2
      29: astore        4
      31: new           #31                 // class java/util/ArrayList
      34: dup
      35: aload_2
      36: bipush        10
      38: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      41: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      44: checkcast     #42                 // class java/util/Collection
      47: astore        5
      49: iconst_0
      50: istore        6
      52: aload         4
      54: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      59: astore        7
      61: aload         7
      63: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      68: ifeq          118
      71: aload         7
      73: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      78: astore        8
      80: aload         5
      82: aload         8
      84: checkcast     #58                 // class java/lang/String
      87: astore        9
      89: astore        11
      91: iconst_0
      92: istore        10
      94: aload         9
      96: invokevirtual #62                 // Method java/lang/String.toCharArray:()[C
      99: dup
     100: ldc           #64                 // String toCharArray(...)
     102: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     105: nop
     106: aload         11
     108: swap
     109: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     114: pop
     115: goto          61
     118: aload         5
     120: checkcast     #73                 // class java/util/List
     123: nop
     124: checkcast     #42                 // class java/util/Collection
     127: astore_2
     128: nop
     129: iconst_0
     130: istore_3
     131: aload_2
     132: astore        4
     134: aload         4
     136: iconst_0
     137: anewarray     #75                 // class "[C"
     140: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     145: checkcast     #81                 // class "[[C"
     148: astore_1
     149: new           #83                 // class java/lang/StringBuilder
     152: dup
     153: invokespecial #86                 // Method java/lang/StringBuilder."<init>":()V
     156: ldc           #88                 // String Number of occupied seats:
     158: invokevirtual #92                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     161: aload_1
     162: invokestatic  #96                 // Method findSteadyFloorPlanByVisibility:([[C)[[C
     165: bipush        35
     167: invokestatic  #102                // Method com/marcdenning/adventofcode/day11/Day11aKt.countSeats:([[CC)I
     170: invokevirtual #105                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     173: invokevirtual #109                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     176: getstatic     #115                // Field java/lang/System.out:Ljava/io/PrintStream;
     179: swap
     180: invokevirtual #121                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     183: return

  public static final char[][] fillSeatsByVisibility(char[][]);
    Code:
       0: aload_0
       1: ldc           #142                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #144                // class "[Ljava/lang/Object;"
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #31                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: arraylength
      22: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #42                 // class java/util/Collection
      28: astore        5
      30: iconst_0
      31: istore        6
      33: iconst_0
      34: istore        7
      36: aload         4
      38: arraylength
      39: istore        8
      41: iload         7
      43: iload         8
      45: if_icmpge     98
      48: aload         4
      50: iload         7
      52: aaload
      53: astore        9
      55: aload         5
      57: aload         9
      59: checkcast     #75                 // class "[C"
      62: astore        10
      64: astore        12
      66: iconst_0
      67: istore        11
      69: aload         10
      71: dup
      72: arraylength
      73: invokestatic  #150                // Method java/util/Arrays.copyOf:([CI)[C
      76: dup
      77: ldc           #152                // String copyOf(...)
      79: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      82: nop
      83: aload         12
      85: swap
      86: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: iinc          7, 1
      95: goto          41
      98: aload         5
     100: checkcast     #73                 // class java/util/List
     103: nop
     104: checkcast     #42                 // class java/util/Collection
     107: astore_2
     108: nop
     109: iconst_0
     110: istore_3
     111: aload_2
     112: astore        4
     114: aload         4
     116: iconst_0
     117: anewarray     #75                 // class "[C"
     120: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     125: checkcast     #81                 // class "[[C"
     128: astore_1
     129: iconst_0
     130: istore_2
     131: aload_0
     132: checkcast     #144                // class "[Ljava/lang/Object;"
     135: arraylength
     136: istore_3
     137: iload_2
     138: iload_3
     139: if_icmpge     217
     142: iload_2
     143: istore        4
     145: aload_0
     146: iload_2
     147: aaload
     148: astore        5
     150: iconst_0
     151: istore        6
     153: aload         5
     155: arraylength
     156: istore        7
     158: iload         6
     160: iload         7
     162: if_icmpge     211
     165: iload         6
     167: istore        8
     169: aload         5
     171: iload         6
     173: caload
     174: istore        9
     176: iload         9
     178: bipush        76
     180: if_icmpne     205
     183: aload_0
     184: iload         4
     186: iload         8
     188: bipush        35
     190: invokestatic  #156                // Method countVisibleSeats:([[CIIC)I
     193: ifne          205
     196: aload_1
     197: iload         4
     199: aaload
     200: iload         8
     202: bipush        35
     204: castore
     205: iinc          6, 1
     208: goto          158
     211: iinc          2, 1
     214: goto          137
     217: aload_1
     218: areturn

  public static final char[][] emptySeatsByVisibility(char[][]);
    Code:
       0: aload_0
       1: ldc           #142                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #144                // class "[Ljava/lang/Object;"
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #31                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: arraylength
      22: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #42                 // class java/util/Collection
      28: astore        5
      30: iconst_0
      31: istore        6
      33: iconst_0
      34: istore        7
      36: aload         4
      38: arraylength
      39: istore        8
      41: iload         7
      43: iload         8
      45: if_icmpge     98
      48: aload         4
      50: iload         7
      52: aaload
      53: astore        9
      55: aload         5
      57: aload         9
      59: checkcast     #75                 // class "[C"
      62: astore        10
      64: astore        12
      66: iconst_0
      67: istore        11
      69: aload         10
      71: dup
      72: arraylength
      73: invokestatic  #150                // Method java/util/Arrays.copyOf:([CI)[C
      76: dup
      77: ldc           #152                // String copyOf(...)
      79: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      82: nop
      83: aload         12
      85: swap
      86: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: iinc          7, 1
      95: goto          41
      98: aload         5
     100: checkcast     #73                 // class java/util/List
     103: nop
     104: checkcast     #42                 // class java/util/Collection
     107: astore_2
     108: nop
     109: iconst_0
     110: istore_3
     111: aload_2
     112: astore        4
     114: aload         4
     116: iconst_0
     117: anewarray     #75                 // class "[C"
     120: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     125: checkcast     #81                 // class "[[C"
     128: astore_1
     129: iconst_0
     130: istore_2
     131: aload_0
     132: checkcast     #144                // class "[Ljava/lang/Object;"
     135: arraylength
     136: istore_3
     137: iload_2
     138: iload_3
     139: if_icmpge     218
     142: iload_2
     143: istore        4
     145: aload_0
     146: iload_2
     147: aaload
     148: astore        5
     150: iconst_0
     151: istore        6
     153: aload         5
     155: arraylength
     156: istore        7
     158: iload         6
     160: iload         7
     162: if_icmpge     212
     165: iload         6
     167: istore        8
     169: aload         5
     171: iload         6
     173: caload
     174: istore        9
     176: iload         9
     178: bipush        35
     180: if_icmpne     206
     183: aload_0
     184: iload         4
     186: iload         8
     188: bipush        35
     190: invokestatic  #156                // Method countVisibleSeats:([[CIIC)I
     193: iconst_5
     194: if_icmplt     206
     197: aload_1
     198: iload         4
     200: aaload
     201: iload         8
     203: bipush        76
     205: castore
     206: iinc          6, 1
     209: goto          158
     212: iinc          2, 1
     215: goto          137
     218: aload_1
     219: areturn

  public static final char[][] findSteadyFloorPlanByVisibility(char[][]);
    Code:
       0: aload_0
       1: ldc           #142                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_0
       9: checkcast     #144                // class "[Ljava/lang/Object;"
      12: arraylength
      13: istore_3
      14: iload_3
      15: anewarray     #75                 // class "[C"
      18: astore        4
      20: iload_2
      21: iload_3
      22: if_icmpge     45
      25: iload_2
      26: istore        5
      28: aload         4
      30: iload         5
      32: aload_0
      33: iconst_0
      34: aaload
      35: arraylength
      36: newarray       char
      38: aastore
      39: iinc          2, 1
      42: goto          20
      45: aload         4
      47: astore_1
      48: aload_0
      49: checkcast     #144                // class "[Ljava/lang/Object;"
      52: dup
      53: arraylength
      54: invokestatic  #168                // Method java/util/Arrays.copyOf:([Ljava/lang/Object;I)[Ljava/lang/Object;
      57: dup
      58: ldc           #152                // String copyOf(...)
      60: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      63: checkcast     #81                 // class "[[C"
      66: astore_2
      67: iconst_1
      68: istore_3
      69: aload_1
      70: checkcast     #144                // class "[Ljava/lang/Object;"
      73: aload_2
      74: checkcast     #144                // class "[Ljava/lang/Object;"
      77: invokestatic  #174                // Method kotlin/collections/ArraysKt.contentDeepEquals:([Ljava/lang/Object;[Ljava/lang/Object;)Z
      80: ifne          109
      83: aload_2
      84: astore_1
      85: iload_3
      86: ifeq          99
      89: aload_2
      90: invokestatic  #176                // Method fillSeatsByVisibility:([[C)[[C
      93: astore_2
      94: iconst_0
      95: istore_3
      96: goto          69
      99: aload_2
     100: invokestatic  #178                // Method emptySeatsByVisibility:([[C)[[C
     103: astore_2
     104: iconst_1
     105: istore_3
     106: goto          69
     109: aload_2
     110: areturn

  public static final int countVisibleSeats(char[][], int, int, char);
    Code:
       0: aload_0
       1: ldc           #142                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: bipush        8
       8: anewarray     #184                // class kotlin/Pair
      11: astore        5
      13: aload         5
      15: iconst_0
      16: new           #184                // class kotlin/Pair
      19: dup
      20: iconst_m1
      21: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      24: iconst_0
      25: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: invokespecial #193                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      31: aastore
      32: aload         5
      34: iconst_1
      35: new           #184                // class kotlin/Pair
      38: dup
      39: iconst_m1
      40: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      43: iconst_1
      44: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: invokespecial #193                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      50: aastore
      51: aload         5
      53: iconst_2
      54: new           #184                // class kotlin/Pair
      57: dup
      58: iconst_0
      59: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      62: iconst_1
      63: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokespecial #193                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      69: aastore
      70: aload         5
      72: iconst_3
      73: new           #184                // class kotlin/Pair
      76: dup
      77: iconst_1
      78: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      81: iconst_1
      82: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      85: invokespecial #193                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      88: aastore
      89: aload         5
      91: iconst_4
      92: new           #184                // class kotlin/Pair
      95: dup
      96: iconst_1
      97: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     100: iconst_0
     101: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: invokespecial #193                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     107: aastore
     108: aload         5
     110: iconst_5
     111: new           #184                // class kotlin/Pair
     114: dup
     115: iconst_1
     116: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     119: iconst_m1
     120: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     123: invokespecial #193                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     126: aastore
     127: aload         5
     129: bipush        6
     131: new           #184                // class kotlin/Pair
     134: dup
     135: iconst_0
     136: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     139: iconst_m1
     140: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: invokespecial #193                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     146: aastore
     147: aload         5
     149: bipush        7
     151: new           #184                // class kotlin/Pair
     154: dup
     155: iconst_m1
     156: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     159: iconst_m1
     160: invokestatic  #190                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     163: invokespecial #193                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     166: aastore
     167: aload         5
     169: invokestatic  #197                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     172: astore        4
     174: iconst_0
     175: istore        5
     177: aload         4
     179: invokeinterface #198,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     184: astore        6
     186: aload         6
     188: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     193: ifeq          246
     196: aload         6
     198: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     203: checkcast     #184                // class kotlin/Pair
     206: astore        7
     208: aload_0
     209: iload_1
     210: iload_2
     211: aload         7
     213: invokevirtual #201                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     216: checkcast     #203                // class java/lang/Number
     219: invokevirtual #207                // Method java/lang/Number.intValue:()I
     222: aload         7
     224: invokevirtual #210                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     227: checkcast     #203                // class java/lang/Number
     230: invokevirtual #207                // Method java/lang/Number.intValue:()I
     233: invokestatic  #214                // Method findVisibleSeatInDirection:([[CIIII)C
     236: iload_3
     237: if_icmpne     186
     240: iinc          5, 1
     243: goto          186
     246: iload         5
     248: ireturn

  public static final char findVisibleSeatInDirection(char[][], int, int, int, int);
    Code:
       0: aload_0
       1: ldc           #142                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_1
       7: iload_3
       8: iadd
       9: iflt          41
      12: iload_1
      13: iload_3
      14: iadd
      15: aload_0
      16: checkcast     #144                // class "[Ljava/lang/Object;"
      19: arraylength
      20: if_icmpge     41
      23: iload_2
      24: iload         4
      26: iadd
      27: iflt          41
      30: iload_2
      31: iload         4
      33: iadd
      34: aload_0
      35: iload_1
      36: aaload
      37: arraylength
      38: if_icmplt     44
      41: bipush        32
      43: ireturn
      44: aload_0
      45: iload_1
      46: iload_3
      47: iadd
      48: aaload
      49: iload_2
      50: iload         4
      52: iadd
      53: caload
      54: istore        5
      56: iload         5
      58: lookupswitch  { // 2
                    35: 84
                    76: 84
               default: 87
          }
      84: iload         5
      86: ireturn
      87: aload_0
      88: iload_1
      89: iload_3
      90: iadd
      91: iload_2
      92: iload         4
      94: iadd
      95: iload_3
      96: iload         4
      98: invokestatic  #214                // Method findVisibleSeatInDirection:([[CIIII)C
     101: ireturn
}


package com.marcdenning.adventofcode.day11

import java.io.File
import java.lang.Integer.max
import java.lang.Integer.min

private const val FLOOR = '.'
private const val EMPTY = 'L'
private const val OCCUPIED = '#'

fun main(args: Array<String>) {
    val floorPlanMatrix = File(args[0]).readLines().map { it.toCharArray() }.toTypedArray()

    println("Number of occupied seats: ${countSeats(findSteadyFloorPlan(floorPlanMatrix), OCCUPIED)}")
}

fun fillSeats(floorPlanMatrix: Array<CharArray>): Array<CharArray> {
    val outputFloorPlanMatrix = floorPlanMatrix.map { it.copyOf() }.toTypedArray()

    for ((rowIndex, row) in floorPlanMatrix.withIndex()) {
        for ((columnIndex, seat) in row.withIndex()) {
            if (seat == EMPTY && countSeats(getAdjascentSeats(floorPlanMatrix, rowIndex, columnIndex), OCCUPIED) == 0) {
                outputFloorPlanMatrix[rowIndex][columnIndex] = OCCUPIED
            }
        }
    }
    return outputFloorPlanMatrix
}

fun emptySeats(floorPlanMatrix: Array<CharArray>): Array<CharArray> {
    val outputFloorPlanMatrix = floorPlanMatrix.map { it.copyOf() }.toTypedArray()

    for ((rowIndex, row) in floorPlanMatrix.withIndex()) {
        for ((columnIndex, seat) in row.withIndex()) {
            if (seat == OCCUPIED && countSeats(getAdjascentSeats(floorPlanMatrix, rowIndex, columnIndex), OCCUPIED) >= 4) {
                outputFloorPlanMatrix[rowIndex][columnIndex] = EMPTY
            }
        }
    }
    return outputFloorPlanMatrix
}

fun getAdjascentSeats(floorPlanMatrix: Array<CharArray>, rowIndex: Int, columnIndex: Int): Array<CharArray> {
    val startRow = max(0, rowIndex - 1)
    val startColumn = max(0, columnIndex - 1)
    val endRow = min(floorPlanMatrix.size - 1, rowIndex + 1)
    val endColumn = min(floorPlanMatrix[0].size - 1, columnIndex + 1)
    val adjascentSeatMatrix = floorPlanMatrix.copyOfRange(startRow, endRow + 1)
        .map { row -> row.copyOfRange(startColumn, endColumn + 1) }
        .toTypedArray()

    adjascentSeatMatrix[rowIndex - startRow][columnIndex - startColumn] = ' '
    return adjascentSeatMatrix
}

fun findSteadyFloorPlan(floorPlanMatrix: Array<CharArray>): Array<CharArray> {
    var lastFloorPlan = Array(floorPlanMatrix.size) { CharArray(floorPlanMatrix[0].size) }
    var currentFloorPlan = floorPlanMatrix.copyOf()
    var isFillTurn = true

    while (!lastFloorPlan.contentDeepEquals(currentFloorPlan)) {
        lastFloorPlan = currentFloorPlan
        if (isFillTurn) {
            currentFloorPlan = fillSeats(currentFloorPlan)
            isFillTurn = false
        } else {
            currentFloorPlan = emptySeats(currentFloorPlan)
            isFillTurn = true
        }
    }
    return currentFloorPlan
}

fun countSeats(floorPlanMatrix: Array<CharArray>, seatType: Char): Int =
    floorPlanMatrix.map { row -> row.map { seat -> if (seat == seatType) 1 else 0 }.sum() }.sum()

Compiled from "Day11a.kt"
public final class com.marcdenning.adventofcode.day11.Day11aKt {
  private static final char FLOOR;

  private static final char EMPTY;

  private static final char OCCUPIED;

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class java/io/File
       9: dup
      10: aload_0
      11: iconst_0
      12: aaload
      13: invokespecial #21                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      16: aconst_null
      17: iconst_1
      18: aconst_null
      19: invokestatic  #27                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      22: checkcast     #29                 // class java/lang/Iterable
      25: astore_2
      26: iconst_0
      27: istore_3
      28: aload_2
      29: astore        4
      31: new           #31                 // class java/util/ArrayList
      34: dup
      35: aload_2
      36: bipush        10
      38: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      41: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      44: checkcast     #42                 // class java/util/Collection
      47: astore        5
      49: iconst_0
      50: istore        6
      52: aload         4
      54: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      59: astore        7
      61: aload         7
      63: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      68: ifeq          118
      71: aload         7
      73: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      78: astore        8
      80: aload         5
      82: aload         8
      84: checkcast     #58                 // class java/lang/String
      87: astore        9
      89: astore        11
      91: iconst_0
      92: istore        10
      94: aload         9
      96: invokevirtual #62                 // Method java/lang/String.toCharArray:()[C
      99: dup
     100: ldc           #64                 // String toCharArray(...)
     102: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     105: nop
     106: aload         11
     108: swap
     109: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     114: pop
     115: goto          61
     118: aload         5
     120: checkcast     #73                 // class java/util/List
     123: nop
     124: checkcast     #42                 // class java/util/Collection
     127: astore_2
     128: nop
     129: iconst_0
     130: istore_3
     131: aload_2
     132: astore        4
     134: aload         4
     136: iconst_0
     137: anewarray     #75                 // class "[C"
     140: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     145: checkcast     #81                 // class "[[C"
     148: astore_1
     149: new           #83                 // class java/lang/StringBuilder
     152: dup
     153: invokespecial #86                 // Method java/lang/StringBuilder."<init>":()V
     156: ldc           #88                 // String Number of occupied seats:
     158: invokevirtual #92                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     161: aload_1
     162: invokestatic  #96                 // Method findSteadyFloorPlan:([[C)[[C
     165: bipush        35
     167: invokestatic  #100                // Method countSeats:([[CC)I
     170: invokevirtual #103                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     173: invokevirtual #107                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     176: getstatic     #113                // Field java/lang/System.out:Ljava/io/PrintStream;
     179: swap
     180: invokevirtual #119                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     183: return

  public static final char[][] fillSeats(char[][]);
    Code:
       0: aload_0
       1: ldc           #140                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #142                // class "[Ljava/lang/Object;"
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #31                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: arraylength
      22: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #42                 // class java/util/Collection
      28: astore        5
      30: iconst_0
      31: istore        6
      33: iconst_0
      34: istore        7
      36: aload         4
      38: arraylength
      39: istore        8
      41: iload         7
      43: iload         8
      45: if_icmpge     98
      48: aload         4
      50: iload         7
      52: aaload
      53: astore        9
      55: aload         5
      57: aload         9
      59: checkcast     #75                 // class "[C"
      62: astore        10
      64: astore        12
      66: iconst_0
      67: istore        11
      69: aload         10
      71: dup
      72: arraylength
      73: invokestatic  #148                // Method java/util/Arrays.copyOf:([CI)[C
      76: dup
      77: ldc           #150                // String copyOf(...)
      79: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      82: nop
      83: aload         12
      85: swap
      86: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: iinc          7, 1
      95: goto          41
      98: aload         5
     100: checkcast     #73                 // class java/util/List
     103: nop
     104: checkcast     #42                 // class java/util/Collection
     107: astore_2
     108: nop
     109: iconst_0
     110: istore_3
     111: aload_2
     112: astore        4
     114: aload         4
     116: iconst_0
     117: anewarray     #75                 // class "[C"
     120: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     125: checkcast     #81                 // class "[[C"
     128: astore_1
     129: iconst_0
     130: istore_2
     131: aload_0
     132: checkcast     #142                // class "[Ljava/lang/Object;"
     135: arraylength
     136: istore_3
     137: iload_2
     138: iload_3
     139: if_icmpge     220
     142: iload_2
     143: istore        4
     145: aload_0
     146: iload_2
     147: aaload
     148: astore        5
     150: iconst_0
     151: istore        6
     153: aload         5
     155: arraylength
     156: istore        7
     158: iload         6
     160: iload         7
     162: if_icmpge     214
     165: iload         6
     167: istore        8
     169: aload         5
     171: iload         6
     173: caload
     174: istore        9
     176: iload         9
     178: bipush        76
     180: if_icmpne     208
     183: aload_0
     184: iload         4
     186: iload         8
     188: invokestatic  #154                // Method getAdjascentSeats:([[CII)[[C
     191: bipush        35
     193: invokestatic  #100                // Method countSeats:([[CC)I
     196: ifne          208
     199: aload_1
     200: iload         4
     202: aaload
     203: iload         8
     205: bipush        35
     207: castore
     208: iinc          6, 1
     211: goto          158
     214: iinc          2, 1
     217: goto          137
     220: aload_1
     221: areturn

  public static final char[][] emptySeats(char[][]);
    Code:
       0: aload_0
       1: ldc           #140                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #142                // class "[Ljava/lang/Object;"
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #31                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: arraylength
      22: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #42                 // class java/util/Collection
      28: astore        5
      30: iconst_0
      31: istore        6
      33: iconst_0
      34: istore        7
      36: aload         4
      38: arraylength
      39: istore        8
      41: iload         7
      43: iload         8
      45: if_icmpge     98
      48: aload         4
      50: iload         7
      52: aaload
      53: astore        9
      55: aload         5
      57: aload         9
      59: checkcast     #75                 // class "[C"
      62: astore        10
      64: astore        12
      66: iconst_0
      67: istore        11
      69: aload         10
      71: dup
      72: arraylength
      73: invokestatic  #148                // Method java/util/Arrays.copyOf:([CI)[C
      76: dup
      77: ldc           #150                // String copyOf(...)
      79: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      82: nop
      83: aload         12
      85: swap
      86: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: iinc          7, 1
      95: goto          41
      98: aload         5
     100: checkcast     #73                 // class java/util/List
     103: nop
     104: checkcast     #42                 // class java/util/Collection
     107: astore_2
     108: nop
     109: iconst_0
     110: istore_3
     111: aload_2
     112: astore        4
     114: aload         4
     116: iconst_0
     117: anewarray     #75                 // class "[C"
     120: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     125: checkcast     #81                 // class "[[C"
     128: astore_1
     129: iconst_0
     130: istore_2
     131: aload_0
     132: checkcast     #142                // class "[Ljava/lang/Object;"
     135: arraylength
     136: istore_3
     137: iload_2
     138: iload_3
     139: if_icmpge     221
     142: iload_2
     143: istore        4
     145: aload_0
     146: iload_2
     147: aaload
     148: astore        5
     150: iconst_0
     151: istore        6
     153: aload         5
     155: arraylength
     156: istore        7
     158: iload         6
     160: iload         7
     162: if_icmpge     215
     165: iload         6
     167: istore        8
     169: aload         5
     171: iload         6
     173: caload
     174: istore        9
     176: iload         9
     178: bipush        35
     180: if_icmpne     209
     183: aload_0
     184: iload         4
     186: iload         8
     188: invokestatic  #154                // Method getAdjascentSeats:([[CII)[[C
     191: bipush        35
     193: invokestatic  #100                // Method countSeats:([[CC)I
     196: iconst_4
     197: if_icmplt     209
     200: aload_1
     201: iload         4
     203: aaload
     204: iload         8
     206: bipush        76
     208: castore
     209: iinc          6, 1
     212: goto          158
     215: iinc          2, 1
     218: goto          137
     221: aload_1
     222: areturn

  public static final char[][] getAdjascentSeats(char[][], int, int);
    Code:
       0: aload_0
       1: ldc           #140                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: iload_1
       8: iconst_1
       9: isub
      10: invokestatic  #169                // Method java/lang/Integer.max:(II)I
      13: istore_3
      14: iconst_0
      15: iload_2
      16: iconst_1
      17: isub
      18: invokestatic  #169                // Method java/lang/Integer.max:(II)I
      21: istore        4
      23: aload_0
      24: checkcast     #142                // class "[Ljava/lang/Object;"
      27: arraylength
      28: iconst_1
      29: isub
      30: iload_1
      31: iconst_1
      32: iadd
      33: invokestatic  #172                // Method java/lang/Integer.min:(II)I
      36: istore        5
      38: aload_0
      39: iconst_0
      40: aaload
      41: arraylength
      42: iconst_1
      43: isub
      44: iload_2
      45: iconst_1
      46: iadd
      47: invokestatic  #172                // Method java/lang/Integer.min:(II)I
      50: istore        6
      52: aload_0
      53: checkcast     #142                // class "[Ljava/lang/Object;"
      56: iload_3
      57: iload         5
      59: iconst_1
      60: iadd
      61: invokestatic  #178                // Method kotlin/collections/ArraysKt.copyOfRange:([Ljava/lang/Object;II)[Ljava/lang/Object;
      64: astore        8
      66: nop
      67: iconst_0
      68: istore        9
      70: aload         8
      72: astore        10
      74: new           #31                 // class java/util/ArrayList
      77: dup
      78: aload         8
      80: arraylength
      81: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      84: checkcast     #42                 // class java/util/Collection
      87: astore        11
      89: iconst_0
      90: istore        12
      92: iconst_0
      93: istore        13
      95: aload         10
      97: arraylength
      98: istore        14
     100: iload         13
     102: iload         14
     104: if_icmpge     155
     107: aload         10
     109: iload         13
     111: aaload
     112: astore        15
     114: aload         11
     116: aload         15
     118: checkcast     #75                 // class "[C"
     121: astore        16
     123: astore        18
     125: iconst_0
     126: istore        17
     128: aload         16
     130: iload         4
     132: iload         6
     134: iconst_1
     135: iadd
     136: invokestatic  #181                // Method kotlin/collections/ArraysKt.copyOfRange:([CII)[C
     139: nop
     140: aload         18
     142: swap
     143: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     148: pop
     149: iinc          13, 1
     152: goto          100
     155: aload         11
     157: checkcast     #73                 // class java/util/List
     160: nop
     161: checkcast     #42                 // class java/util/Collection
     164: astore        8
     166: nop
     167: iconst_0
     168: istore        9
     170: aload         8
     172: astore        10
     174: aload         10
     176: iconst_0
     177: anewarray     #75                 // class "[C"
     180: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     185: checkcast     #81                 // class "[[C"
     188: astore        7
     190: aload         7
     192: iload_1
     193: iload_3
     194: isub
     195: aaload
     196: iload_2
     197: iload         4
     199: isub
     200: bipush        32
     202: castore
     203: aload         7
     205: areturn

  public static final char[][] findSteadyFloorPlan(char[][]);
    Code:
       0: aload_0
       1: ldc           #140                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_0
       9: checkcast     #142                // class "[Ljava/lang/Object;"
      12: arraylength
      13: istore_3
      14: iload_3
      15: anewarray     #75                 // class "[C"
      18: astore        4
      20: iload_2
      21: iload_3
      22: if_icmpge     45
      25: iload_2
      26: istore        5
      28: aload         4
      30: iload         5
      32: aload_0
      33: iconst_0
      34: aaload
      35: arraylength
      36: newarray       char
      38: aastore
      39: iinc          2, 1
      42: goto          20
      45: aload         4
      47: astore_1
      48: aload_0
      49: checkcast     #142                // class "[Ljava/lang/Object;"
      52: dup
      53: arraylength
      54: invokestatic  #190                // Method java/util/Arrays.copyOf:([Ljava/lang/Object;I)[Ljava/lang/Object;
      57: dup
      58: ldc           #150                // String copyOf(...)
      60: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      63: checkcast     #81                 // class "[[C"
      66: astore_2
      67: iconst_1
      68: istore_3
      69: aload_1
      70: checkcast     #142                // class "[Ljava/lang/Object;"
      73: aload_2
      74: checkcast     #142                // class "[Ljava/lang/Object;"
      77: invokestatic  #194                // Method kotlin/collections/ArraysKt.contentDeepEquals:([Ljava/lang/Object;[Ljava/lang/Object;)Z
      80: ifne          109
      83: aload_2
      84: astore_1
      85: iload_3
      86: ifeq          99
      89: aload_2
      90: invokestatic  #196                // Method fillSeats:([[C)[[C
      93: astore_2
      94: iconst_0
      95: istore_3
      96: goto          69
      99: aload_2
     100: invokestatic  #198                // Method emptySeats:([[C)[[C
     103: astore_2
     104: iconst_1
     105: istore_3
     106: goto          69
     109: aload_2
     110: areturn

  public static final int countSeats(char[][], char);
    Code:
       0: aload_0
       1: ldc           #140                // String floorPlanMatrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #142                // class "[Ljava/lang/Object;"
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #31                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: arraylength
      22: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #42                 // class java/util/Collection
      28: astore        5
      30: iconst_0
      31: istore        6
      33: iconst_0
      34: istore        7
      36: aload         4
      38: arraylength
      39: istore        8
      41: iload         7
      43: iload         8
      45: if_icmpge     190
      48: aload         4
      50: iload         7
      52: aaload
      53: astore        9
      55: aload         5
      57: aload         9
      59: checkcast     #75                 // class "[C"
      62: astore        10
      64: astore        23
      66: iconst_0
      67: istore        11
      69: aload         10
      71: astore        12
      73: iconst_0
      74: istore        13
      76: aload         12
      78: astore        14
      80: new           #31                 // class java/util/ArrayList
      83: dup
      84: aload         12
      86: arraylength
      87: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      90: checkcast     #42                 // class java/util/Collection
      93: astore        15
      95: iconst_0
      96: istore        16
      98: iconst_0
      99: istore        17
     101: aload         14
     103: arraylength
     104: istore        18
     106: iload         17
     108: iload         18
     110: if_icmpge     160
     113: aload         14
     115: iload         17
     117: caload
     118: istore        19
     120: aload         15
     122: iload         19
     124: istore        20
     126: astore        21
     128: iconst_0
     129: istore        22
     131: iload         20
     133: iload_1
     134: if_icmpne     141
     137: iconst_1
     138: goto          142
     141: iconst_0
     142: invokestatic  #206                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     145: aload         21
     147: swap
     148: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     153: pop
     154: iinc          17, 1
     157: goto          106
     160: aload         15
     162: checkcast     #73                 // class java/util/List
     165: nop
     166: checkcast     #29                 // class java/lang/Iterable
     169: invokestatic  #210                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     172: invokestatic  #206                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     175: aload         23
     177: swap
     178: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     183: pop
     184: iinc          7, 1
     187: goto          41
     190: aload         5
     192: checkcast     #73                 // class java/util/List
     195: nop
     196: checkcast     #29                 // class java/lang/Iterable
     199: invokestatic  #210                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     202: ireturn
}