import java.io.File
import java.nio.charset.Charset.defaultCharset
import kotlin.streams.toList

typealias OctopusGrid = Map<Pair<Int, Int>, Day11.Octopus>

object Day11 {
    private fun toCoordinates(row: Int, line: String) = line.chars()
        .map(Character::getNumericValue)
        .toList()
        .mapIndexed { col, value -> (row to col) to Octopus((row to col), value) }

    val octopusGrid = {
        File("day11/input-Day11.kt.txt")
            .readLines(defaultCharset())
            .mapIndexed(::toCoordinates)
            .flatten()
            .associate { it }
    }

    data class Octopus(var coord: Pair<Int, Int>, var score: Int, var hasFlashed: Boolean = false) {
        fun increment() = score++
        private fun needsToFlash() = score > 9 && !hasFlashed

        private fun flash() {
            hasFlashed = true
        }

        fun reset() = if (hasFlashed) {
            hasFlashed = false; score = 0; 1
        } else 0

        private fun getNeighbours(
            validCells: OctopusGrid,
            deltas: List<Pair<Int, Int>> = listOf(
                -1 to 0, 0 to -1,
                1 to 0, 0 to 1,
                -1 to -1, 1 to 1,
                -1 to 1, 1 to -1
            )
        ) = deltas.asSequence()
            .map { (x2, y2) -> coord.first + x2 to coord.second + y2 }
            .mapNotNull { validCells[it] }

        fun check(grid: OctopusGrid) {
            if (this.needsToFlash()) {
                this.flash()
                this.getNeighbours(grid).forEach { it.increment(); it.check(grid) }
            }
        }
    }

    private fun OctopusGrid.step(): Int {
        this.values.forEach { it.increment() }
        this.values.forEach { oct -> oct.check(this) }
        return this.values.sumOf { it.reset() }
    }

    object Part1 {
        fun run() {
            val grid = octopusGrid()
            val count = (0..99).map { grid.step() }.sum()
            println(count)
        }
    }

    object Part2 {
        private fun OctopusGrid.isNotComplete(): Boolean {
            val flashCount = this.step()
            return flashCount != this.size
        }

        fun run() {
            val grid = octopusGrid()
            var count = 0
            do {
                count++
            } while (grid.isNotComplete())

            println(count)
        }
    }
}

fun main() {
    Day11.Part1.run()
    Day11.Part2.run()
}

Compiled from "Day11.kt"
public final class Day11$Part1 {
  public static final Day11$Part1 INSTANCE;

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

  public final void run();
    Code:
       0: getstatic     #17                 // Field Day11.INSTANCE:LDay11;
       3: invokevirtual #21                 // Method Day11.getOctopusGrid:()Lkotlin/jvm/functions/Function0;
       6: invokeinterface #27,  1           // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object;
      11: checkcast     #29                 // class java/util/Map
      14: astore_1
      15: new           #31                 // class kotlin/ranges/IntRange
      18: dup
      19: iconst_0
      20: bipush        99
      22: invokespecial #34                 // Method kotlin/ranges/IntRange."<init>":(II)V
      25: checkcast     #36                 // class java/lang/Iterable
      28: astore_3
      29: iconst_0
      30: istore        4
      32: aload_3
      33: astore        5
      35: new           #38                 // class java/util/ArrayList
      38: dup
      39: aload_3
      40: bipush        10
      42: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      45: invokespecial #47                 // Method java/util/ArrayList."<init>":(I)V
      48: checkcast     #49                 // class java/util/Collection
      51: astore        6
      53: iconst_0
      54: istore        7
      56: aload         5
      58: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        8
      65: aload         8
      67: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          118
      75: aload         8
      77: checkcast     #61                 // class kotlin/collections/IntIterator
      80: invokevirtual #65                 // Method kotlin/collections/IntIterator.nextInt:()I
      83: istore        9
      85: aload         6
      87: iload         9
      89: istore        10
      91: astore        12
      93: iconst_0
      94: istore        11
      96: getstatic     #17                 // Field Day11.INSTANCE:LDay11;
      99: aload_1
     100: invokestatic  #69                 // Method Day11.access$step:(LDay11;Ljava/util/Map;)I
     103: invokestatic  #75                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: aload         12
     108: swap
     109: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     114: pop
     115: goto          65
     118: aload         6
     120: checkcast     #81                 // class java/util/List
     123: nop
     124: checkcast     #36                 // class java/lang/Iterable
     127: invokestatic  #85                 // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     130: istore_2
     131: getstatic     #91                 // Field java/lang/System.out:Ljava/io/PrintStream;
     134: iload_2
     135: invokevirtual #96                 // Method java/io/PrintStream.println:(I)V
     138: return

