package day05

import java.io.File
import kotlin.math.min
import kotlin.math.max

fun main() {
    val data = parse("src/main/kotlin/day05/Day05.txt")

    val answer1 = part1(data)
    val answer2 = part2(data)

    println("🎄 Day 05 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

private data class Point(
    val x: Int,
    val y: Int,
)

private data class Line(
    val x1: Int,
    val y1: Int,
    val x2: Int,
    val y2: Int,
)

private fun parse(path: String): List<Line> =
    File(path)
        .readLines()
        .map(String::toLine)

private fun String.toLine(): Line {
    val regex = """(\d+),(\d+) -> (\d+),(\d+)""".toRegex()
    val (x1, y1, x2, y2) = regex.find(this)!!
        .destructured
        .toList()
        .map(String::toInt)

    return Line(x1, y1, x2, y2)
}

private fun part1(lines: List<Line>) =
    lines.asSequence()
        .flatMap { (x1, y1, x2, y2) ->
            if (y1 == y2) {
                (min(x1, x2)..max(x1, x2)).asSequence().map { x -> Point(x, y1) }
            } else if (x1 == x2) {
                (min(y1, y2)..max(y1, y2)).asSequence().map { y -> Point(x1, y) }
            } else {
                sequenceOf()
            }
        }
        .groupingBy { it }
        .eachCount()
        .count { (_, frequency) -> frequency >= 2 }

private fun part2(lines: List<Line>) =
    lines.asSequence()
        .flatMap { (x1, y1, x2, y2) ->
            if (y1 == y2) {
                (min(x1, x2)..max(x1, x2)).asSequence().map { x -> Point(x, y1) }
            } else if (x1 == x2) {
                (min(y1, y2)..max(y1, y2)).asSequence().map { y -> Point(x1, y) }
            } else {
                val xd = if (x2 > x1) 1 else -1
                val yd = if (y2 > y1) 1 else -1

                (0..(max(x1, x2) - min(x1, x2))).asSequence()
                    .map { delta -> Point(x1 + delta * xd, y1 + delta * yd) }
            }
        }
        .groupingBy { it }
        .eachCount()
        .count { (_, frequency) -> frequency >= 2 }

Compiled from "_Sequences.kt"
public final class day05.Day05Kt$part1$$inlined$groupingBy$1 implements kotlin.collections.Grouping<day05.Point, day05.Point> {
  final kotlin.sequences.Sequence $this_groupingBy;

  public day05.Day05Kt$part1$$inlined$groupingBy$1(kotlin.sequences.Sequence);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_groupingBy:Lkotlin/sequences/Sequence;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public java.util.Iterator<day05.Point> sourceIterator();
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_groupingBy:Lkotlin/sequences/Sequence;
       4: invokeinterface #32,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
       9: areturn

  public day05.Point keyOf(day05.Point);
    Code:
       0: aload_1
       1: checkcast     #37                 // class day05/Point
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: areturn
}

Compiled from "Day05.kt"
public final class day05.Day05Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day05/Day05.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method part1:(Ljava/util/List;)I
      10: istore_1
      11: aload_0
      12: invokestatic  #19                 // Method part2:(Ljava/util/List;)I
      15: istore_2
      16: ldc           #21                 // String 🎄 Day 05 🎄
      18: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      31: ldc           #37                 // String [Part 1]
      33: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: new           #39                 // class java/lang/StringBuilder
      43: dup
      44: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      47: ldc           #44                 // String Answer:
      49: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      52: iload_1
      53: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      56: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      59: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      72: ldc           #57                 // String [Part 2]
      74: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: new           #39                 // class java/lang/StringBuilder
      84: dup
      85: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      88: ldc           #44                 // String Answer:
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: iload_2
      94: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      97: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     100: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: swap
     104: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     107: return

  private static final java.util.List<day05.Line> parse(java.lang.String);
    Code:
       0: new           #65                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #68                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #74                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: checkcast     #76                 // class java/lang/Iterable
      17: astore_1
      18: nop
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #78                 // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #87                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #89                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          102
      62: aload         6
      64: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         4
      73: aload         7
      75: checkcast     #105                // class java/lang/String
      78: astore        8
      80: astore        10
      82: iconst_0
      83: istore        9
      85: aload         8
      87: invokestatic  #109                // Method toLine:(Ljava/lang/String;)Lday05/Line;
      90: aload         10
      92: swap
      93: invokeinterface #113,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      98: pop
      99: goto          52
     102: aload         4
     104: checkcast     #115                // class java/util/List
     107: nop
     108: areturn

  private static final day05.Line toLine(java.lang.String);
    Code:
       0: new           #130                // class kotlin/text/Regex
       3: dup
       4: ldc           #132                // String (\\d+),(\\d+) -> (\\d+),(\\d+)
       6: invokespecial #133                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: astore_1
      10: aload_1
      11: aload_0
      12: checkcast     #135                // class java/lang/CharSequence
      15: iconst_0
      16: iconst_2
      17: aconst_null
      18: invokestatic  #139                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      21: dup
      22: invokestatic  #144                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      25: invokeinterface #150,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      30: invokevirtual #156                // Method kotlin/text/MatchResult$Destructured.toList:()Ljava/util/List;
      33: checkcast     #76                 // class java/lang/Iterable
      36: astore_3
      37: nop
      38: iconst_0
      39: istore        4
      41: aload_3
      42: astore        5
      44: new           #78                 // class java/util/ArrayList
      47: dup
      48: aload_3
      49: bipush        10
      51: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      54: invokespecial #87                 // Method java/util/ArrayList."<init>":(I)V
      57: checkcast     #89                 // class java/util/Collection
      60: astore        6
      62: iconst_0
      63: istore        7
      65: aload         5
      67: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      72: astore        8
      74: aload         8
      76: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      81: ifeq          128
      84: aload         8
      86: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      91: astore        9
      93: aload         6
      95: aload         9
      97: checkcast     #105                // class java/lang/String
     100: astore        10
     102: astore        12
     104: iconst_0
     105: istore        11
     107: aload         10
     109: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     112: nop
     113: invokestatic  #166                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     116: aload         12
     118: swap
     119: invokeinterface #113,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     124: pop
     125: goto          74
     128: aload         6
     130: checkcast     #115                // class java/util/List
     133: nop
     134: astore_2
     135: aload_2
     136: iconst_0
     137: invokeinterface #170,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     142: checkcast     #172                // class java/lang/Number
     145: invokevirtual #176                // Method java/lang/Number.intValue:()I
     148: istore_3
     149: aload_2
     150: iconst_1
     151: invokeinterface #170,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     156: checkcast     #172                // class java/lang/Number
     159: invokevirtual #176                // Method java/lang/Number.intValue:()I
     162: istore        4
     164: aload_2
     165: iconst_2
     166: invokeinterface #170,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     171: checkcast     #172                // class java/lang/Number
     174: invokevirtual #176                // Method java/lang/Number.intValue:()I
     177: istore        5
     179: aload_2
     180: iconst_3
     181: invokeinterface #170,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: checkcast     #172                // class java/lang/Number
     189: invokevirtual #176                // Method java/lang/Number.intValue:()I
     192: istore        6
     194: new           #178                // class day05/Line
     197: dup
     198: iload_3
     199: iload         4
     201: iload         5
     203: iload         6
     205: invokespecial #181                // Method day05/Line."<init>":(IIII)V
     208: areturn

  private static final int part1(java.util.List<day05.Line>);
    Code:
       0: aload_0
       1: checkcast     #76                 // class java/lang/Iterable
       4: invokestatic  #194                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
       7: invokedynamic #213,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      12: invokestatic  #219                // Method kotlin/sequences/SequencesKt.flatMap:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      15: astore_1
      16: nop
      17: iconst_0
      18: istore_2
      19: new           #221                // class day05/Day05Kt$part1$$inlined$groupingBy$1
      22: dup
      23: aload_1
      24: invokespecial #224                // Method day05/Day05Kt$part1$$inlined$groupingBy$1."<init>":(Lkotlin/sequences/Sequence;)V
      27: checkcast     #226                // class kotlin/collections/Grouping
      30: invokestatic  #232                // Method kotlin/collections/GroupingKt.eachCount:(Lkotlin/collections/Grouping;)Ljava/util/Map;
      33: astore_1
      34: nop
      35: iconst_0
      36: istore_2
      37: aload_1
      38: invokeinterface #237,  1          // InterfaceMethod java/util/Map.isEmpty:()Z
      43: ifeq          50
      46: iconst_0
      47: goto          130
      50: iconst_0
      51: istore_3
      52: aload_1
      53: invokeinterface #241,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      58: invokeinterface #244,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      63: astore        4
      65: aload         4
      67: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          129
      75: aload         4
      77: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: checkcast     #246                // class java/util/Map$Entry
      85: astore        5
      87: aload         5
      89: astore        6
      91: iconst_0
      92: istore        7
      94: aload         6
      96: invokeinterface #249,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     101: checkcast     #172                // class java/lang/Number
     104: invokevirtual #176                // Method java/lang/Number.intValue:()I
     107: istore        8
     109: iload         8
     111: iconst_2
     112: if_icmplt     119
     115: iconst_1
     116: goto          120
     119: iconst_0
     120: ifeq          65
     123: iinc          3, 1
     126: goto          65
     129: iload_3
     130: ireturn

  private static final int part2(java.util.List<day05.Line>);
    Code:
       0: aload_0
       1: checkcast     #76                 // class java/lang/Iterable
       4: invokestatic  #194                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
       7: invokedynamic #266,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      12: invokestatic  #219                // Method kotlin/sequences/SequencesKt.flatMap:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      15: astore_1
      16: nop
      17: iconst_0
      18: istore_2
      19: new           #268                // class day05/Day05Kt$part2$$inlined$groupingBy$1
      22: dup
      23: aload_1
      24: invokespecial #269                // Method day05/Day05Kt$part2$$inlined$groupingBy$1."<init>":(Lkotlin/sequences/Sequence;)V
      27: checkcast     #226                // class kotlin/collections/Grouping
      30: invokestatic  #232                // Method kotlin/collections/GroupingKt.eachCount:(Lkotlin/collections/Grouping;)Ljava/util/Map;
      33: astore_1
      34: nop
      35: iconst_0
      36: istore_2
      37: aload_1
      38: invokeinterface #237,  1          // InterfaceMethod java/util/Map.isEmpty:()Z
      43: ifeq          50
      46: iconst_0
      47: goto          130
      50: iconst_0
      51: istore_3
      52: aload_1
      53: invokeinterface #241,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      58: invokeinterface #244,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      63: astore        4
      65: aload         4
      67: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          129
      75: aload         4
      77: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: checkcast     #246                // class java/util/Map$Entry
      85: astore        5
      87: aload         5
      89: astore        6
      91: iconst_0
      92: istore        7
      94: aload         6
      96: invokeinterface #249,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     101: checkcast     #172                // class java/lang/Number
     104: invokevirtual #176                // Method java/lang/Number.intValue:()I
     107: istore        8
     109: iload         8
     111: iconst_2
     112: if_icmplt     119
     115: iconst_1
     116: goto          120
     119: iconst_0
     120: ifeq          65
     123: iinc          3, 1
     126: goto          65
     129: iload_3
     130: ireturn

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

  private static final day05.Point part1$lambda$3$lambda$1(int, int);
    Code:
       0: new           #279                // class day05/Point
       3: dup
       4: iload_1
       5: iload_0
       6: invokespecial #282                // Method day05/Point."<init>":(II)V
       9: areturn

  private static final day05.Point part1$lambda$3$lambda$2(int, int);
    Code:
       0: new           #279                // class day05/Point
       3: dup
       4: iload_0
       5: iload_1
       6: invokespecial #282                // Method day05/Point."<init>":(II)V
       9: areturn

  private static final kotlin.sequences.Sequence part1$lambda$3(day05.Line);
    Code:
       0: aload_0
       1: ldc_w         #289                // String <destruct>
       4: invokestatic  #293                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #296                // Method day05/Line.component1:()I
      11: istore_1
      12: aload_0
      13: invokevirtual #299                // Method day05/Line.component2:()I
      16: istore_2
      17: aload_0
      18: invokevirtual #302                // Method day05/Line.component3:()I
      21: istore_3
      22: aload_0
      23: invokevirtual #305                // Method day05/Line.component4:()I
      26: istore        4
      28: iload_2
      29: iload         4
      31: if_icmpne     69
      34: new           #307                // class kotlin/ranges/IntRange
      37: dup
      38: iload_1
      39: iload_3
      40: invokestatic  #313                // Method java/lang/Math.min:(II)I
      43: iload_1
      44: iload_3
      45: invokestatic  #316                // Method java/lang/Math.max:(II)I
      48: invokespecial #317                // Method kotlin/ranges/IntRange."<init>":(II)V
      51: checkcast     #76                 // class java/lang/Iterable
      54: invokestatic  #194                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      57: iload_2
      58: invokedynamic #325,  0            // InvokeDynamic #2:invoke:(I)Lkotlin/jvm/functions/Function1;
      63: invokestatic  #328                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      66: goto          118
      69: iload_1
      70: iload_3
      71: if_icmpne     111
      74: new           #307                // class kotlin/ranges/IntRange
      77: dup
      78: iload_2
      79: iload         4
      81: invokestatic  #313                // Method java/lang/Math.min:(II)I
      84: iload_2
      85: iload         4
      87: invokestatic  #316                // Method java/lang/Math.max:(II)I
      90: invokespecial #317                // Method kotlin/ranges/IntRange."<init>":(II)V
      93: checkcast     #76                 // class java/lang/Iterable
      96: invokestatic  #194                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      99: iload_1
     100: invokedynamic #332,  0            // InvokeDynamic #3:invoke:(I)Lkotlin/jvm/functions/Function1;
     105: invokestatic  #328                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     108: goto          118
     111: iconst_0
     112: anewarray     #279                // class day05/Point
     115: invokestatic  #336                // Method kotlin/sequences/SequencesKt.sequenceOf:([Ljava/lang/Object;)Lkotlin/sequences/Sequence;
     118: areturn

  private static final day05.Point part2$lambda$9$lambda$6(int, int);
    Code:
       0: new           #279                // class day05/Point
       3: dup
       4: iload_1
       5: iload_0
       6: invokespecial #282                // Method day05/Point."<init>":(II)V
       9: areturn

  private static final day05.Point part2$lambda$9$lambda$7(int, int);
    Code:
       0: new           #279                // class day05/Point
       3: dup
       4: iload_0
       5: iload_1
       6: invokespecial #282                // Method day05/Point."<init>":(II)V
       9: areturn

  private static final day05.Point part2$lambda$9$lambda$8(int, int, int, int, int);
    Code:
       0: new           #279                // class day05/Point
       3: dup
       4: iload_0
       5: iload         4
       7: iload_1
       8: imul
       9: iadd
      10: iload_2
      11: iload         4
      13: iload_3
      14: imul
      15: iadd
      16: invokespecial #282                // Method day05/Point."<init>":(II)V
      19: areturn

  private static final kotlin.sequences.Sequence part2$lambda$9(day05.Line);
    Code:
       0: aload_0
       1: ldc_w         #289                // String <destruct>
       4: invokestatic  #293                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #296                // Method day05/Line.component1:()I
      11: istore_1
      12: aload_0
      13: invokevirtual #299                // Method day05/Line.component2:()I
      16: istore_2
      17: aload_0
      18: invokevirtual #302                // Method day05/Line.component3:()I
      21: istore_3
      22: aload_0
      23: invokevirtual #305                // Method day05/Line.component4:()I
      26: istore        4
      28: iload_2
      29: iload         4
      31: if_icmpne     69
      34: new           #307                // class kotlin/ranges/IntRange
      37: dup
      38: iload_1
      39: iload_3
      40: invokestatic  #313                // Method java/lang/Math.min:(II)I
      43: iload_1
      44: iload_3
      45: invokestatic  #316                // Method java/lang/Math.max:(II)I
      48: invokespecial #317                // Method kotlin/ranges/IntRange."<init>":(II)V
      51: checkcast     #76                 // class java/lang/Iterable
      54: invokestatic  #194                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      57: iload_2
      58: invokedynamic #349,  0            // InvokeDynamic #4:invoke:(I)Lkotlin/jvm/functions/Function1;
      63: invokestatic  #328                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      66: goto          175
      69: iload_1
      70: iload_3
      71: if_icmpne     111
      74: new           #307                // class kotlin/ranges/IntRange
      77: dup
      78: iload_2
      79: iload         4
      81: invokestatic  #313                // Method java/lang/Math.min:(II)I
      84: iload_2
      85: iload         4
      87: invokestatic  #316                // Method java/lang/Math.max:(II)I
      90: invokespecial #317                // Method kotlin/ranges/IntRange."<init>":(II)V
      93: checkcast     #76                 // class java/lang/Iterable
      96: invokestatic  #194                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      99: iload_1
     100: invokedynamic #353,  0            // InvokeDynamic #5:invoke:(I)Lkotlin/jvm/functions/Function1;
     105: invokestatic  #328                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     108: goto          175
     111: iload_3
     112: iload_1
     113: if_icmple     120
     116: iconst_1
     117: goto          121
     120: iconst_m1
     121: istore        5
     123: iload         4
     125: iload_2
     126: if_icmple     133
     129: iconst_1
     130: goto          134
     133: iconst_m1
     134: istore        6
     136: new           #307                // class kotlin/ranges/IntRange
     139: dup
     140: iconst_0
     141: iload_1
     142: iload_3
     143: invokestatic  #316                // Method java/lang/Math.max:(II)I
     146: iload_1
     147: iload_3
     148: invokestatic  #313                // Method java/lang/Math.min:(II)I
     151: isub
     152: invokespecial #317                // Method kotlin/ranges/IntRange."<init>":(II)V
     155: checkcast     #76                 // class java/lang/Iterable
     158: invokestatic  #194                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     161: iload_1
     162: iload         5
     164: iload_2
     165: iload         6
     167: invokedynamic #359,  0            // InvokeDynamic #6:invoke:(IIII)Lkotlin/jvm/functions/Function1;
     172: invokestatic  #328                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     175: areturn
}

Compiled from "_Sequences.kt"
public final class day05.Day05Kt$part2$$inlined$groupingBy$1 implements kotlin.collections.Grouping<day05.Point, day05.Point> {
  final kotlin.sequences.Sequence $this_groupingBy;

  public day05.Day05Kt$part2$$inlined$groupingBy$1(kotlin.sequences.Sequence);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_groupingBy:Lkotlin/sequences/Sequence;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public java.util.Iterator<day05.Point> sourceIterator();
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_groupingBy:Lkotlin/sequences/Sequence;
       4: invokeinterface #32,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
       9: areturn

  public day05.Point keyOf(day05.Point);
    Code:
       0: aload_1
       1: checkcast     #37                 // class day05/Point
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: areturn
}


package day20

import java.io.File

fun main() {
    val data = parse("src/main/kotlin/day20/Day20.txt")

    val answer1 = part1(data)
    val answer2 = part2(data)

    println("🎄 Day 20 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

private fun parse(path: String): Enhance {
    val (algorithm, bits) = File(path)
        .readText()
        .trim()
        .split("""(\n\n)|(\r\n\r\n)""".toRegex())

    return Enhance(bits.toImage(), algorithm)
}

private fun String.toImage(): Image =
    this.lines()
        .let { lines -> lines.joinToString(separator = "") to lines.size }
        .let { (bitmap, size) -> Image(bitmap, size) }

private data class Enhance(
    val image: Image,
    val algorithm: String,
)

private data class Image(
    val bitmap: String,
    val size: Int,
    val fill: Char = '.',
)

private fun <T> Iterable<T>.cross(other: Iterable<T>): List<Pair<T, T>> =
    this.flatMap { a -> other.map { b -> a to b } }

private operator fun Image.get(x: Int, y: Int): Char =
    if (x in 0 until size && y in 0 until size) {
        bitmap[y * size + x]
    } else {
        fill
    }

private fun Image.adjacent(x: Int, y: Int): List<Char> =
    (-1..1).cross(-1..1)
        .map { (dy, dx) -> this[x + dx, y + dy] }

private fun Image.indexAt(x: Int, y: Int): Int =
    this.adjacent(x, y)
        .fold(0) { acc, c -> acc shl 1 or if (c == '#') 1 else 0 }

private fun Enhance.step(): Enhance {
    // After each iteration, the image expands one unit in each direction,
    // increasing the length of its sides by 2 in total.
    val size = image.size + 2
    val side = -1 until image.size + 1
    val bitmap = (side).cross(side)
        .map { (y, x) -> image.indexAt(x, y) }
        .map { index -> algorithm[index] }
        .joinToString(separator = "")

    val fill = if (image.fill == '.') {
        algorithm.first()
    } else {
        algorithm.last()
    }

    return this.copy(image = Image(bitmap, size, fill))
}

private fun Enhance.perform(iterations: Int): Image =
    generateSequence(this) { p -> p.step() }
        .elementAt(iterations).image

private fun Enhance.countAfter(iterations: Int): Int =
    perform(iterations)
        .bitmap.count { pixel -> pixel == '#' }

private fun part1(enhance: Enhance): Int =
    enhance.countAfter(iterations = 2)

private fun part2(enhance: Enhance): Int =
    enhance.countAfter(iterations = 50)

Compiled from "Day20.kt"
public final class day20.Day20Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day20/Day20.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Lday20/Enhance;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method part1:(Lday20/Enhance;)I
      10: istore_1
      11: aload_0
      12: invokestatic  #19                 // Method part2:(Lday20/Enhance;)I
      15: istore_2
      16: ldc           #21                 // String 🎄 Day 20 🎄
      18: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      31: ldc           #37                 // String [Part 1]
      33: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: new           #39                 // class java/lang/StringBuilder
      43: dup
      44: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      47: ldc           #44                 // String Answer:
      49: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      52: iload_1
      53: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      56: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      59: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      72: ldc           #57                 // String [Part 2]
      74: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: new           #39                 // class java/lang/StringBuilder
      84: dup
      85: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      88: ldc           #44                 // String Answer:
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: iload_2
      94: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      97: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     100: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: swap
     104: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     107: return

  private static final day20.Enhance parse(java.lang.String);
    Code:
       0: nop
       1: new           #64                 // class java/io/File
       4: dup
       5: aload_0
       6: invokespecial #67                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #73                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: checkcast     #75                 // class java/lang/CharSequence
      18: invokestatic  #81                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      21: invokevirtual #82                 // Method java/lang/Object.toString:()Ljava/lang/String;
      24: checkcast     #75                 // class java/lang/CharSequence
      27: astore_2
      28: new           #84                 // class kotlin/text/Regex
      31: dup
      32: ldc           #86                 // String (\\n\\n)|(\\r\\n\\r\\n)
      34: invokespecial #87                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      37: astore_3
      38: iconst_0
      39: istore        4
      41: aload_3
      42: aload_2
      43: iload         4
      45: invokevirtual #91                 // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      48: astore_1
      49: aload_1
      50: iconst_0
      51: invokeinterface #97,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      56: checkcast     #99                 // class java/lang/String
      59: astore_2
      60: aload_1
      61: iconst_1
      62: invokeinterface #97,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #99                 // class java/lang/String
      70: astore_3
      71: new           #101                // class day20/Enhance
      74: dup
      75: aload_3
      76: invokestatic  #105                // Method toImage:(Ljava/lang/String;)Lday20/Image;
      79: aload_2
      80: invokespecial #108                // Method day20/Enhance."<init>":(Lday20/Image;Ljava/lang/String;)V
      83: areturn

  private static final day20.Image toImage(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #75                 // class java/lang/CharSequence
       4: invokestatic  #116                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: checkcast     #118                // class java/lang/Iterable
      14: ldc           #120                // String
      16: checkcast     #75                 // class java/lang/CharSequence
      19: aconst_null
      20: aconst_null
      21: iconst_0
      22: aconst_null
      23: aconst_null
      24: bipush        62
      26: aconst_null
      27: invokestatic  #126                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      30: aload_1
      31: invokeinterface #130,  1          // InterfaceMethod java/util/List.size:()I
      36: invokestatic  #136                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      39: invokestatic  #142                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      42: nop
      43: astore_1
      44: iconst_0
      45: istore_2
      46: aload_1
      47: invokevirtual #148                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      50: checkcast     #99                 // class java/lang/String
      53: astore_3
      54: aload_1
      55: invokevirtual #151                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      58: checkcast     #153                // class java/lang/Number
      61: invokevirtual #156                // Method java/lang/Number.intValue:()I
      64: istore        4
      66: new           #158                // class day20/Image
      69: dup
      70: aload_3
      71: iload         4
      73: iconst_0
      74: iconst_4
      75: aconst_null
      76: invokespecial #161                // Method day20/Image."<init>":(Ljava/lang/String;ICILkotlin/jvm/internal/DefaultConstructorMarker;)V
      79: nop
      80: areturn

  private static final <T> java.util.List<kotlin.Pair<T, T>> cross(java.lang.Iterable<? extends T>, java.lang.Iterable<? extends T>);
    Code:
       0: aload_0
       1: astore_2
       2: iconst_0
       3: istore_3
       4: aload_2
       5: astore        4
       7: new           #171                // class java/util/ArrayList
      10: dup
      11: invokespecial #172                // Method java/util/ArrayList."<init>":()V
      14: checkcast     #174                // class java/util/Collection
      17: astore        5
      19: iconst_0
      20: istore        6
      22: aload         4
      24: invokeinterface #178,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      29: astore        7
      31: aload         7
      33: invokeinterface #184,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      38: ifeq          170
      41: aload         7
      43: invokeinterface #187,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      48: astore        8
      50: aload         8
      52: astore        9
      54: iconst_0
      55: istore        10
      57: aload_1
      58: astore        11
      60: iconst_0
      61: istore        12
      63: aload         11
      65: astore        13
      67: new           #171                // class java/util/ArrayList
      70: dup
      71: aload         11
      73: bipush        10
      75: invokestatic  #191                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      78: invokespecial #194                // Method java/util/ArrayList."<init>":(I)V
      81: checkcast     #174                // class java/util/Collection
      84: astore        14
      86: iconst_0
      87: istore        15
      89: aload         13
      91: invokeinterface #178,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      96: astore        16
      98: aload         16
     100: invokeinterface #184,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     105: ifeq          147
     108: aload         16
     110: invokeinterface #187,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     115: astore        17
     117: aload         14
     119: aload         17
     121: astore        18
     123: astore        19
     125: iconst_0
     126: istore        20
     128: aload         9
     130: aload         18
     132: invokestatic  #142                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     135: aload         19
     137: swap
     138: invokeinterface #198,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     143: pop
     144: goto          98
     147: aload         14
     149: checkcast     #93                 // class java/util/List
     152: nop
     153: checkcast     #118                // class java/lang/Iterable
     156: nop
     157: astore        9
     159: aload         5
     161: aload         9
     163: invokestatic  #202                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     166: pop
     167: goto          31
     170: aload         5
     172: checkcast     #93                 // class java/util/List
     175: nop
     176: areturn

  private static final char get(day20.Image, int, int);
    Code:
       0: aload_0
       1: ldc           #226                // String <this>
       3: invokestatic  #232                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: iload_1
       8: if_icmpgt     27
      11: iload_1
      12: aload_0
      13: invokevirtual #235                // Method day20/Image.getSize:()I
      16: if_icmpge     23
      19: iconst_1
      20: goto          28
      23: iconst_0
      24: goto          28
      27: iconst_0
      28: ifeq          74
      31: iconst_0
      32: iload_2
      33: if_icmpgt     52
      36: iload_2
      37: aload_0
      38: invokevirtual #235                // Method day20/Image.getSize:()I
      41: if_icmpge     48
      44: iconst_1
      45: goto          53
      48: iconst_0
      49: goto          53
      52: iconst_0
      53: ifeq          74
      56: aload_0
      57: invokevirtual #238                // Method day20/Image.getBitmap:()Ljava/lang/String;
      60: iload_2
      61: aload_0
      62: invokevirtual #235                // Method day20/Image.getSize:()I
      65: imul
      66: iload_1
      67: iadd
      68: invokevirtual #242                // Method java/lang/String.charAt:(I)C
      71: goto          78
      74: aload_0
      75: invokevirtual #246                // Method day20/Image.getFill:()C
      78: ireturn

  private static final java.util.List<java.lang.Character> adjacent(day20.Image, int, int);
    Code:
       0: new           #255                // class kotlin/ranges/IntRange
       3: dup
       4: iconst_m1
       5: iconst_1
       6: invokespecial #258                // Method kotlin/ranges/IntRange."<init>":(II)V
       9: checkcast     #118                // class java/lang/Iterable
      12: new           #255                // class kotlin/ranges/IntRange
      15: dup
      16: iconst_m1
      17: iconst_1
      18: invokespecial #258                // Method kotlin/ranges/IntRange."<init>":(II)V
      21: checkcast     #118                // class java/lang/Iterable
      24: invokestatic  #260                // Method cross:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
      27: checkcast     #118                // class java/lang/Iterable
      30: astore_3
      31: nop
      32: iconst_0
      33: istore        4
      35: aload_3
      36: astore        5
      38: new           #171                // class java/util/ArrayList
      41: dup
      42: aload_3
      43: bipush        10
      45: invokestatic  #191                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      48: invokespecial #194                // Method java/util/ArrayList."<init>":(I)V
      51: checkcast     #174                // class java/util/Collection
      54: astore        6
      56: iconst_0
      57: istore        7
      59: aload         5
      61: invokeinterface #178,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      66: astore        8
      68: aload         8
      70: invokeinterface #184,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      75: ifeq          154
      78: aload         8
      80: invokeinterface #187,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      85: astore        9
      87: aload         6
      89: aload         9
      91: checkcast     #144                // class kotlin/Pair
      94: astore        10
      96: astore        14
      98: iconst_0
      99: istore        11
     101: aload         10
     103: invokevirtual #148                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     106: checkcast     #153                // class java/lang/Number
     109: invokevirtual #156                // Method java/lang/Number.intValue:()I
     112: istore        12
     114: aload         10
     116: invokevirtual #151                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     119: checkcast     #153                // class java/lang/Number
     122: invokevirtual #156                // Method java/lang/Number.intValue:()I
     125: istore        13
     127: aload_0
     128: iload_1
     129: iload         13
     131: iadd
     132: iload_2
     133: iload         12
     135: iadd
     136: invokestatic  #262                // Method get:(Lday20/Image;II)C
     139: invokestatic  #267                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     142: aload         14
     144: swap
     145: invokeinterface #198,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     150: pop
     151: goto          68
     154: aload         6
     156: checkcast     #93                 // class java/util/List
     159: nop
     160: areturn

  private static final int indexAt(day20.Image, int, int);
    Code:
       0: aload_0
       1: iload_1
       2: iload_2
       3: invokestatic  #275                // Method adjacent:(Lday20/Image;II)Ljava/util/List;
       6: checkcast     #118                // class java/lang/Iterable
       9: astore_3
      10: iconst_0
      11: istore        4
      13: iconst_0
      14: istore        5
      16: iload         4
      18: istore        6
      20: aload_3
      21: invokeinterface #178,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      26: astore        7
      28: aload         7
      30: invokeinterface #184,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      35: ifeq          86
      38: aload         7
      40: invokeinterface #187,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      45: astore        8
      47: iload         6
      49: aload         8
      51: checkcast     #264                // class java/lang/Character
      54: invokevirtual #278                // Method java/lang/Character.charValue:()C
      57: istore        9
      59: istore        10
      61: iconst_0
      62: istore        11
      64: iload         10
      66: iconst_1
      67: ishl
      68: iload         9
      70: bipush        35
      72: if_icmpne     79
      75: iconst_1
      76: goto          80
      79: iconst_0
      80: ior
      81: istore        6
      83: goto          28
      86: iload         6
      88: ireturn

  private static final day20.Enhance step(day20.Enhance);
    Code:
       0: aload_0
       1: invokevirtual #294                // Method day20/Enhance.getImage:()Lday20/Image;
       4: invokevirtual #235                // Method day20/Image.getSize:()I
       7: iconst_2
       8: iadd
       9: istore_1
      10: iconst_m1
      11: aload_0
      12: invokevirtual #294                // Method day20/Enhance.getImage:()Lday20/Image;
      15: invokevirtual #235                // Method day20/Image.getSize:()I
      18: iconst_1
      19: iadd
      20: invokestatic  #300                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      23: astore_2
      24: aload_2
      25: checkcast     #118                // class java/lang/Iterable
      28: aload_2
      29: checkcast     #118                // class java/lang/Iterable
      32: invokestatic  #260                // Method cross:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
      35: checkcast     #118                // class java/lang/Iterable
      38: astore        4
      40: nop
      41: iconst_0
      42: istore        5
      44: aload         4
      46: astore        6
      48: new           #171                // class java/util/ArrayList
      51: dup
      52: aload         4
      54: bipush        10
      56: invokestatic  #191                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      59: invokespecial #194                // Method java/util/ArrayList."<init>":(I)V
      62: checkcast     #174                // class java/util/Collection
      65: astore        7
      67: iconst_0
      68: istore        8
      70: aload         6
      72: invokeinterface #178,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      77: astore        9
      79: aload         9
      81: invokeinterface #184,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      86: ifeq          164
      89: aload         9
      91: invokeinterface #187,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      96: astore        10
      98: aload         7
     100: aload         10
     102: checkcast     #144                // class kotlin/Pair
     105: astore        11
     107: astore        15
     109: iconst_0
     110: istore        12
     112: aload         11
     114: invokevirtual #148                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     117: checkcast     #153                // class java/lang/Number
     120: invokevirtual #156                // Method java/lang/Number.intValue:()I
     123: istore        13
     125: aload         11
     127: invokevirtual #151                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     130: checkcast     #153                // class java/lang/Number
     133: invokevirtual #156                // Method java/lang/Number.intValue:()I
     136: istore        14
     138: aload_0
     139: invokevirtual #294                // Method day20/Enhance.getImage:()Lday20/Image;
     142: iload         14
     144: iload         13
     146: invokestatic  #302                // Method indexAt:(Lday20/Image;II)I
     149: invokestatic  #136                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     152: aload         15
     154: swap
     155: invokeinterface #198,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     160: pop
     161: goto          79
     164: aload         7
     166: checkcast     #93                 // class java/util/List
     169: nop
     170: checkcast     #118                // class java/lang/Iterable
     173: astore        4
     175: nop
     176: iconst_0
     177: istore        5
     179: aload         4
     181: astore        6
     183: new           #171                // class java/util/ArrayList
     186: dup
     187: aload         4
     189: bipush        10
     191: invokestatic  #191                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     194: invokespecial #194                // Method java/util/ArrayList."<init>":(I)V
     197: checkcast     #174                // class java/util/Collection
     200: astore        7
     202: iconst_0
     203: istore        8
     205: aload         6
     207: invokeinterface #178,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     212: astore        9
     214: aload         9
     216: invokeinterface #184,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     221: ifeq          274
     224: aload         9
     226: invokeinterface #187,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     231: astore        10
     233: aload         7
     235: aload         10
     237: checkcast     #153                // class java/lang/Number
     240: invokevirtual #156                // Method java/lang/Number.intValue:()I
     243: istore        11
     245: astore        15
     247: iconst_0
     248: istore        12
     250: aload_0
     251: invokevirtual #305                // Method day20/Enhance.getAlgorithm:()Ljava/lang/String;
     254: iload         11
     256: invokevirtual #242                // Method java/lang/String.charAt:(I)C
     259: invokestatic  #267                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     262: aload         15
     264: swap
     265: invokeinterface #198,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     270: pop
     271: goto          214
     274: aload         7
     276: checkcast     #93                 // class java/util/List
     279: nop
     280: checkcast     #118                // class java/lang/Iterable
     283: ldc           #120                // String
     285: checkcast     #75                 // class java/lang/CharSequence
     288: aconst_null
     289: aconst_null
     290: iconst_0
     291: aconst_null
     292: aconst_null
     293: bipush        62
     295: aconst_null
     296: invokestatic  #126                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     299: astore_3
     300: aload_0
     301: invokevirtual #294                // Method day20/Enhance.getImage:()Lday20/Image;
     304: invokevirtual #246                // Method day20/Image.getFill:()C
     307: bipush        46
     309: if_icmpne     325
     312: aload_0
     313: invokevirtual #305                // Method day20/Enhance.getAlgorithm:()Ljava/lang/String;
     316: checkcast     #75                 // class java/lang/CharSequence
     319: invokestatic  #309                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     322: goto          335
     325: aload_0
     326: invokevirtual #305                // Method day20/Enhance.getAlgorithm:()Ljava/lang/String;
     329: checkcast     #75                 // class java/lang/CharSequence
     332: invokestatic  #312                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     335: istore        4
     337: aload_0
     338: new           #158                // class day20/Image
     341: dup
     342: aload_3
     343: iload_1
     344: iload         4
     346: invokespecial #315                // Method day20/Image."<init>":(Ljava/lang/String;IC)V
     349: aconst_null
     350: iconst_2
     351: aconst_null
     352: invokestatic  #319                // Method day20/Enhance.copy$default:(Lday20/Enhance;Lday20/Image;Ljava/lang/String;ILjava/lang/Object;)Lday20/Enhance;
     355: areturn

  private static final day20.Image perform(day20.Enhance, int);
    Code:
       0: aload_0
       1: invokedynamic #346,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
       6: invokestatic  #352                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
       9: iload_1
      10: invokestatic  #356                // Method kotlin/sequences/SequencesKt.elementAt:(Lkotlin/sequences/Sequence;I)Ljava/lang/Object;
      13: checkcast     #101                // class day20/Enhance
      16: invokevirtual #294                // Method day20/Enhance.getImage:()Lday20/Image;
      19: areturn

  private static final int countAfter(day20.Enhance, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokestatic  #362                // Method perform:(Lday20/Enhance;I)Lday20/Image;
       5: invokevirtual #238                // Method day20/Image.getBitmap:()Ljava/lang/String;
       8: checkcast     #75                 // class java/lang/CharSequence
      11: astore_2
      12: iconst_0
      13: istore_3
      14: iconst_0
      15: istore        4
      17: iconst_0
      18: istore        5
      20: iload         5
      22: aload_2
      23: invokeinterface #365,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      28: if_icmpge     72
      31: aload_2
      32: iload         5
      34: invokeinterface #366,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      39: istore        6
      41: iload         6
      43: istore        7
      45: iconst_0
      46: istore        8
      48: iload         7
      50: bipush        35
      52: if_icmpne     59
      55: iconst_1
      56: goto          60
      59: iconst_0
      60: ifeq          66
      63: iinc          4, 1
      66: iinc          5, 1
      69: goto          20
      72: iload         4
      74: ireturn

  private static final int part1(day20.Enhance);
    Code:
       0: aload_0
       1: iconst_2
       2: invokestatic  #375                // Method countAfter:(Lday20/Enhance;I)I
       5: ireturn

  private static final int part2(day20.Enhance);
    Code:
       0: aload_0
       1: bipush        50
       3: invokestatic  #375                // Method countAfter:(Lday20/Enhance;I)I
       6: ireturn

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

  private static final day20.Enhance perform$lambda$8(day20.Enhance);
    Code:
       0: aload_0
       1: ldc_w         #383                // String p
       4: invokestatic  #232                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokestatic  #385                // Method step:(Lday20/Enhance;)Lday20/Enhance;
      11: areturn
}


package day11

import java.io.File

fun main() {
    val data = parse("src/main/kotlin/day11/Day11.txt")

    val answer1 = part1(data.toMutableList())
    val answer2 = part2(data.toMutableList())

    println("🎄 Day 11 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

private fun parse(path: String): List<Int> =
    File(path)
        .readLines()
        .flatMap { it.map(Char::digitToInt) }

private fun adjacentNodes(x: Int, y: Int): List<Pair<Int, Int>> =
    listOfNotNull(
        if (x - 1 >= 0 && y - 1 >= 0) x - 1 to y - 1 else null,
        if (              y - 1 >= 0) x     to y - 1 else null,
        if (x + 1 < 10 && y - 1 >= 0) x + 1 to y - 1 else null,
        if (x - 1 >= 0              ) x - 1 to y     else null,
        if (x + 1 < 10              ) x + 1 to y     else null,
        if (x - 1 >= 0 && y + 1 < 10) x - 1 to y + 1 else null,
        if (              y + 1 < 10) x     to y + 1 else null,
        if (x + 1 < 10 && y + 1 < 10) x + 1 to y + 1 else null,
    )

private fun step(energy: MutableList<Int>): Int {
    var flashCount = 0

    val flashQueue = ArrayDeque<Pair<Int, Int>>(100)
    for (y in 0 until 10) {
        for (x in 0 until 10) {
            val index = y * 10 + x
             if (++energy[index] > 9) {
                flashQueue.addLast(x to y)
                energy[index] = 0
            }
        }
    }

    while (flashQueue.isNotEmpty()) {
        val (x, y) = flashQueue.removeLast()
        for ((nx, ny) in adjacentNodes(x, y)) {
            val index = ny * 10 + nx
             if (energy[index] != 0 && ++energy[index] > 9) {
                flashQueue.addLast(nx to ny)
                energy[index] = 0
            }
        }
        ++flashCount
    }

    return flashCount
}

private fun part1(energy: MutableList<Int>) =
    (0 until 100)
        .sumOf { step(energy) }

private fun part2(energy: MutableList<Int>) =
    generateSequence(1) { it + 1 }
        .first { step(energy) == 100 }

Compiled from "Day11.kt"
public final class day11.Day11Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day11/Day11.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: checkcast     #14                 // class java/util/Collection
      10: invokestatic  #20                 // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      13: invokestatic  #24                 // Method part1:(Ljava/util/List;)I
      16: istore_1
      17: aload_0
      18: checkcast     #14                 // class java/util/Collection
      21: invokestatic  #20                 // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      24: invokestatic  #27                 // Method part2:(Ljava/util/List;)I
      27: istore_2
      28: ldc           #29                 // String 🎄 Day 11 🎄
      30: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      33: swap
      34: invokevirtual #41                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      37: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      40: invokevirtual #43                 // Method java/io/PrintStream.println:()V
      43: ldc           #45                 // String [Part 1]
      45: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      48: swap
      49: invokevirtual #41                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      52: new           #47                 // class java/lang/StringBuilder
      55: dup
      56: invokespecial #50                 // Method java/lang/StringBuilder."<init>":()V
      59: ldc           #52                 // String Answer:
      61: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      64: iload_1
      65: invokevirtual #59                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      68: invokevirtual #63                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      71: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      74: swap
      75: invokevirtual #41                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      78: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      81: invokevirtual #43                 // Method java/io/PrintStream.println:()V
      84: ldc           #65                 // String [Part 2]
      86: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      89: swap
      90: invokevirtual #41                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      93: new           #47                 // class java/lang/StringBuilder
      96: dup
      97: invokespecial #50                 // Method java/lang/StringBuilder."<init>":()V
     100: ldc           #52                 // String Answer:
     102: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     105: iload_2
     106: invokevirtual #59                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     109: invokevirtual #63                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     112: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
     115: swap
     116: invokevirtual #41                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     119: return

  private static final java.util.List<java.lang.Integer> parse(java.lang.String);
    Code:
       0: new           #73                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #76                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #82                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: checkcast     #84                 // class java/lang/Iterable
      17: astore_1
      18: nop
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #86                 // class java/util/ArrayList
      26: dup
      27: invokespecial #87                 // Method java/util/ArrayList."<init>":()V
      30: checkcast     #14                 // class java/util/Collection
      33: astore        4
      35: iconst_0
      36: istore        5
      38: aload_3
      39: invokeinterface #91,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        6
      46: aload         6
      48: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          194
      56: aload         6
      58: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        7
      65: aload         7
      67: checkcast     #103                // class java/lang/String
      70: astore        8
      72: iconst_0
      73: istore        9
      75: aload         8
      77: checkcast     #105                // class java/lang/CharSequence
      80: astore        10
      82: iconst_0
      83: istore        11
      85: aload         10
      87: astore        12
      89: new           #86                 // class java/util/ArrayList
      92: dup
      93: aload         10
      95: invokeinterface #109,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     100: invokespecial #112                // Method java/util/ArrayList."<init>":(I)V
     103: checkcast     #14                 // class java/util/Collection
     106: astore        13
     108: iconst_0
     109: istore        14
     111: iconst_0
     112: istore        15
     114: iload         15
     116: aload         12
     118: invokeinterface #109,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     123: if_icmpge     171
     126: aload         12
     128: iload         15
     130: invokeinterface #116,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     135: istore        16
     137: aload         13
     139: iload         16
     141: istore        17
     143: astore        18
     145: iconst_0
     146: istore        19
     148: iload         17
     150: invokestatic  #122                // Method kotlin/text/CharsKt.digitToInt:(C)I
     153: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     156: aload         18
     158: swap
     159: invokeinterface #132,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     164: pop
     165: iinc          15, 1
     168: goto          114
     171: aload         13
     173: checkcast     #134                // class java/util/List
     176: nop
     177: checkcast     #84                 // class java/lang/Iterable
     180: nop
     181: astore        8
     183: aload         4
     185: aload         8
     187: invokestatic  #138                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     190: pop
     191: goto          46
     194: aload         4
     196: checkcast     #134                // class java/util/List
     199: nop
     200: areturn

  private static final java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>> adjacentNodes(int, int);
    Code:
       0: bipush        8
       2: anewarray     #166                // class kotlin/Pair
       5: astore_2
       6: aload_2
       7: iconst_0
       8: iload_0
       9: iconst_1
      10: isub
      11: iflt          38
      14: iload_1
      15: iconst_1
      16: isub
      17: iflt          38
      20: iload_0
      21: iconst_1
      22: isub
      23: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      26: iload_1
      27: iconst_1
      28: isub
      29: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      35: goto          39
      38: aconst_null
      39: aastore
      40: aload_2
      41: iconst_1
      42: iload_1
      43: iconst_1
      44: isub
      45: iflt          64
      48: iload_0
      49: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      52: iload_1
      53: iconst_1
      54: isub
      55: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      58: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      61: goto          65
      64: aconst_null
      65: aastore
      66: aload_2
      67: iconst_2
      68: iload_0
      69: iconst_1
      70: iadd
      71: bipush        10
      73: if_icmpge     100
      76: iload_1
      77: iconst_1
      78: isub
      79: iflt          100
      82: iload_0
      83: iconst_1
      84: iadd
      85: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: iload_1
      89: iconst_1
      90: isub
      91: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      97: goto          101
     100: aconst_null
     101: aastore
     102: aload_2
     103: iconst_3
     104: iload_0
     105: iconst_1
     106: isub
     107: iflt          126
     110: iload_0
     111: iconst_1
     112: isub
     113: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     116: iload_1
     117: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     120: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     123: goto          127
     126: aconst_null
     127: aastore
     128: aload_2
     129: iconst_4
     130: iload_0
     131: iconst_1
     132: iadd
     133: bipush        10
     135: if_icmpge     154
     138: iload_0
     139: iconst_1
     140: iadd
     141: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     144: iload_1
     145: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     148: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     151: goto          155
     154: aconst_null
     155: aastore
     156: aload_2
     157: iconst_5
     158: iload_0
     159: iconst_1
     160: isub
     161: iflt          190
     164: iload_1
     165: iconst_1
     166: iadd
     167: bipush        10
     169: if_icmpge     190
     172: iload_0
     173: iconst_1
     174: isub
     175: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     178: iload_1
     179: iconst_1
     180: iadd
     181: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     184: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     187: goto          191
     190: aconst_null
     191: aastore
     192: aload_2
     193: bipush        6
     195: iload_1
     196: iconst_1
     197: iadd
     198: bipush        10
     200: if_icmpge     219
     203: iload_0
     204: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     207: iload_1
     208: iconst_1
     209: iadd
     210: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     213: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     216: goto          220
     219: aconst_null
     220: aastore
     221: aload_2
     222: bipush        7
     224: iload_0
     225: iconst_1
     226: iadd
     227: bipush        10
     229: if_icmpge     258
     232: iload_1
     233: iconst_1
     234: iadd
     235: bipush        10
     237: if_icmpge     258
     240: iload_0
     241: iconst_1
     242: iadd
     243: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     246: iload_1
     247: iconst_1
     248: iadd
     249: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     252: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     255: goto          259
     258: aconst_null
     259: aastore
     260: aload_2
     261: invokestatic  #176                // Method kotlin/collections/CollectionsKt.listOfNotNull:([Ljava/lang/Object;)Ljava/util/List;
     264: areturn

  private static final int step(java.util.List<java.lang.Integer>);
    Code:
       0: iconst_0
       1: istore_1
       2: new           #184                // class kotlin/collections/ArrayDeque
       5: dup
       6: bipush        100
       8: invokespecial #185                // Method kotlin/collections/ArrayDeque."<init>":(I)V
      11: astore_2
      12: iconst_0
      13: istore_3
      14: iload_3
      15: bipush        10
      17: if_icmpge     127
      20: iconst_0
      21: istore        4
      23: iload         4
      25: bipush        10
      27: if_icmpge     121
      30: iload_3
      31: bipush        10
      33: imul
      34: iload         4
      36: iadd
      37: istore        5
      39: aload_0
      40: iload         5
      42: aload_0
      43: iload         5
      45: invokeinterface #189,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      50: checkcast     #191                // class java/lang/Number
      53: invokevirtual #194                // Method java/lang/Number.intValue:()I
      56: iconst_1
      57: iadd
      58: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      61: invokeinterface #198,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      66: pop
      67: aload_0
      68: iload         5
      70: invokeinterface #189,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      75: checkcast     #191                // class java/lang/Number
      78: invokevirtual #194                // Method java/lang/Number.intValue:()I
      81: bipush        9
      83: if_icmple     115
      86: aload_2
      87: iload         4
      89: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      92: iload_3
      93: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      96: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      99: invokevirtual #201                // Method kotlin/collections/ArrayDeque.addLast:(Ljava/lang/Object;)V
     102: aload_0
     103: iload         5
     105: iconst_0
     106: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     109: invokeinterface #198,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     114: pop
     115: iinc          4, 1
     118: goto          23
     121: iinc          3, 1
     124: goto          14
     127: aload_2
     128: checkcast     #14                 // class java/util/Collection
     131: invokeinterface #204,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     136: ifne          143
     139: iconst_1
     140: goto          144
     143: iconst_0
     144: ifeq          354
     147: aload_2
     148: invokevirtual #207                // Method kotlin/collections/ArrayDeque.removeLast:()Ljava/lang/Object;
     151: checkcast     #166                // class kotlin/Pair
     154: astore_3
     155: aload_3
     156: invokevirtual #210                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     159: checkcast     #191                // class java/lang/Number
     162: invokevirtual #194                // Method java/lang/Number.intValue:()I
     165: istore        4
     167: aload_3
     168: invokevirtual #213                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     171: checkcast     #191                // class java/lang/Number
     174: invokevirtual #194                // Method java/lang/Number.intValue:()I
     177: istore        5
     179: iload         4
     181: iload         5
     183: invokestatic  #215                // Method adjacentNodes:(II)Ljava/util/List;
     186: invokeinterface #216,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     191: astore        6
     193: aload         6
     195: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     200: ifeq          348
     203: aload         6
     205: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     210: checkcast     #166                // class kotlin/Pair
     213: astore        7
     215: aload         7
     217: invokevirtual #210                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     220: checkcast     #191                // class java/lang/Number
     223: invokevirtual #194                // Method java/lang/Number.intValue:()I
     226: istore        8
     228: aload         7
     230: invokevirtual #213                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     233: checkcast     #191                // class java/lang/Number
     236: invokevirtual #194                // Method java/lang/Number.intValue:()I
     239: istore        9
     241: iload         9
     243: bipush        10
     245: imul
     246: iload         8
     248: iadd
     249: istore        10
     251: aload_0
     252: iload         10
     254: invokeinterface #189,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     259: checkcast     #191                // class java/lang/Number
     262: invokevirtual #194                // Method java/lang/Number.intValue:()I
     265: ifeq          193
     268: aload_0
     269: iload         10
     271: aload_0
     272: iload         10
     274: invokeinterface #189,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     279: checkcast     #191                // class java/lang/Number
     282: invokevirtual #194                // Method java/lang/Number.intValue:()I
     285: iconst_1
     286: iadd
     287: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     290: invokeinterface #198,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     295: pop
     296: aload_0
     297: iload         10
     299: invokeinterface #189,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     304: checkcast     #191                // class java/lang/Number
     307: invokevirtual #194                // Method java/lang/Number.intValue:()I
     310: bipush        9
     312: if_icmple     193
     315: aload_2
     316: iload         8
     318: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     321: iload         9
     323: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     326: invokestatic  #172                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     329: invokevirtual #201                // Method kotlin/collections/ArrayDeque.addLast:(Ljava/lang/Object;)V
     332: aload_0
     333: iload         10
     335: iconst_0
     336: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     339: invokeinterface #198,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     344: pop
     345: goto          193
     348: iinc          1, 1
     351: goto          127
     354: iload_1
     355: ireturn

  private static final int part1(java.util.List<java.lang.Integer>);
    Code:
       0: iconst_0
       1: bipush        100
       3: invokestatic  #229                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       6: checkcast     #84                 // class java/lang/Iterable
       9: astore_1
      10: iconst_0
      11: istore_2
      12: aload_1
      13: invokeinterface #91,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      18: astore_3
      19: aload_3
      20: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      25: ifeq          62
      28: aload_3
      29: checkcast     #231                // class kotlin/collections/IntIterator
      32: invokevirtual #234                // Method kotlin/collections/IntIterator.nextInt:()I
      35: istore        4
      37: iload_2
      38: iload         4
      40: istore        5
      42: istore        7
      44: iconst_0
      45: istore        6
      47: aload_0
      48: invokestatic  #236                // Method step:(Ljava/util/List;)I
      51: istore        8
      53: iload         7
      55: iload         8
      57: iadd
      58: istore_2
      59: goto          19
      62: iload_2
      63: ireturn

  private static final int part2(java.util.List<java.lang.Integer>);
    Code:
       0: iconst_1
       1: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       4: invokedynamic #256,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
       9: invokestatic  #262                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      12: astore_1
      13: nop
      14: iconst_0
      15: istore_2
      16: aload_1
      17: invokeinterface #265,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      22: astore_3
      23: aload_3
      24: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifeq          75
      32: aload_3
      33: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      38: astore        4
      40: aload         4
      42: checkcast     #191                // class java/lang/Number
      45: invokevirtual #194                // Method java/lang/Number.intValue:()I
      48: istore        5
      50: iconst_0
      51: istore        6
      53: aload_0
      54: invokestatic  #236                // Method step:(Ljava/util/List;)I
      57: bipush        100
      59: if_icmpne     66
      62: iconst_1
      63: goto          67
      66: iconst_0
      67: ifeq          23
      70: aload         4
      72: goto          86
      75: new           #267                // class java/util/NoSuchElementException
      78: dup
      79: ldc_w         #269                // String Sequence contains no element matching the predicate.
      82: invokespecial #270                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
      85: athrow
      86: checkcast     #191                // class java/lang/Number
      89: invokevirtual #194                // Method java/lang/Number.intValue:()I
      92: ireturn

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

  private static final java.lang.Integer part2$lambda$2(int);
    Code:
       0: iload_0
       1: iconst_1
       2: iadd
       3: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       6: areturn
}