package day13

import java.io.File
import kotlin.math.abs

fun main() {
    val (points, folds) = parse("src/main/kotlin/day13/Day13.txt")

    val answer1 = part1(points, folds)
    val answer2 = part2(points, folds)

    println("🎄 Day 13 🎄")

    println()

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

    println()

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

private enum class Axis {
    X, Y
}

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

private data class Fold(
    val axis: Axis,
    val line: Int,
)

private data class Instructions(
    val points: Set<Point>,
    val folds: List<Fold>,
)

private fun parse(path: String): Instructions {
    val (pointsPart, foldsPart) = File(path)
        .readText()
        .split("""(\n\n)|(\r\n\r\n)""".toRegex())
        .map(String::trim)

    val points = pointsPart
        .lines()
        .mapTo(HashSet(), String::toPoint)

    val folds = foldsPart
        .lines()
        .map(String::toFold)

    return Instructions(points, folds)
}

private fun String.toPoint(): Point =
    this.split(",")
        .let { (lhs, rhs) -> Point(lhs.toInt(), rhs.toInt()) }

private fun String.toFold(): Fold =
    this.removePrefix("fold along ")
        .split("=")
        .let { (lhs, rhs) -> Fold(lhs.toAxis(), rhs.toInt()) }

private fun String.toAxis(): Axis =
    when (this) {
        "x" -> Axis.X
        "y" -> Axis.Y
        else -> error("Invalid folding axis")
    }

private fun Point.reflect(axis: Axis, line: Int): Point =
    when (axis) {
        Axis.X -> Point(line - abs(x - line), y)
        Axis.Y -> Point(x, line - abs(y - line))
    }

private fun part1(points: Set<Point>, folds: List<Fold>): Int {
    val (axis, line) = folds.first()
    return points
        .mapTo(HashSet()) { it.reflect(axis, line) }
        .count()
}

private fun part2(points: Set<Point>, folds: List<Fold>): String {
    val code = folds.fold(points) { dots, (axis, line) ->
        dots.mapTo(HashSet())  { it.reflect(axis, line) }
    }

    return buildString {
        for (y in 0 until 6) {
            for (x in 0 until 40) {
                if (x % 5 == 0) {
                    append("  ")
                }
                append(if (code.contains(Point(x, y))) '#' else ' ')
            }
            append('\n')
        }
    }
}

Compiled from "Day13.kt"
public final class day13.Day13Kt$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method day13/Axis.values:()[Lday13/Axis;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field day13/Axis.X:Lday13/Axis;
      12: invokevirtual #22                 // Method day13/Axis.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field day13/Axis.Y:Lday13/Axis;
      26: invokevirtual #22                 // Method day13/Axis.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: aload_0
      36: putstatic     #29                 // Field $EnumSwitchMapping$0:[I
      39: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
}

Compiled from "Day13.kt"
public final class day13.Day13Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day13/Day13.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Lday13/Instructions;
       5: astore_0
       6: aload_0
       7: invokevirtual #18                 // Method day13/Instructions.component1:()Ljava/util/Set;
      10: astore_1
      11: aload_0
      12: invokevirtual #22                 // Method day13/Instructions.component2:()Ljava/util/List;
      15: astore_2
      16: aload_1
      17: aload_2
      18: invokestatic  #26                 // Method part1:(Ljava/util/Set;Ljava/util/List;)I
      21: istore_3
      22: aload_1
      23: aload_2
      24: invokestatic  #30                 // Method part2:(Ljava/util/Set;Ljava/util/List;)Ljava/lang/String;
      27: astore        4
      29: ldc           #32                 // String 🎄 Day 13 🎄
      31: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      34: swap
      35: invokevirtual #44                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      38: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      41: invokevirtual #46                 // Method java/io/PrintStream.println:()V
      44: ldc           #48                 // String [Part 1]
      46: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      49: swap
      50: invokevirtual #44                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      53: new           #50                 // class java/lang/StringBuilder
      56: dup
      57: invokespecial #53                 // Method java/lang/StringBuilder."<init>":()V
      60: ldc           #55                 // String Answer:
      62: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      65: iload_3
      66: invokevirtual #62                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      69: invokevirtual #66                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      72: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      75: swap
      76: invokevirtual #44                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      79: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      82: invokevirtual #46                 // Method java/io/PrintStream.println:()V
      85: ldc           #68                 // String [Part 2]
      87: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      90: swap
      91: invokevirtual #44                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      94: new           #50                 // class java/lang/StringBuilder
      97: dup
      98: invokespecial #53                 // Method java/lang/StringBuilder."<init>":()V
     101: ldc           #70                 // String Answer:\n
     103: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     106: aload         4
     108: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     111: invokevirtual #66                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     114: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
     117: swap
     118: invokevirtual #44                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     121: return

  private static final day13.Instructions parse(java.lang.String);
    Code:
       0: new           #80                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #83                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #89                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      14: checkcast     #91                 // class java/lang/CharSequence
      17: astore_2
      18: new           #93                 // class kotlin/text/Regex
      21: dup
      22: ldc           #95                 // String (\\n\\n)|(\\r\\n\\r\\n)
      24: invokespecial #96                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_3
      32: aload_2
      33: iload         4
      35: invokevirtual #100                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      38: checkcast     #102                // class java/lang/Iterable
      41: astore_2
      42: nop
      43: iconst_0
      44: istore_3
      45: aload_2
      46: astore        4
      48: new           #104                // class java/util/ArrayList
      51: dup
      52: aload_2
      53: bipush        10
      55: invokestatic  #110                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      58: invokespecial #113                // Method java/util/ArrayList."<init>":(I)V
      61: checkcast     #115                // class java/util/Collection
      64: astore        5
      66: iconst_0
      67: istore        6
      69: aload         4
      71: invokeinterface #119,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      76: astore        7
      78: aload         7
      80: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      85: ifeq          135
      88: aload         7
      90: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      95: astore        8
      97: aload         5
      99: aload         8
     101: checkcast     #131                // class java/lang/String
     104: astore        9
     106: astore        15
     108: iconst_0
     109: istore        10
     111: aload         9
     113: checkcast     #91                 // class java/lang/CharSequence
     116: invokestatic  #137                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     119: invokevirtual #138                // Method java/lang/Object.toString:()Ljava/lang/String;
     122: nop
     123: aload         15
     125: swap
     126: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     131: pop
     132: goto          78
     135: aload         5
     137: checkcast     #144                // class java/util/List
     140: nop
     141: astore_1
     142: aload_1
     143: iconst_0
     144: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     149: checkcast     #131                // class java/lang/String
     152: astore_2
     153: aload_1
     154: iconst_1
     155: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     160: checkcast     #131                // class java/lang/String
     163: astore_3
     164: aload_2
     165: checkcast     #91                 // class java/lang/CharSequence
     168: invokestatic  #152                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     171: checkcast     #102                // class java/lang/Iterable
     174: astore        5
     176: new           #154                // class java/util/HashSet
     179: dup
     180: invokespecial #155                // Method java/util/HashSet."<init>":()V
     183: checkcast     #115                // class java/util/Collection
     186: astore        6
     188: iconst_0
     189: istore        7
     191: aload         5
     193: invokeinterface #119,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     198: astore        8
     200: aload         8
     202: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     207: ifeq          250
     210: aload         8
     212: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     217: astore        9
     219: aload         6
     221: aload         9
     223: checkcast     #131                // class java/lang/String
     226: astore        10
     228: astore        15
     230: iconst_0
     231: istore        11
     233: aload         10
     235: invokestatic  #159                // Method toPoint:(Ljava/lang/String;)Lday13/Point;
     238: aload         15
     240: swap
     241: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     246: pop
     247: goto          200
     250: aload         6
     252: checkcast     #154                // class java/util/HashSet
     255: astore        4
     257: aload_3
     258: checkcast     #91                 // class java/lang/CharSequence
     261: invokestatic  #152                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     264: checkcast     #102                // class java/lang/Iterable
     267: astore        6
     269: nop
     270: iconst_0
     271: istore        7
     273: aload         6
     275: astore        8
     277: new           #104                // class java/util/ArrayList
     280: dup
     281: aload         6
     283: bipush        10
     285: invokestatic  #110                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     288: invokespecial #113                // Method java/util/ArrayList."<init>":(I)V
     291: checkcast     #115                // class java/util/Collection
     294: astore        9
     296: iconst_0
     297: istore        10
     299: aload         8
     301: invokeinterface #119,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     306: astore        11
     308: aload         11
     310: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     315: ifeq          358
     318: aload         11
     320: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     325: astore        12
     327: aload         9
     329: aload         12
     331: checkcast     #131                // class java/lang/String
     334: astore        13
     336: astore        15
     338: iconst_0
     339: istore        14
     341: aload         13
     343: invokestatic  #163                // Method toFold:(Ljava/lang/String;)Lday13/Fold;
     346: aload         15
     348: swap
     349: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     354: pop
     355: goto          308
     358: aload         9
     360: checkcast     #144                // class java/util/List
     363: nop
     364: astore        5
     366: new           #14                 // class day13/Instructions
     369: dup
     370: aload         4
     372: checkcast     #165                // class java/util/Set
     375: aload         5
     377: invokespecial #168                // Method day13/Instructions."<init>":(Ljava/util/Set;Ljava/util/List;)V
     380: areturn

  private static final day13.Point toPoint(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #91                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #131                // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc           #190                // String ,
      13: aastore
      14: aload_1
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #194                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: astore_2
      24: iconst_0
      25: istore_3
      26: aload_2
      27: iconst_0
      28: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      33: checkcast     #131                // class java/lang/String
      36: astore        4
      38: aload_2
      39: iconst_1
      40: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      45: checkcast     #131                // class java/lang/String
      48: astore        5
      50: new           #196                // class day13/Point
      53: dup
      54: aload         4
      56: invokestatic  #202                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      59: aload         5
      61: invokestatic  #202                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      64: invokespecial #205                // Method day13/Point."<init>":(II)V
      67: nop
      68: areturn

  private static final day13.Fold toFold(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #211                // String fold along
       3: checkcast     #91                 // class java/lang/CharSequence
       6: invokestatic  #215                // Method kotlin/text/StringsKt.removePrefix:(Ljava/lang/String;Ljava/lang/CharSequence;)Ljava/lang/String;
       9: checkcast     #91                 // class java/lang/CharSequence
      12: iconst_1
      13: anewarray     #131                // class java/lang/String
      16: astore_1
      17: aload_1
      18: iconst_0
      19: ldc           #217                // String =
      21: aastore
      22: aload_1
      23: iconst_0
      24: iconst_0
      25: bipush        6
      27: aconst_null
      28: invokestatic  #194                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      31: astore_2
      32: iconst_0
      33: istore_3
      34: aload_2
      35: iconst_0
      36: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      41: checkcast     #131                // class java/lang/String
      44: astore        4
      46: aload_2
      47: iconst_1
      48: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      53: checkcast     #131                // class java/lang/String
      56: astore        5
      58: new           #219                // class day13/Fold
      61: dup
      62: aload         4
      64: invokestatic  #223                // Method toAxis:(Ljava/lang/String;)Lday13/Axis;
      67: aload         5
      69: invokestatic  #202                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      72: invokespecial #226                // Method day13/Fold."<init>":(Lday13/Axis;I)V
      75: nop
      76: areturn

  private static final day13.Axis toAxis(java.lang.String);
    Code:
       0: aload_0
       1: astore_1
       2: aload_1
       3: ldc           #230                // String x
       5: invokestatic  #236                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       8: ifeq          17
      11: getstatic     #242                // Field day13/Axis.X:Lday13/Axis;
      14: goto          45
      17: aload_1
      18: ldc           #244                // String y
      20: invokestatic  #236                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      23: ifeq          32
      26: getstatic     #247                // Field day13/Axis.Y:Lday13/Axis;
      29: goto          45
      32: new           #249                // class java/lang/IllegalStateException
      35: dup
      36: ldc           #251                // String Invalid folding axis
      38: invokevirtual #138                // Method java/lang/Object.toString:()Ljava/lang/String;
      41: invokespecial #252                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      44: athrow
      45: areturn

  private static final day13.Point reflect(day13.Point, day13.Axis, int);
    Code:
       0: aload_1
       1: getstatic     #261                // Field day13/Day13Kt$WhenMappings.$EnumSwitchMapping$0:[I
       4: swap
       5: invokevirtual #265                // Method day13/Axis.ordinal:()I
       8: iaload
       9: tableswitch   { // 1 to 2
                     1: 32
                     2: 57
               default: 82
          }
      32: new           #196                // class day13/Point
      35: dup
      36: iload_2
      37: aload_0
      38: invokevirtual #268                // Method day13/Point.getX:()I
      41: iload_2
      42: isub
      43: invokestatic  #274                // Method java/lang/Math.abs:(I)I
      46: isub
      47: aload_0
      48: invokevirtual #277                // Method day13/Point.getY:()I
      51: invokespecial #205                // Method day13/Point."<init>":(II)V
      54: goto          90
      57: new           #196                // class day13/Point
      60: dup
      61: aload_0
      62: invokevirtual #268                // Method day13/Point.getX:()I
      65: iload_2
      66: aload_0
      67: invokevirtual #277                // Method day13/Point.getY:()I
      70: iload_2
      71: isub
      72: invokestatic  #274                // Method java/lang/Math.abs:(I)I
      75: isub
      76: invokespecial #205                // Method day13/Point."<init>":(II)V
      79: goto          90
      82: new           #279                // class kotlin/NoWhenBranchMatchedException
      85: dup
      86: invokespecial #280                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
      89: athrow
      90: areturn

  private static final int part1(java.util.Set<day13.Point>, java.util.List<day13.Fold>);
    Code:
       0: aload_1
       1: invokestatic  #289                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
       4: checkcast     #219                // class day13/Fold
       7: astore_2
       8: aload_2
       9: invokevirtual #292                // Method day13/Fold.component1:()Lday13/Axis;
      12: astore_3
      13: aload_2
      14: invokevirtual #294                // Method day13/Fold.component2:()I
      17: istore        4
      19: aload_0
      20: checkcast     #102                // class java/lang/Iterable
      23: astore        5
      25: new           #154                // class java/util/HashSet
      28: dup
      29: invokespecial #155                // Method java/util/HashSet."<init>":()V
      32: checkcast     #115                // class java/util/Collection
      35: astore        6
      37: iconst_0
      38: istore        7
      40: aload         5
      42: invokeinterface #119,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      47: astore        8
      49: aload         8
      51: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      56: ifeq          102
      59: aload         8
      61: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      66: astore        9
      68: aload         6
      70: aload         9
      72: checkcast     #196                // class day13/Point
      75: astore        10
      77: astore        12
      79: iconst_0
      80: istore        11
      82: aload         10
      84: aload_3
      85: iload         4
      87: invokestatic  #296                // Method reflect:(Lday13/Point;Lday13/Axis;I)Lday13/Point;
      90: aload         12
      92: swap
      93: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      98: pop
      99: goto          49
     102: aload         6
     104: invokeinterface #299,  1          // InterfaceMethod java/util/Collection.size:()I
     109: ireturn

  private static final java.lang.String part2(java.util.Set<day13.Point>, java.util.List<day13.Fold>);
    Code:
       0: aload_1
       1: checkcast     #102                // class java/lang/Iterable
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_0
       9: astore        5
      11: aload_3
      12: invokeinterface #119,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      17: astore        6
      19: aload         6
      21: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifeq          162
      29: aload         6
      31: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      36: astore        7
      38: aload         5
      40: aload         7
      42: checkcast     #219                // class day13/Fold
      45: astore        8
      47: astore        9
      49: iconst_0
      50: istore        10
      52: aload         8
      54: invokevirtual #292                // Method day13/Fold.component1:()Lday13/Axis;
      57: astore        11
      59: aload         8
      61: invokevirtual #294                // Method day13/Fold.component2:()I
      64: istore        12
      66: aload         9
      68: checkcast     #102                // class java/lang/Iterable
      71: astore        13
      73: new           #154                // class java/util/HashSet
      76: dup
      77: invokespecial #155                // Method java/util/HashSet."<init>":()V
      80: checkcast     #115                // class java/util/Collection
      83: astore        14
      85: iconst_0
      86: istore        15
      88: aload         13
      90: invokeinterface #119,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      95: astore        16
      97: aload         16
      99: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     104: ifeq          151
     107: aload         16
     109: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     114: astore        17
     116: aload         14
     118: aload         17
     120: checkcast     #196                // class day13/Point
     123: astore        18
     125: astore        19
     127: iconst_0
     128: istore        20
     130: aload         18
     132: aload         11
     134: iload         12
     136: invokestatic  #296                // Method reflect:(Lday13/Point;Lday13/Axis;I)Lday13/Point;
     139: aload         19
     141: swap
     142: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     147: pop
     148: goto          97
     151: aload         14
     153: checkcast     #165                // class java/util/Set
     156: nop
     157: astore        5
     159: goto          19
     162: aload         5
     164: astore_2
     165: new           #50                 // class java/lang/StringBuilder
     168: dup
     169: invokespecial #53                 // Method java/lang/StringBuilder."<init>":()V
     172: astore_3
     173: aload_3
     174: astore        4
     176: iconst_0
     177: istore        5
     179: iconst_0
     180: istore        6
     182: iload         6
     184: bipush        6
     186: if_icmpge     268
     189: iconst_0
     190: istore        7
     192: iload         7
     194: bipush        40
     196: if_icmpge     254
     199: iload         7
     201: iconst_5
     202: irem
     203: ifne          215
     206: aload         4
     208: ldc_w         #304                // String
     211: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     214: pop
     215: aload         4
     217: aload_2
     218: new           #196                // class day13/Point
     221: dup
     222: iload         7
     224: iload         6
     226: invokespecial #205                // Method day13/Point."<init>":(II)V
     229: invokeinterface #307,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     234: ifeq          242
     237: bipush        35
     239: goto          244
     242: bipush        32
     244: invokevirtual #310                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     247: pop
     248: iinc          7, 1
     251: goto          192
     254: aload         4
     256: bipush        10
     258: invokevirtual #310                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     261: pop
     262: iinc          6, 1
     265: goto          182
     268: nop
     269: aload_3
     270: invokevirtual #66                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     273: areturn

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


package day25

import java.io.File

fun main() {
    val data = parse("src/main/kotlin/day25/Day25.txt")

    val answer = solve(data)

    println("🎄 Day 25 🎄")
    println("Answer: $answer")
}

private data class Area(
    val width: Int,
    val height: Int,
    val cells: List<Char>,
)

private fun Area.getIndex(x: Int, y: Int): Int {
    val xi = if (x >= width) {
        x - width
    } else if (x < 0) {
        x + width
    } else {
        x
    }

    val yi = if (y >= height) {
        y - height
    } else if (y < 0) {
        y + height
    } else {
        y
    }

    return yi * width + xi
}

private fun parse(path: String): Area =
    File(path)
        .readLines()
        .let { lines ->
            val height = lines.size
            val width = lines[0].length
            val cells = lines.flatMap(String::toList)

            Area(width, height, cells)
        }

private fun move(area: Area, herd: Char): Area {
    val dx = if (herd == '>') 1 else 0
    val dy = if (herd == '>') 0 else 1

    val prev = area.cells
    val next = prev.toMutableList()

    for (y in 0 until area.height) {
        for (x in 0 until area.width) {
            val index = area.getIndex(x, y)
            if (prev[index] == herd) {
                val nextIndex = area.getIndex(x + dx, y + dy)
                if (prev[nextIndex] == '.') {
                    next[nextIndex] = herd
                    next[index] = '.'
                }
            }
        }
    }

    return area.copy(cells = next)
}

private fun step(previous: Area): Area {
    return move(move(previous, '>'), 'v')
}

private fun solve(area: Area): Int {
    return 1 + generateSequence(area) { step(it) }
        .zipWithNext()
        .indexOfFirst { (a1, a2) -> a1 == a2 }
}

Compiled from "Day25.kt"
public final class day25.Day25Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day25/Day25.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Lday25/Area;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method solve:(Lday25/Area;)I
      10: istore_1
      11: ldc           #18                 // String 🎄 Day 25 🎄
      13: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      16: swap
      17: invokevirtual #30                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      20: new           #32                 // class java/lang/StringBuilder
      23: dup
      24: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      27: ldc           #37                 // String Answer:
      29: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      32: iload_1
      33: invokevirtual #44                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      36: invokevirtual #48                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      42: swap
      43: invokevirtual #30                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      46: return

  private static final int getIndex(day25.Area, int, int);
    Code:
       0: iload_1
       1: aload_0
       2: invokevirtual #60                 // Method day25/Area.getWidth:()I
       5: if_icmplt     17
       8: iload_1
       9: aload_0
      10: invokevirtual #60                 // Method day25/Area.getWidth:()I
      13: isub
      14: goto          31
      17: iload_1
      18: ifge          30
      21: iload_1
      22: aload_0
      23: invokevirtual #60                 // Method day25/Area.getWidth:()I
      26: iadd
      27: goto          31
      30: iload_1
      31: istore_3
      32: iload_2
      33: aload_0
      34: invokevirtual #63                 // Method day25/Area.getHeight:()I
      37: if_icmplt     49
      40: iload_2
      41: aload_0
      42: invokevirtual #63                 // Method day25/Area.getHeight:()I
      45: isub
      46: goto          63
      49: iload_2
      50: ifge          62
      53: iload_2
      54: aload_0
      55: invokevirtual #63                 // Method day25/Area.getHeight:()I
      58: iadd
      59: goto          63
      62: iload_2
      63: istore        4
      65: iload         4
      67: aload_0
      68: invokevirtual #60                 // Method day25/Area.getWidth:()I
      71: imul
      72: iload_3
      73: iadd
      74: ireturn

  private static final day25.Area parse(java.lang.String);
    Code:
       0: new           #70                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #73                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #79                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: astore_1
      15: iconst_0
      16: istore_2
      17: aload_1
      18: invokeinterface #84,  1           // InterfaceMethod java/util/List.size:()I
      23: istore_3
      24: aload_1
      25: iconst_0
      26: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      31: checkcast     #90                 // class java/lang/String
      34: invokevirtual #93                 // Method java/lang/String.length:()I
      37: istore        4
      39: aload_1
      40: checkcast     #95                 // class java/lang/Iterable
      43: astore        5
      45: iconst_0
      46: istore        6
      48: aload         5
      50: astore        7
      52: new           #97                 // class java/util/ArrayList
      55: dup
      56: invokespecial #98                 // Method java/util/ArrayList."<init>":()V
      59: checkcast     #100                // class java/util/Collection
      62: astore        8
      64: iconst_0
      65: istore        9
      67: aload         7
      69: invokeinterface #104,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      74: astore        10
      76: aload         10
      78: invokeinterface #110,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      83: ifeq          129
      86: aload         10
      88: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      93: astore        11
      95: aload         11
      97: checkcast     #90                 // class java/lang/String
     100: astore        12
     102: iconst_0
     103: istore        13
     105: aload         12
     107: checkcast     #116                // class java/lang/CharSequence
     110: invokestatic  #122                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
     113: checkcast     #95                 // class java/lang/Iterable
     116: astore        12
     118: aload         8
     120: aload         12
     122: invokestatic  #128                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     125: pop
     126: goto          76
     129: aload         8
     131: checkcast     #81                 // class java/util/List
     134: nop
     135: astore        14
     137: new           #56                 // class day25/Area
     140: dup
     141: iload         4
     143: iload_3
     144: aload         14
     146: invokespecial #131                // Method day25/Area."<init>":(IILjava/util/List;)V
     149: nop
     150: areturn

  private static final day25.Area move(day25.Area, char);
    Code:
       0: iload_1
       1: bipush        62
       3: if_icmpne     10
       6: iconst_1
       7: goto          11
      10: iconst_0
      11: istore_2
      12: iload_1
      13: bipush        62
      15: if_icmpne     22
      18: iconst_0
      19: goto          23
      22: iconst_1
      23: istore_3
      24: aload_0
      25: invokevirtual #157                // Method day25/Area.getCells:()Ljava/util/List;
      28: astore        4
      30: aload         4
      32: checkcast     #100                // class java/util/Collection
      35: invokestatic  #161                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      38: astore        5
      40: iconst_0
      41: istore        6
      43: aload_0
      44: invokevirtual #63                 // Method day25/Area.getHeight:()I
      47: istore        7
      49: iload         6
      51: iload         7
      53: if_icmpge     176
      56: iconst_0
      57: istore        8
      59: aload_0
      60: invokevirtual #60                 // Method day25/Area.getWidth:()I
      63: istore        9
      65: iload         8
      67: iload         9
      69: if_icmpge     170
      72: aload_0
      73: iload         8
      75: iload         6
      77: invokestatic  #163                // Method getIndex:(Lday25/Area;II)I
      80: istore        10
      82: aload         4
      84: iload         10
      86: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      91: checkcast     #165                // class java/lang/Character
      94: invokevirtual #169                // Method java/lang/Character.charValue:()C
      97: iload_1
      98: if_icmpne     164
     101: aload_0
     102: iload         8
     104: iload_2
     105: iadd
     106: iload         6
     108: iload_3
     109: iadd
     110: invokestatic  #163                // Method getIndex:(Lday25/Area;II)I
     113: istore        11
     115: aload         4
     117: iload         11
     119: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     124: checkcast     #165                // class java/lang/Character
     127: invokevirtual #169                // Method java/lang/Character.charValue:()C
     130: bipush        46
     132: if_icmpne     164
     135: aload         5
     137: iload         11
     139: iload_1
     140: invokestatic  #173                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     143: invokeinterface #177,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     148: pop
     149: aload         5
     151: iload         10
     153: bipush        46
     155: invokestatic  #173                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     158: invokeinterface #177,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     163: pop
     164: iinc          8, 1
     167: goto          65
     170: iinc          6, 1
     173: goto          49
     176: aload_0
     177: iconst_0
     178: iconst_0
     179: aload         5
     181: iconst_3
     182: aconst_null
     183: invokestatic  #181                // Method day25/Area.copy$default:(Lday25/Area;IILjava/util/List;ILjava/lang/Object;)Lday25/Area;
     186: areturn

  private static final day25.Area step(day25.Area);
    Code:
       0: aload_0
       1: bipush        62
       3: invokestatic  #193                // Method move:(Lday25/Area;C)Lday25/Area;
       6: bipush        118
       8: invokestatic  #193                // Method move:(Lday25/Area;C)Lday25/Area;
      11: areturn

  private static final int solve(day25.Area);
    Code:
       0: iconst_1
       1: aload_0
       2: invokedynamic #212,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
       7: invokestatic  #218                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      10: invokestatic  #222                // Method kotlin/sequences/SequencesKt.zipWithNext:(Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence;
      13: astore_1
      14: istore        10
      16: iconst_0
      17: istore_2
      18: iconst_0
      19: istore_3
      20: aload_1
      21: invokeinterface #225,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      26: astore        4
      28: aload         4
      30: invokeinterface #110,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      35: ifeq          104
      38: aload         4
      40: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      45: astore        5
      47: iload_3
      48: ifge          54
      51: invokestatic  #228                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      54: aload         5
      56: checkcast     #230                // class kotlin/Pair
      59: astore        6
      61: iconst_0
      62: istore        7
      64: aload         6
      66: invokevirtual #233                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      69: checkcast     #56                 // class day25/Area
      72: astore        8
      74: aload         6
      76: invokevirtual #236                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      79: checkcast     #56                 // class day25/Area
      82: astore        9
      84: aload         8
      86: aload         9
      88: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      91: ifeq          98
      94: iload_3
      95: goto          105
      98: iinc          3, 1
     101: goto          28
     104: iconst_m1
     105: istore        11
     107: iload         10
     109: iload         11
     111: iadd
     112: ireturn

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

  private static final day25.Area solve$lambda$1(day25.Area);
    Code:
       0: aload_0
       1: ldc_w         #257                // String it
       4: invokestatic  #261                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokestatic  #263                // Method step:(Lday25/Area;)Lday25/Area;
      11: areturn
}


package day22

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

fun main() {
    val data = parse("src/main/kotlin/day22/Day22.txt")

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

    println("🎄 Day 22 🎄")

    println()

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

    println()

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

private data class Cuboid(
    val x0: Int, val x1: Int,
    val y0: Int, val y1: Int,
    val z0: Int, val z1: Int,
    val on: Boolean = true,
)

private fun Cuboid.overlap(other: Cuboid): Cuboid? {
    val (ax0, ax1, ay0, ay1, az0, az1) = this
    val (bx0, bx1, by0, by1, bz0, bz1) = other

    val ox0 = max(ax0, bx0)
    val ox1 = min(ax1, bx1)
    val oy0 = max(ay0, by0)
    val oy1 = min(ay1, by1)
    val oz0 = max(az0, bz0)
    val oz1 = min(az1, bz1)

    return if (ox0 <= ox1 && oy0 <= oy1 && oz0 <= oz1) {
        Cuboid(ox0, ox1, oy0, oy1, oz0, oz1)
    } else {
        null
    }
}

/*
 * A recursive solution based on the principle of exclusion and inclusion.
 * To be fair, this is not the first solution I came up with. My initial idea
 * was to maintain a list of non-overlapping cuboids by splitting every cuboid
 * into smaller ones whenever overlaps occur, and then calculating the sum of
 * their volumes.
 *
 * However, I found out about this principle and thought that this was a much
 * neater way of implementing this, and it works quite fast, too. There is
 * always something new to learn! :)
 */
private fun count(cuboids: List<Cuboid>): Long {
    if (cuboids.isEmpty()) {
        return 0
    }

    val (head, rest) = cuboids.first() to cuboids.drop(1)
    return if (head.on) {
        val intersections = rest.mapNotNull(head::overlap)
        head.volume() + count(rest) - count(intersections)
    } else {
        count(rest)
    }
}

private fun Cuboid.volume(): Long {
    val xs = (x1 - x0 + 1).toLong()
    val ys = (y1 - y0 + 1).toLong()
    val zs = (z1 - z0 + 1).toLong()
    return xs * ys * zs
}

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

private fun String.toCuboid(): Cuboid {
    val (valuePart, coordinatesPart) = this.split(" ")
    val (x, y, z) = coordinatesPart
        .split(",")
        .map { it.drop(2) }

    val (x0, x1) = x.toBounds()
    val (y0, y1) = y.toBounds()
    val (z0, z1) = z.toBounds()

    val on = valuePart == "on"
    return Cuboid(x0, x1, y0, y1, z0, z1, on)
}

private fun String.toBounds(): Pair<Int, Int> =
    this.split("..")
        .map(String::toInt)
        .let { (a, b) -> a to b }

private fun part1(cuboids: List<Cuboid>): Long =
    cuboids
        .filter { (x0, x1, y0, y1, z0, z1) -> arrayOf(x0, x1, y0, y1, z0, z1).all { it in -50..50 } }
        .let(::count)

private fun part2(cuboids: List<Cuboid>): Long =
    count(cuboids)

Compiled from "Day22.kt"
public final class day22.Day22Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day22/Day22.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;)J
      10: lstore_1
      11: aload_0
      12: invokestatic  #19                 // Method part2:(Ljava/util/List;)J
      15: lstore_3
      16: ldc           #21                 // String 🎄 Day 22 🎄
      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: lload_1
      53: invokevirtual #51                 // Method java/lang/StringBuilder.append:(J)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: lload_3
      94: invokevirtual #51                 // Method java/lang/StringBuilder.append:(J)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 day22.Cuboid overlap(day22.Cuboid, day22.Cuboid);
    Code:
       0: aload_0
       1: invokevirtual #70                 // Method day22/Cuboid.component1:()I
       4: istore_2
       5: aload_0
       6: invokevirtual #73                 // Method day22/Cuboid.component2:()I
       9: istore_3
      10: aload_0
      11: invokevirtual #76                 // Method day22/Cuboid.component3:()I
      14: istore        4
      16: aload_0
      17: invokevirtual #79                 // Method day22/Cuboid.component4:()I
      20: istore        5
      22: aload_0
      23: invokevirtual #82                 // Method day22/Cuboid.component5:()I
      26: istore        6
      28: aload_0
      29: invokevirtual #85                 // Method day22/Cuboid.component6:()I
      32: istore        7
      34: aload_1
      35: invokevirtual #70                 // Method day22/Cuboid.component1:()I
      38: istore        8
      40: aload_1
      41: invokevirtual #73                 // Method day22/Cuboid.component2:()I
      44: istore        9
      46: aload_1
      47: invokevirtual #76                 // Method day22/Cuboid.component3:()I
      50: istore        10
      52: aload_1
      53: invokevirtual #79                 // Method day22/Cuboid.component4:()I
      56: istore        11
      58: aload_1
      59: invokevirtual #82                 // Method day22/Cuboid.component5:()I
      62: istore        12
      64: aload_1
      65: invokevirtual #85                 // Method day22/Cuboid.component6:()I
      68: istore        13
      70: iload_2
      71: iload         8
      73: invokestatic  #91                 // Method java/lang/Math.max:(II)I
      76: istore        14
      78: iload_3
      79: iload         9
      81: invokestatic  #94                 // Method java/lang/Math.min:(II)I
      84: istore        15
      86: iload         4
      88: iload         10
      90: invokestatic  #91                 // Method java/lang/Math.max:(II)I
      93: istore        16
      95: iload         5
      97: iload         11
      99: invokestatic  #94                 // Method java/lang/Math.min:(II)I
     102: istore        17
     104: iload         6
     106: iload         12
     108: invokestatic  #91                 // Method java/lang/Math.max:(II)I
     111: istore        18
     113: iload         7
     115: iload         13
     117: invokestatic  #94                 // Method java/lang/Math.min:(II)I
     120: istore        19
     122: iload         14
     124: iload         15
     126: if_icmpgt     169
     129: iload         16
     131: iload         17
     133: if_icmpgt     169
     136: iload         18
     138: iload         19
     140: if_icmpgt     169
     143: new           #66                 // class day22/Cuboid
     146: dup
     147: iload         14
     149: iload         15
     151: iload         16
     153: iload         17
     155: iload         18
     157: iload         19
     159: iconst_0
     160: bipush        64
     162: aconst_null
     163: invokespecial #97                 // Method day22/Cuboid."<init>":(IIIIIIZILkotlin/jvm/internal/DefaultConstructorMarker;)V
     166: goto          170
     169: aconst_null
     170: areturn

  private static final long count(java.util.List<day22.Cuboid>);
    Code:
       0: aload_0
       1: invokeinterface #127,  1          // InterfaceMethod java/util/List.isEmpty:()Z
       6: ifeq          11
       9: lconst_0
      10: lreturn
      11: aload_0
      12: invokestatic  #133                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      15: aload_0
      16: checkcast     #135                // class java/lang/Iterable
      19: iconst_1
      20: invokestatic  #139                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      23: invokestatic  #145                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      26: astore_1
      27: aload_1
      28: invokevirtual #150                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      31: checkcast     #66                 // class day22/Cuboid
      34: astore_2
      35: aload_1
      36: invokevirtual #152                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      39: checkcast     #123                // class java/util/List
      42: astore_3
      43: aload_2
      44: invokevirtual #155                // Method day22/Cuboid.getOn:()Z
      47: ifeq          190
      50: aload_3
      51: checkcast     #135                // class java/lang/Iterable
      54: astore        5
      56: iconst_0
      57: istore        6
      59: aload         5
      61: astore        7
      63: new           #157                // class java/util/ArrayList
      66: dup
      67: invokespecial #158                // Method java/util/ArrayList."<init>":()V
      70: checkcast     #160                // class java/util/Collection
      73: astore        8
      75: iconst_0
      76: istore        9
      78: aload         7
      80: astore        10
      82: iconst_0
      83: istore        11
      85: aload         10
      87: invokeinterface #164,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      92: astore        12
      94: aload         12
      96: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     101: ifeq          163
     104: aload         12
     106: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     111: astore        13
     113: aload         13
     115: astore        14
     117: iconst_0
     118: istore        15
     120: aload         14
     122: checkcast     #66                 // class day22/Cuboid
     125: astore        16
     127: iconst_0
     128: istore        17
     130: aload_2
     131: aload         16
     133: invokestatic  #174                // Method overlap:(Lday22/Cuboid;Lday22/Cuboid;)Lday22/Cuboid;
     136: dup
     137: ifnull        158
     140: astore        18
     142: iconst_0
     143: istore        19
     145: aload         8
     147: aload         18
     149: invokeinterface #178,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     154: pop
     155: goto          159
     158: pop
     159: nop
     160: goto          94
     163: nop
     164: aload         8
     166: checkcast     #123                // class java/util/List
     169: nop
     170: astore        4
     172: aload_2
     173: invokestatic  #182                // Method volume:(Lday22/Cuboid;)J
     176: aload_3
     177: invokestatic  #184                // Method count:(Ljava/util/List;)J
     180: ladd
     181: aload         4
     183: invokestatic  #184                // Method count:(Ljava/util/List;)J
     186: lsub
     187: goto          194
     190: aload_3
     191: invokestatic  #184                // Method count:(Ljava/util/List;)J
     194: lreturn

  private static final long volume(day22.Cuboid);
    Code:
       0: aload_0
       1: invokevirtual #208                // Method day22/Cuboid.getX1:()I
       4: aload_0
       5: invokevirtual #211                // Method day22/Cuboid.getX0:()I
       8: isub
       9: iconst_1
      10: iadd
      11: i2l
      12: lstore_1
      13: aload_0
      14: invokevirtual #214                // Method day22/Cuboid.getY1:()I
      17: aload_0
      18: invokevirtual #217                // Method day22/Cuboid.getY0:()I
      21: isub
      22: iconst_1
      23: iadd
      24: i2l
      25: lstore_3
      26: aload_0
      27: invokevirtual #220                // Method day22/Cuboid.getZ1:()I
      30: aload_0
      31: invokevirtual #223                // Method day22/Cuboid.getZ0:()I
      34: isub
      35: iconst_1
      36: iadd
      37: i2l
      38: lstore        5
      40: lload_1
      41: lload_3
      42: lmul
      43: lload         5
      45: lmul
      46: lreturn

  private static final java.util.List<day22.Cuboid> parse(java.lang.String);
    Code:
       0: new           #230                // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #233                // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #239                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: checkcast     #135                // class java/lang/Iterable
      17: astore_1
      18: nop
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #157                // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #243                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #246                // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #160                // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #164,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          102
      62: aload         6
      64: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         4
      73: aload         7
      75: checkcast     #248                // class java/lang/String
      78: astore        8
      80: astore        10
      82: iconst_0
      83: istore        9
      85: aload         8
      87: invokestatic  #252                // Method toCuboid:(Ljava/lang/String;)Lday22/Cuboid;
      90: aload         10
      92: swap
      93: invokeinterface #178,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      98: pop
      99: goto          52
     102: aload         4
     104: checkcast     #123                // class java/util/List
     107: nop
     108: areturn

  private static final day22.Cuboid toCuboid(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #262                // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #248                // class java/lang/String
       8: astore_2
       9: aload_2
      10: iconst_0
      11: ldc_w         #264                // String
      14: aastore
      15: aload_2
      16: iconst_0
      17: iconst_0
      18: bipush        6
      20: aconst_null
      21: invokestatic  #270                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      24: astore_1
      25: aload_1
      26: iconst_0
      27: invokeinterface #274,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      32: checkcast     #248                // class java/lang/String
      35: astore_2
      36: aload_1
      37: iconst_1
      38: invokeinterface #274,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      43: checkcast     #248                // class java/lang/String
      46: astore_3
      47: aload_3
      48: checkcast     #262                // class java/lang/CharSequence
      51: iconst_1
      52: anewarray     #248                // class java/lang/String
      55: astore        5
      57: aload         5
      59: iconst_0
      60: ldc_w         #276                // String ,
      63: aastore
      64: aload         5
      66: iconst_0
      67: iconst_0
      68: bipush        6
      70: aconst_null
      71: invokestatic  #270                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      74: checkcast     #135                // class java/lang/Iterable
      77: astore        5
      79: nop
      80: iconst_0
      81: istore        6
      83: aload         5
      85: astore        7
      87: new           #157                // class java/util/ArrayList
      90: dup
      91: aload         5
      93: bipush        10
      95: invokestatic  #243                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      98: invokespecial #246                // Method java/util/ArrayList."<init>":(I)V
     101: checkcast     #160                // class java/util/Collection
     104: astore        8
     106: iconst_0
     107: istore        9
     109: aload         7
     111: invokeinterface #164,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        10
     118: aload         10
     120: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          169
     128: aload         10
     130: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: astore        11
     137: aload         8
     139: aload         11
     141: checkcast     #248                // class java/lang/String
     144: astore        12
     146: astore        18
     148: iconst_0
     149: istore        13
     151: aload         12
     153: iconst_2
     154: invokestatic  #279                // Method kotlin/text/StringsKt.drop:(Ljava/lang/String;I)Ljava/lang/String;
     157: aload         18
     159: swap
     160: invokeinterface #178,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     165: pop
     166: goto          118
     169: aload         8
     171: checkcast     #123                // class java/util/List
     174: nop
     175: astore        4
     177: aload         4
     179: iconst_0
     180: invokeinterface #274,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     185: checkcast     #248                // class java/lang/String
     188: astore        5
     190: aload         4
     192: iconst_1
     193: invokeinterface #274,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     198: checkcast     #248                // class java/lang/String
     201: astore        6
     203: aload         4
     205: iconst_2
     206: invokeinterface #274,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     211: checkcast     #248                // class java/lang/String
     214: astore        7
     216: aload         5
     218: invokestatic  #283                // Method toBounds:(Ljava/lang/String;)Lkotlin/Pair;
     221: astore        8
     223: aload         8
     225: invokevirtual #150                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     228: checkcast     #285                // class java/lang/Number
     231: invokevirtual #288                // Method java/lang/Number.intValue:()I
     234: istore        9
     236: aload         8
     238: invokevirtual #152                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     241: checkcast     #285                // class java/lang/Number
     244: invokevirtual #288                // Method java/lang/Number.intValue:()I
     247: istore        10
     249: aload         6
     251: invokestatic  #283                // Method toBounds:(Ljava/lang/String;)Lkotlin/Pair;
     254: astore        11
     256: aload         11
     258: invokevirtual #150                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     261: checkcast     #285                // class java/lang/Number
     264: invokevirtual #288                // Method java/lang/Number.intValue:()I
     267: istore        12
     269: aload         11
     271: invokevirtual #152                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     274: checkcast     #285                // class java/lang/Number
     277: invokevirtual #288                // Method java/lang/Number.intValue:()I
     280: istore        13
     282: aload         7
     284: invokestatic  #283                // Method toBounds:(Ljava/lang/String;)Lkotlin/Pair;
     287: astore        14
     289: aload         14
     291: invokevirtual #150                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     294: checkcast     #285                // class java/lang/Number
     297: invokevirtual #288                // Method java/lang/Number.intValue:()I
     300: istore        15
     302: aload         14
     304: invokevirtual #152                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     307: checkcast     #285                // class java/lang/Number
     310: invokevirtual #288                // Method java/lang/Number.intValue:()I
     313: istore        16
     315: aload_2
     316: ldc_w         #290                // String on
     319: invokestatic  #296                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     322: istore        17
     324: new           #66                 // class day22/Cuboid
     327: dup
     328: iload         9
     330: iload         10
     332: iload         12
     334: iload         13
     336: iload         15
     338: iload         16
     340: iload         17
     342: invokespecial #299                // Method day22/Cuboid."<init>":(IIIIIIZ)V
     345: areturn

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> toBounds(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #262                // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #248                // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc_w         #317                // String ..
      14: aastore
      15: aload_1
      16: iconst_0
      17: iconst_0
      18: bipush        6
      20: aconst_null
      21: invokestatic  #270                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      24: checkcast     #135                // class java/lang/Iterable
      27: astore_1
      28: nop
      29: iconst_0
      30: istore_2
      31: aload_1
      32: astore_3
      33: new           #157                // class java/util/ArrayList
      36: dup
      37: aload_1
      38: bipush        10
      40: invokestatic  #243                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      43: invokespecial #246                // Method java/util/ArrayList."<init>":(I)V
      46: checkcast     #160                // class java/util/Collection
      49: astore        4
      51: iconst_0
      52: istore        5
      54: aload_3
      55: invokeinterface #164,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      60: astore        6
      62: aload         6
      64: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      69: ifeq          116
      72: aload         6
      74: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      79: astore        7
      81: aload         4
      83: aload         7
      85: checkcast     #248                // class java/lang/String
      88: astore        8
      90: astore        10
      92: iconst_0
      93: istore        9
      95: aload         8
      97: invokestatic  #323                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     100: nop
     101: invokestatic  #327                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: aload         10
     106: swap
     107: invokeinterface #178,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     112: pop
     113: goto          62
     116: aload         4
     118: checkcast     #123                // class java/util/List
     121: nop
     122: astore_2
     123: iconst_0
     124: istore_3
     125: aload_2
     126: iconst_0
     127: invokeinterface #274,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     132: checkcast     #285                // class java/lang/Number
     135: invokevirtual #288                // Method java/lang/Number.intValue:()I
     138: istore        4
     140: aload_2
     141: iconst_1
     142: invokeinterface #274,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     147: checkcast     #285                // class java/lang/Number
     150: invokevirtual #288                // Method java/lang/Number.intValue:()I
     153: istore        5
     155: iload         4
     157: invokestatic  #327                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     160: iload         5
     162: invokestatic  #327                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     165: invokestatic  #145                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     168: nop
     169: areturn

  private static final long part1(java.util.List<day22.Cuboid>);
    Code:
       0: aload_0
       1: checkcast     #135                // class java/lang/Iterable
       4: astore_1
       5: nop
       6: iconst_0
       7: istore_2
       8: aload_1
       9: astore_3
      10: new           #157                // class java/util/ArrayList
      13: dup
      14: invokespecial #158                // Method java/util/ArrayList."<init>":()V
      17: checkcast     #160                // class java/util/Collection
      20: astore        4
      22: iconst_0
      23: istore        5
      25: aload_3
      26: invokeinterface #164,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      31: astore        6
      33: aload         6
      35: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifeq          261
      43: aload         6
      45: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      50: astore        7
      52: aload         7
      54: checkcast     #66                 // class day22/Cuboid
      57: astore        8
      59: iconst_0
      60: istore        9
      62: aload         8
      64: invokevirtual #70                 // Method day22/Cuboid.component1:()I
      67: istore        10
      69: aload         8
      71: invokevirtual #73                 // Method day22/Cuboid.component2:()I
      74: istore        11
      76: aload         8
      78: invokevirtual #76                 // Method day22/Cuboid.component3:()I
      81: istore        12
      83: aload         8
      85: invokevirtual #79                 // Method day22/Cuboid.component4:()I
      88: istore        13
      90: aload         8
      92: invokevirtual #82                 // Method day22/Cuboid.component5:()I
      95: istore        14
      97: aload         8
      99: invokevirtual #85                 // Method day22/Cuboid.component6:()I
     102: istore        15
     104: bipush        6
     106: anewarray     #319                // class java/lang/Integer
     109: astore        16
     111: aload         16
     113: iconst_0
     114: iload         10
     116: invokestatic  #327                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     119: aastore
     120: aload         16
     122: iconst_1
     123: iload         11
     125: invokestatic  #327                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     128: aastore
     129: aload         16
     131: iconst_2
     132: iload         12
     134: invokestatic  #327                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     137: aastore
     138: aload         16
     140: iconst_3
     141: iload         13
     143: invokestatic  #327                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     146: aastore
     147: aload         16
     149: iconst_4
     150: iload         14
     152: invokestatic  #327                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     155: aastore
     156: aload         16
     158: iconst_5
     159: iload         15
     161: invokestatic  #327                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     164: aastore
     165: aload         16
     167: astore        16
     169: iconst_0
     170: istore        17
     172: iconst_0
     173: istore        18
     175: aload         16
     177: arraylength
     178: istore        19
     180: iload         18
     182: iload         19
     184: if_icmpge     243
     187: aload         16
     189: iload         18
     191: aaload
     192: astore        20
     194: aload         20
     196: checkcast     #285                // class java/lang/Number
     199: invokevirtual #288                // Method java/lang/Number.intValue:()I
     202: istore        21
     204: iconst_0
     205: istore        22
     207: bipush        -50
     209: iload         21
     211: if_icmpgt     229
     214: iload         21
     216: bipush        51
     218: if_icmpge     225
     221: iconst_1
     222: goto          230
     225: iconst_0
     226: goto          230
     229: iconst_0
     230: ifne          237
     233: iconst_0
     234: goto          244
     237: iinc          18, 1
     240: goto          180
     243: iconst_1
     244: nop
     245: ifeq          33
     248: aload         4
     250: aload         7
     252: invokeinterface #178,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     257: pop
     258: goto          33
     261: aload         4
     263: checkcast     #123                // class java/util/List
     266: nop
     267: astore_2
     268: iconst_0
     269: istore_3
     270: aload_2
     271: invokestatic  #184                // Method count:(Ljava/util/List;)J
     274: nop
     275: lreturn

  private static final long part2(java.util.List<day22.Cuboid>);
    Code:
       0: aload_0
       1: invokestatic  #184                // Method count:(Ljava/util/List;)J
       4: lreturn

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