  static {};
    Code:
       0: new           #2                  // class Day11$Part1
       3: dup
       4: invokespecial #112                // Method "<init>":()V
       7: putstatic     #114                // Field INSTANCE:LDay11$Part1;
      10: return
}

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

  private static final kotlin.jvm.functions.Function0<java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, Day11$Octopus>> octopusGrid;

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

  private final java.util.List<kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, Day11$Octopus>> toCoordinates(int, java.lang.String);
    Code:
       0: aload_2
       1: invokevirtual #19                 // Method java/lang/String.chars:()Ljava/util/stream/IntStream;
       4: invokedynamic #38,  0             // InvokeDynamic #0:applyAsInt:()Ljava/util/function/IntUnaryOperator;
       9: invokeinterface #44,  2           // InterfaceMethod java/util/stream/IntStream.map:(Ljava/util/function/IntUnaryOperator;)Ljava/util/stream/IntStream;
      14: dup
      15: ldc           #46                 // String map(...)
      17: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      20: invokestatic  #58                 // Method kotlin/streams/jdk8/StreamsKt.toList:(Ljava/util/stream/IntStream;)Ljava/util/List;
      23: checkcast     #60                 // class java/lang/Iterable
      26: astore_3
      27: nop
      28: iconst_0
      29: istore        4
      31: aload_3
      32: astore        5
      34: new           #62                 // class java/util/ArrayList
      37: dup
      38: aload_3
      39: bipush        10
      41: invokestatic  #68                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      44: invokespecial #71                 // Method java/util/ArrayList."<init>":(I)V
      47: checkcast     #73                 // class java/util/Collection
      50: astore        6
      52: iconst_0
      53: istore        7
      55: iconst_0
      56: istore        8
      58: aload         5
      60: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      65: astore        9
      67: aload         9
      69: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      74: ifeq          173
      77: aload         9
      79: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      84: astore        10
      86: aload         6
      88: iload         8
      90: iinc          8, 1
      93: istore        11
      95: iload         11
      97: ifge          103
     100: invokestatic  #90                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     103: iload         11
     105: aload         10
     107: checkcast     #92                 // class java/lang/Number
     110: invokevirtual #96                 // Method java/lang/Number.intValue:()I
     113: istore        12
     115: istore        13
     117: astore        15
     119: iconst_0
     120: istore        14
     122: iload_1
     123: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     126: iload         13
     128: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     131: invokestatic  #108                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     134: new           #110                // class Day11$Octopus
     137: dup
     138: iload_1
     139: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     142: iload         13
     144: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     147: invokestatic  #108                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     150: iload         12
     152: iconst_0
     153: iconst_4
     154: aconst_null
     155: invokespecial #113                // Method Day11$Octopus."<init>":(Lkotlin/Pair;IZILkotlin/jvm/internal/DefaultConstructorMarker;)V
     158: invokestatic  #108                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     161: aload         15
     163: swap
     164: invokeinterface #117,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     169: pop
     170: goto          67
     173: aload         6
     175: checkcast     #119                // class java/util/List
     178: nop
     179: areturn

  public final kotlin.jvm.functions.Function0<java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, Day11$Octopus>> getOctopusGrid();
    Code:
       0: getstatic     #144                // Field octopusGrid:Lkotlin/jvm/functions/Function0;
       3: areturn

  private final int step(java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, Day11$Octopus>);
    Code:
       0: aload_1
       1: invokeinterface #153,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
       6: checkcast     #60                 // class java/lang/Iterable
       9: astore_2
      10: iconst_0
      11: istore_3
      12: aload_2
      13: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      18: astore        4
      20: aload         4
      22: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      27: ifeq          59
      30: aload         4
      32: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      37: astore        5
      39: aload         5
      41: checkcast     #110                // class Day11$Octopus
      44: astore        6
      46: iconst_0
      47: istore        7
      49: aload         6
      51: invokevirtual #156                // Method Day11$Octopus.increment:()I
      54: pop
      55: nop
      56: goto          20
      59: nop
      60: aload_1
      61: invokeinterface #153,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      66: checkcast     #60                 // class java/lang/Iterable
      69: astore_2
      70: iconst_0
      71: istore_3
      72: aload_2
      73: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      78: astore        4
      80: aload         4
      82: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      87: ifeq          119
      90: aload         4
      92: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      97: astore        5
      99: aload         5
     101: checkcast     #110                // class Day11$Octopus
     104: astore        6
     106: iconst_0
     107: istore        7
     109: aload         6
     111: aload_1
     112: invokevirtual #160                // Method Day11$Octopus.check:(Ljava/util/Map;)V
     115: nop
     116: goto          80
     119: nop
     120: aload_1
     121: invokeinterface #153,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     126: checkcast     #60                 // class java/lang/Iterable
     129: astore_2
     130: iconst_0
     131: istore_3
     132: aload_2
     133: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     138: astore        4
     140: aload         4
     142: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     147: ifeq          188
     150: aload         4
     152: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     157: astore        5
     159: iload_3
     160: aload         5
     162: checkcast     #110                // class Day11$Octopus
     165: astore        6
     167: istore        8
     169: iconst_0
     170: istore        7
     172: aload         6
     174: invokevirtual #163                // Method Day11$Octopus.reset:()I
     177: istore        9
     179: iload         8
     181: iload         9
     183: iadd
     184: istore_3
     185: goto          140
     188: iload_3
     189: ireturn

  private static final java.util.Map octopusGrid$lambda$2();
    Code:
       0: new           #178                // class java/io/File
       3: dup
       4: ldc           #180                // String day11/input-Day11.kt.txt
       6: invokespecial #183                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: invokestatic  #189                // Method java/nio/charset/Charset.defaultCharset:()Ljava/nio/charset/Charset;
      12: dup
      13: ldc           #191                // String defaultCharset(...)
      15: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      18: invokestatic  #197                // Method kotlin/io/FilesKt.readLines:(Ljava/io/File;Ljava/nio/charset/Charset;)Ljava/util/List;
      21: checkcast     #60                 // class java/lang/Iterable
      24: astore_0
      25: getstatic     #200                // Field INSTANCE:LDay11;
      28: astore_1
      29: iconst_0
      30: istore_2
      31: aload_0
      32: astore_3
      33: new           #62                 // class java/util/ArrayList
      36: dup
      37: aload_0
      38: bipush        10
      40: invokestatic  #68                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      43: invokespecial #71                 // Method java/util/ArrayList."<init>":(I)V
      46: checkcast     #73                 // class java/util/Collection
      49: astore        4
      51: iconst_0
      52: istore        5
      54: iconst_0
      55: istore        6
      57: aload_3
      58: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        7
      65: aload         7
      67: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          137
      75: aload         7
      77: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: astore        8
      84: aload         4
      86: iload         6
      88: iinc          6, 1
      91: istore        9
      93: iload         9
      95: ifge          101
      98: invokestatic  #90                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     101: iload         9
     103: aload         8
     105: checkcast     #15                 // class java/lang/String
     108: astore        10
     110: istore        11
     112: astore        13
     114: iconst_0
     115: istore        12
     117: aload_1
     118: iload         11
     120: aload         10
     122: invokespecial #202                // Method toCoordinates:(ILjava/lang/String;)Ljava/util/List;
     125: aload         13
     127: swap
     128: invokeinterface #117,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     133: pop
     134: goto          65
     137: aload         4
     139: checkcast     #119                // class java/util/List
     142: nop
     143: checkcast     #60                 // class java/lang/Iterable
     146: invokestatic  #206                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     149: checkcast     #60                 // class java/lang/Iterable
     152: astore_0
     153: nop
     154: iconst_0
     155: istore_1
     156: aload_0
     157: bipush        10
     159: invokestatic  #68                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     162: invokestatic  #211                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     165: bipush        16
     167: invokestatic  #217                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     170: istore_2
     171: aload_0
     172: astore_3
     173: new           #219                // class java/util/LinkedHashMap
     176: dup
     177: iload_2
     178: invokespecial #220                // Method java/util/LinkedHashMap."<init>":(I)V
     181: checkcast     #149                // class java/util/Map
     184: astore        4
     186: iconst_0
     187: istore        5
     189: aload_3
     190: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     195: astore        6
     197: aload         6
     199: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     204: ifeq          255
     207: aload         6
     209: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     214: astore        7
     216: aload         4
     218: astore        8
     220: aload         7
     222: checkcast     #222                // class kotlin/Pair
     225: astore        9
     227: iconst_0
     228: istore        10
     230: aload         9
     232: astore        9
     234: aload         8
     236: aload         9
     238: invokevirtual #225                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     241: aload         9
     243: invokevirtual #228                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     246: invokeinterface #232,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     251: pop
     252: goto          197
     255: aload         4
     257: nop
     258: areturn

  public static final int access$step(Day11, java.util.Map);
    Code:
       0: aload_0
       1: aload_1
       2: invokespecial #247                // Method step:(Ljava/util/Map;)I
       5: ireturn

  static {};
    Code:
       0: new           #2                  // class Day11
       3: dup
       4: invokespecial #251                // Method "<init>":()V
       7: putstatic     #200                // Field INSTANCE:LDay11;
      10: invokedynamic #259,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function0;
      15: putstatic     #144                // Field octopusGrid:Lkotlin/jvm/functions/Function0;
      18: return
}

Compiled from "Day11.kt"
public final class Day11$Part2 {
  public static final Day11$Part2 INSTANCE;

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

  private final boolean isNotComplete(java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, Day11$Octopus>);
    Code:
       0: getstatic     #19                 // Field Day11.INSTANCE:LDay11;
       3: aload_1
       4: invokestatic  #23                 // Method Day11.access$step:(LDay11;Ljava/util/Map;)I
       7: istore_2
       8: iload_2
       9: aload_1
      10: invokeinterface #29,  1           // InterfaceMethod java/util/Map.size:()I
      15: if_icmpeq     22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ireturn

  public final void run();
    Code:
       0: getstatic     #19                 // Field Day11.INSTANCE:LDay11;
       3: invokevirtual #38                 // Method Day11.getOctopusGrid:()Lkotlin/jvm/functions/Function0;
       6: invokeinterface #44,  1           // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object;
      11: checkcast     #25                 // class java/util/Map
      14: astore_1
      15: iconst_0
      16: istore_2
      17: iinc          2, 1
      20: aload_0
      21: aload_1
      22: invokespecial #46                 // Method isNotComplete:(Ljava/util/Map;)Z
      25: ifne          17
      28: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: iload_2
      32: invokevirtual #58                 // Method java/io/PrintStream.println:(I)V
      35: return

  static {};
    Code:
       0: new           #2                  // class Day11$Part2
       3: dup
       4: invokespecial #62                 // Method "<init>":()V
       7: putstatic     #64                 // Field INSTANCE:LDay11$Part2;
      10: return
}

Compiled from "Day11.kt"
public final class Day11$Octopus {
  private kotlin.Pair<java.lang.Integer, java.lang.Integer> coord;

  private int score;

  private boolean hasFlashed;

  public Day11$Octopus(kotlin.Pair<java.lang.Integer, java.lang.Integer>, int, boolean);
    Code:
       0: aload_1
       1: ldc           #10                 // String coord
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #22                 // Field coord:Lkotlin/Pair;
      15: aload_0
      16: iload_2
      17: putfield      #26                 // Field score:I
      20: aload_0
      21: iload_3
      22: putfield      #30                 // Field hasFlashed:Z
      25: return

  public Day11$Octopus(kotlin.Pair, int, boolean, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         4
       2: iconst_4
       3: iand
       4: ifeq          9
       7: iconst_0
       8: istore_3
       9: aload_0
      10: aload_1
      11: iload_2
      12: iload_3
      13: invokespecial #35                 // Method "<init>":(Lkotlin/Pair;IZ)V
      16: return

  public final kotlin.Pair<java.lang.Integer, java.lang.Integer> getCoord();
    Code:
       0: aload_0
       1: getfield      #22                 // Field coord:Lkotlin/Pair;
       4: areturn

  public final void setCoord(kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #43                 // String <set-?>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: putfield      #22                 // Field coord:Lkotlin/Pair;
      11: return

  public final int getScore();
    Code:
       0: aload_0
       1: getfield      #26                 // Field score:I
       4: ireturn

  public final void setScore(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #26                 // Field score:I
       5: return

  public final boolean getHasFlashed();
    Code:
       0: aload_0
       1: getfield      #30                 // Field hasFlashed:Z
       4: ireturn

  public final void setHasFlashed(boolean);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #30                 // Field hasFlashed:Z
       5: return

  public final int increment();
    Code:
       0: aload_0
       1: getfield      #26                 // Field score:I
       4: istore_1
       5: aload_0
       6: iload_1
       7: iconst_1
       8: iadd
       9: putfield      #26                 // Field score:I
      12: iload_1
      13: ireturn

  private final boolean needsToFlash();
    Code:
       0: aload_0
       1: getfield      #26                 // Field score:I
       4: bipush        9
       6: if_icmple     20
       9: aload_0
      10: getfield      #30                 // Field hasFlashed:Z
      13: ifne          20
      16: iconst_1
      17: goto          21
      20: iconst_0
      21: ireturn

  private final void flash();
    Code:
       0: aload_0
       1: iconst_1
       2: putfield      #30                 // Field hasFlashed:Z
       5: return

  public final int reset();
    Code:
       0: aload_0
       1: getfield      #30                 // Field hasFlashed:Z
       4: ifeq          21
       7: aload_0
       8: iconst_0
       9: putfield      #30                 // Field hasFlashed:Z
      12: aload_0
      13: iconst_0
      14: putfield      #26                 // Field score:I
      17: iconst_1
      18: goto          22
      21: iconst_0
      22: ireturn

  private final kotlin.sequences.Sequence<Day11$Octopus> getNeighbours(java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, Day11$Octopus>, java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_2
       1: checkcast     #60                 // class java/lang/Iterable
       4: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
       7: aload_0
       8: invokedynamic #86,  0             // InvokeDynamic #0:invoke:(LDay11$Octopus;)Lkotlin/jvm/functions/Function1;
      13: invokestatic  #92                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      16: aload_1
      17: invokedynamic #102,  0            // InvokeDynamic #1:invoke:(Ljava/util/Map;)Lkotlin/jvm/functions/Function1;
      22: invokestatic  #105                // Method kotlin/sequences/SequencesKt.mapNotNull:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      25: areturn

  static kotlin.sequences.Sequence getNeighbours$default(Day11$Octopus, java.util.Map, java.util.List, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          141
       6: bipush        8
       8: anewarray     #113                // class kotlin/Pair
      11: astore        5
      13: aload         5
      15: iconst_0
      16: iconst_m1
      17: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      20: iconst_0
      21: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      24: invokestatic  #125                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      27: aastore
      28: aload         5
      30: iconst_1
      31: iconst_0
      32: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: iconst_m1
      36: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      39: invokestatic  #125                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      42: aastore
      43: aload         5
      45: iconst_2
      46: iconst_1
      47: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      50: iconst_0
      51: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: invokestatic  #125                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      57: aastore
      58: aload         5
      60: iconst_3
      61: iconst_0
      62: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: iconst_1
      66: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      69: invokestatic  #125                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      72: aastore
      73: aload         5
      75: iconst_4
      76: iconst_m1
      77: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: iconst_m1
      81: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      84: invokestatic  #125                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      87: aastore
      88: aload         5
      90: iconst_5
      91: iconst_1
      92: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      95: iconst_1
      96: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: invokestatic  #125                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     102: aastore
     103: aload         5
     105: bipush        6
     107: iconst_m1
     108: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     111: iconst_1
     112: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     115: invokestatic  #125                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     118: aastore
     119: aload         5
     121: bipush        7
     123: iconst_1
     124: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     127: iconst_m1
     128: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     131: invokestatic  #125                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     134: aastore
     135: aload         5
     137: invokestatic  #129                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     140: astore_2
     141: aload_0
     142: aload_1
     143: aload_2
     144: invokespecial #131                // Method getNeighbours:(Ljava/util/Map;Ljava/util/List;)Lkotlin/sequences/Sequence;
     147: areturn

  public final void check(java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, Day11$Octopus>);
    Code:
       0: aload_1
       1: ldc           #136                // String grid
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #138                // Method needsToFlash:()Z
      10: ifeq          82
      13: aload_0
      14: invokespecial #140                // Method flash:()V
      17: aload_0
      18: aload_1
      19: aconst_null
      20: iconst_2
      21: aconst_null
      22: invokestatic  #142                // Method getNeighbours$default:(LDay11$Octopus;Ljava/util/Map;Ljava/util/List;ILjava/lang/Object;)Lkotlin/sequences/Sequence;
      25: astore_2
      26: iconst_0
      27: istore_3
      28: aload_2
      29: invokeinterface #148,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      34: astore        4
      36: aload         4
      38: invokeinterface #153,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          81
      46: aload         4
      48: invokeinterface #157,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        5
      55: aload         5
      57: checkcast     #2                  // class Day11$Octopus
      60: astore        6
      62: iconst_0
      63: istore        7
      65: aload         6
      67: invokevirtual #159                // Method increment:()I
      70: pop
      71: aload         6
      73: aload_1
      74: invokevirtual #161                // Method check:(Ljava/util/Map;)V
      77: nop
      78: goto          36
      81: nop
      82: return

  public final kotlin.Pair<java.lang.Integer, java.lang.Integer> component1();
    Code:
       0: aload_0
       1: getfield      #22                 // Field coord:Lkotlin/Pair;
       4: areturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #26                 // Field score:I
       4: ireturn

  public final boolean component3();
    Code:
       0: aload_0
       1: getfield      #30                 // Field hasFlashed:Z
       4: ireturn

  public final Day11$Octopus copy(kotlin.Pair<java.lang.Integer, java.lang.Integer>, int, boolean);
    Code:
       0: aload_1
       1: ldc           #10                 // String coord
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class Day11$Octopus
       9: dup
      10: aload_1
      11: iload_2
      12: iload_3
      13: invokespecial #35                 // Method "<init>":(Lkotlin/Pair;IZ)V
      16: areturn

  public static Day11$Octopus copy$default(Day11$Octopus, kotlin.Pair, int, boolean, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #22                 // Field coord:Lkotlin/Pair;
      11: astore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #26                 // Field score:I
      23: istore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #30                 // Field hasFlashed:Z
      35: istore_3
      36: aload_0
      37: aload_1
      38: iload_2
      39: iload_3
      40: invokevirtual #178                // Method copy:(Lkotlin/Pair;IZ)LDay11$Octopus;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #182                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #183                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #185                // String Octopus(coord=
       9: invokevirtual #189                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #22                 // Field coord:Lkotlin/Pair;
      16: invokevirtual #192                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: ldc           #194                // String , score=
      21: invokevirtual #189                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #26                 // Field score:I
      28: invokevirtual #197                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #199                // String , hasFlashed=
      33: invokevirtual #189                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #30                 // Field hasFlashed:Z
      40: invokevirtual #202                // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #205                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #207                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #22                 // Field coord:Lkotlin/Pair;
       4: invokevirtual #210                // Method kotlin/Pair.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #26                 // Field score:I
      16: invokestatic  #213                // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #30                 // Field hasFlashed:Z
      29: invokestatic  #218                // Method java/lang/Boolean.hashCode:(Z)I
      32: iadd
      33: istore_1
      34: iload_1
      35: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class Day11$Octopus
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day11$Octopus
      20: astore_2
      21: aload_0
      22: getfield      #22                 // Field coord:Lkotlin/Pair;
      25: aload_2
      26: getfield      #22                 // Field coord:Lkotlin/Pair;
      29: invokestatic  #226                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #26                 // Field score:I
      41: aload_2
      42: getfield      #26                 // Field score:I
      45: if_icmpeq     50
      48: iconst_0
      49: ireturn
      50: aload_0
      51: getfield      #30                 // Field hasFlashed:Z
      54: aload_2
      55: getfield      #30                 // Field hasFlashed:Z
      58: if_icmpeq     63
      61: iconst_0
      62: ireturn
      63: iconst_1
      64: ireturn

  private static final kotlin.Pair getNeighbours$lambda$0(Day11$Octopus, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc           #229                // String <destruct>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokevirtual #231                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      10: checkcast     #233                // class java/lang/Number
      13: invokevirtual #236                // Method java/lang/Number.intValue:()I
      16: istore_2
      17: aload_1
      18: invokevirtual #238                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      21: checkcast     #233                // class java/lang/Number
      24: invokevirtual #236                // Method java/lang/Number.intValue:()I
      27: istore_3
      28: aload_0
      29: getfield      #22                 // Field coord:Lkotlin/Pair;
      32: invokevirtual #241                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      35: checkcast     #233                // class java/lang/Number
      38: invokevirtual #236                // Method java/lang/Number.intValue:()I
      41: iload_2
      42: iadd
      43: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      46: aload_0
      47: getfield      #22                 // Field coord:Lkotlin/Pair;
      50: invokevirtual #244                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      53: checkcast     #233                // class java/lang/Number
      56: invokevirtual #236                // Method java/lang/Number.intValue:()I
      59: iload_3
      60: iadd
      61: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      64: invokestatic  #125                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      67: areturn

  private static final Day11$Octopus getNeighbours$lambda$1(java.util.Map, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc           #248                // String it
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokeinterface #253,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      13: checkcast     #2                  // class Day11$Octopus
      16: areturn
}

Compiled from "Day11.kt"
public final class Day11Kt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field Day11$Part1.INSTANCE:LDay11$Part1;
       3: invokevirtual #15                 // Method Day11$Part1.run:()V
       6: getstatic     #20                 // Field Day11$Part2.INSTANCE:LDay11$Part2;
       9: invokevirtual #21                 // Method Day11$Part2.run:()V
      12: return

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