package day05

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

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

    println("🎄 Day 05 🎄")

    println()

    println("[Part 1]")
    println("Answer: ${part1(data)}")

    println()

    println("[Part 2]")
    println("Answer: ${part2(data)}")
}

private data class Range(
    val start: Long,
    val end: Long,
)

private data class Mapping(
    val src: Range,
    val dst: Range,
)

private data class Almanac(
    val seeds: List<Long>,
    val transforms: List<List<Mapping>>,
)

private fun String.toMapping(): Mapping =
    this.split(" ")
        .map(String::toLong)
        .let { (dst, src, length) ->
            Mapping(
                Range(src, src + length - 1),
                Range(dst, dst + length - 1),
            )
        }

private fun parse(path: String): Almanac {
    val sections = File(path)
        .readText()
        .split("\n\n", "\r\n\r\n")

    val seeds = sections.first()
        .split(": ", " ")
        .mapNotNull(String::toLongOrNull)

    val maps = sections.asSequence()
        .drop(1)
        .map { it.split("\n", "\r\n") }
        .map { it.drop(1) }
        .map { it.map(String::toMapping) }
        .toList()

    return Almanac(seeds, maps)
}

private fun intersection(a: Range, b: Range): Range? =
    if (a.end < b.start || b.end < a.start) {
        null
    } else {
        Range(max(a.start, b.start), min(a.end, b.end))
    }

private fun part1(data: Almanac): Long {
    val (seeds, transforms) = data

    val values = seeds.toMutableList()
    for (mapping in transforms) {
        transforming@ for ((i, value) in values.withIndex()) {
            for ((src, dst) in mapping) {
                if (value in src.start..src.end) {
                    values[i] = dst.start + (value - src.start)
                    continue@transforming
                }
            }
        }
    }

    return values.min()
}

private fun part2(data: Almanac): Long {
    val (seeds, transforms) = data
    val ranges = seeds
        .chunked(2)
        .map { (start, length) -> Range(start, start + length - 1) }
        .toMutableList()

    for (mappings in transforms) {
        // List of ranges that already had a mapping applied to them. These are
        // stored separately because we don't want to transform the same range
        // multiple times within the same transformation "round".
        val transformed = mutableListOf<Range>()

        for ((src, dst) in mappings) {
            // We may need to break each range into multiple sub-ranges in case
            // the mapping only applies to its portion. This is the "unmapped"
            // parts of the split ranges to be re-used later.
            val remainders = mutableListOf<Range>()

            for (range in ranges) {
                val intersection = intersection(range, src)
                if (intersection == null) {
                    remainders.add(range)
                    continue
                }

                val offset = intersection.start - src.start
                val length = intersection.end - intersection.start
                transformed.add(Range(
                    dst.start + offset,
                    dst.start + offset + length,
                ))

                if (range.start < src.start) {
                    remainders.add(Range(range.start, src.start - 1))
                }
                if (range.end > src.end) {
                    remainders.add(Range(src.end + 1, range.end))
                }
            }

            ranges.clear()
            ranges.addAll(remainders)
        }

        ranges.addAll(transformed)
    }

    return ranges.minOf(Range::start)
}

Compiled from "Day05.kt"
public final class day05.Day05Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/day05/Day05.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Lday05/Almanac;
       5: astore_0
       6: ldc           #14                 // String 🎄 Day 05 🎄
       8: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      11: swap
      12: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      15: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      18: invokevirtual #28                 // Method java/io/PrintStream.println:()V
      21: ldc           #30                 // String [Part 1]
      23: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: swap
      27: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: new           #32                 // class java/lang/StringBuilder
      33: dup
      34: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      37: ldc           #37                 // String Answer:
      39: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: aload_0
      43: invokestatic  #45                 // Method part1:(Lday05/Almanac;)J
      46: invokevirtual #48                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      49: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      52: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      55: swap
      56: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      59: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: invokevirtual #28                 // Method java/io/PrintStream.println:()V
      65: ldc           #54                 // String [Part 2]
      67: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      70: swap
      71: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      74: new           #32                 // class java/lang/StringBuilder
      77: dup
      78: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      81: ldc           #37                 // String Answer:
      83: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      86: aload_0
      87: invokestatic  #57                 // Method part2:(Lday05/Almanac;)J
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      93: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      96: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      99: swap
     100: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: return

  private static final day05.Mapping toMapping(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #63                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #65                 // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc           #67                 // String
      13: aastore
      14: aload_1
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #73                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #75                 // class java/lang/Iterable
      26: astore_1
      27: nop
      28: iconst_0
      29: istore_2
      30: aload_1
      31: astore_3
      32: new           #77                 // class java/util/ArrayList
      35: dup
      36: aload_1
      37: bipush        10
      39: invokestatic  #83                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      42: invokespecial #86                 // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #88                 // class java/util/Collection
      48: astore        4
      50: iconst_0
      51: istore        5
      53: aload_3
      54: invokeinterface #92,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      59: astore        6
      61: aload         6
      63: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      68: ifeq          115
      71: aload         6
      73: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      78: astore        7
      80: aload         4
      82: aload         7
      84: checkcast     #65                 // class java/lang/String
      87: astore        8
      89: astore        10
      91: iconst_0
      92: istore        9
      94: aload         8
      96: invokestatic  #108                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      99: nop
     100: invokestatic  #112                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     103: aload         10
     105: swap
     106: invokeinterface #116,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     111: pop
     112: goto          61
     115: aload         4
     117: checkcast     #118                // class java/util/List
     120: nop
     121: astore_2
     122: iconst_0
     123: istore_3
     124: aload_2
     125: iconst_0
     126: invokeinterface #122,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     131: checkcast     #124                // class java/lang/Number
     134: invokevirtual #128                // Method java/lang/Number.longValue:()J
     137: lstore        4
     139: aload_2
     140: iconst_1
     141: invokeinterface #122,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     146: checkcast     #124                // class java/lang/Number
     149: invokevirtual #128                // Method java/lang/Number.longValue:()J
     152: lstore        6
     154: aload_2
     155: iconst_2
     156: invokeinterface #122,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     161: checkcast     #124                // class java/lang/Number
     164: invokevirtual #128                // Method java/lang/Number.longValue:()J
     167: lstore        8
     169: new           #130                // class day05/Mapping
     172: dup
     173: new           #132                // class day05/Range
     176: dup
     177: lload         6
     179: lload         6
     181: lload         8
     183: ladd
     184: lconst_1
     185: lsub
     186: invokespecial #135                // Method day05/Range."<init>":(JJ)V
     189: new           #132                // class day05/Range
     192: dup
     193: lload         4
     195: lload         4
     197: lload         8
     199: ladd
     200: lconst_1
     201: lsub
     202: invokespecial #135                // Method day05/Range."<init>":(JJ)V
     205: invokespecial #138                // Method day05/Mapping."<init>":(Lday05/Range;Lday05/Range;)V
     208: nop
     209: nop
     210: areturn

  private static final day05.Almanac parse(java.lang.String);
    Code:
       0: new           #159                // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #162                // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #168                // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      14: checkcast     #63                 // class java/lang/CharSequence
      17: iconst_2
      18: anewarray     #65                 // class java/lang/String
      21: astore_2
      22: aload_2
      23: iconst_0
      24: ldc           #170                // String \n\n
      26: aastore
      27: aload_2
      28: iconst_1
      29: ldc           #172                // String \r\n\r\n
      31: aastore
      32: aload_2
      33: iconst_0
      34: iconst_0
      35: bipush        6
      37: aconst_null
      38: invokestatic  #73                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      41: astore_1
      42: aload_1
      43: invokestatic  #176                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      46: checkcast     #63                 // class java/lang/CharSequence
      49: iconst_2
      50: anewarray     #65                 // class java/lang/String
      53: astore_3
      54: aload_3
      55: iconst_0
      56: ldc           #178                // String :
      58: aastore
      59: aload_3
      60: iconst_1
      61: ldc           #67                 // String
      63: aastore
      64: aload_3
      65: iconst_0
      66: iconst_0
      67: bipush        6
      69: aconst_null
      70: invokestatic  #73                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      73: checkcast     #75                 // class java/lang/Iterable
      76: astore_3
      77: nop
      78: iconst_0
      79: istore        4
      81: aload_3
      82: astore        5
      84: new           #77                 // class java/util/ArrayList
      87: dup
      88: invokespecial #179                // Method java/util/ArrayList."<init>":()V
      91: checkcast     #88                 // class java/util/Collection
      94: astore        6
      96: iconst_0
      97: istore        7
      99: aload         5
     101: astore        8
     103: iconst_0
     104: istore        9
     106: aload         8
     108: invokeinterface #92,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     113: astore        10
     115: aload         10
     117: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     122: ifeq          183
     125: aload         10
     127: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     132: astore        11
     134: aload         11
     136: astore        12
     138: iconst_0
     139: istore        13
     141: aload         12
     143: checkcast     #65                 // class java/lang/String
     146: astore        14
     148: iconst_0
     149: istore        15
     151: aload         14
     153: invokestatic  #183                // Method kotlin/text/StringsKt.toLongOrNull:(Ljava/lang/String;)Ljava/lang/Long;
     156: dup
     157: ifnull        178
     160: astore        16
     162: iconst_0
     163: istore        17
     165: aload         6
     167: aload         16
     169: invokeinterface #116,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     174: pop
     175: goto          179
     178: pop
     179: nop
     180: goto          115
     183: nop
     184: aload         6
     186: checkcast     #118                // class java/util/List
     189: nop
     190: astore_2
     191: aload_1
     192: checkcast     #75                 // class java/lang/Iterable
     195: invokestatic  #187                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     198: iconst_1
     199: invokestatic  #193                // Method kotlin/sequences/SequencesKt.drop:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
     202: invokedynamic #212,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     207: invokestatic  #216                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     210: invokedynamic #223,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
     215: invokestatic  #216                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     218: invokedynamic #228,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
     223: invokestatic  #216                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     226: invokestatic  #232                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     229: astore_3
     230: new           #234                // class day05/Almanac
     233: dup
     234: aload_2
     235: aload_3
     236: invokespecial #237                // Method day05/Almanac."<init>":(Ljava/util/List;Ljava/util/List;)V
     239: areturn

  private static final day05.Range intersection(day05.Range, day05.Range);
    Code:
       0: aload_0
       1: invokevirtual #261                // Method day05/Range.getEnd:()J
       4: aload_1
       5: invokevirtual #264                // Method day05/Range.getStart:()J
       8: lcmp
       9: iflt          24
      12: aload_1
      13: invokevirtual #261                // Method day05/Range.getEnd:()J
      16: aload_0
      17: invokevirtual #264                // Method day05/Range.getStart:()J
      20: lcmp
      21: ifge          28
      24: aconst_null
      25: goto          57
      28: new           #132                // class day05/Range
      31: dup
      32: aload_0
      33: invokevirtual #264                // Method day05/Range.getStart:()J
      36: aload_1
      37: invokevirtual #264                // Method day05/Range.getStart:()J
      40: invokestatic  #270                // Method java/lang/Math.max:(JJ)J
      43: aload_0
      44: invokevirtual #261                // Method day05/Range.getEnd:()J
      47: aload_1
      48: invokevirtual #261                // Method day05/Range.getEnd:()J
      51: invokestatic  #273                // Method java/lang/Math.min:(JJ)J
      54: invokespecial #135                // Method day05/Range."<init>":(JJ)V
      57: areturn

  private static final long part1(day05.Almanac);
    Code:
       0: aload_0
       1: invokevirtual #280                // Method day05/Almanac.component1:()Ljava/util/List;
       4: astore_1
       5: aload_0
       6: invokevirtual #283                // Method day05/Almanac.component2:()Ljava/util/List;
       9: astore_2
      10: aload_1
      11: checkcast     #88                 // class java/util/Collection
      14: invokestatic  #287                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      17: astore_3
      18: aload_2
      19: invokeinterface #288,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      24: astore        4
      26: aload         4
      28: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      33: ifeq          209
      36: aload         4
      38: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      43: checkcast     #118                // class java/util/List
      46: astore        5
      48: aload_3
      49: checkcast     #75                 // class java/lang/Iterable
      52: invokeinterface #92,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      57: astore        6
      59: iconst_0
      60: istore        7
      62: aload         6
      64: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      69: ifeq          26
      72: iload         7
      74: istore        8
      76: iload         7
      78: iconst_1
      79: iadd
      80: istore        7
      82: aload         6
      84: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      89: checkcast     #124                // class java/lang/Number
      92: invokevirtual #128                // Method java/lang/Number.longValue:()J
      95: lstore        9
      97: aload         5
      99: invokeinterface #288,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     104: astore        11
     106: aload         11
     108: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     113: ifeq          62
     116: aload         11
     118: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     123: checkcast     #130                // class day05/Mapping
     126: astore        12
     128: aload         12
     130: invokevirtual #291                // Method day05/Mapping.component1:()Lday05/Range;
     133: astore        13
     135: aload         12
     137: invokevirtual #293                // Method day05/Mapping.component2:()Lday05/Range;
     140: astore        14
     142: aload         13
     144: invokevirtual #264                // Method day05/Range.getStart:()J
     147: lstore        15
     149: lload         9
     151: aload         13
     153: invokevirtual #261                // Method day05/Range.getEnd:()J
     156: lcmp
     157: ifgt          176
     160: lload         15
     162: lload         9
     164: lcmp
     165: ifgt          172
     168: iconst_1
     169: goto          177
     172: iconst_0
     173: goto          177
     176: iconst_0
     177: ifeq          106
     180: aload_3
     181: iload         8
     183: aload         14
     185: invokevirtual #264                // Method day05/Range.getStart:()J
     188: lload         9
     190: aload         13
     192: invokevirtual #264                // Method day05/Range.getStart:()J
     195: lsub
     196: ladd
     197: invokestatic  #112                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     200: invokeinterface #297,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     205: pop
     206: goto          62
     209: aload_3
     210: checkcast     #75                 // class java/lang/Iterable
     213: invokestatic  #301                // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     216: checkcast     #124                // class java/lang/Number
     219: invokevirtual #128                // Method java/lang/Number.longValue:()J
     222: lreturn

  private static final long part2(day05.Almanac);
    Code:
       0: aload_0
       1: invokevirtual #280                // Method day05/Almanac.component1:()Ljava/util/List;
       4: astore_1
       5: aload_0
       6: invokevirtual #283                // Method day05/Almanac.component2:()Ljava/util/List;
       9: astore_2
      10: aload_1
      11: checkcast     #75                 // class java/lang/Iterable
      14: iconst_2
      15: invokestatic  #310                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
      18: checkcast     #75                 // class java/lang/Iterable
      21: astore        4
      23: nop
      24: iconst_0
      25: istore        5
      27: aload         4
      29: astore        6
      31: new           #77                 // class java/util/ArrayList
      34: dup
      35: aload         4
      37: bipush        10
      39: invokestatic  #83                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      42: invokespecial #86                 // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #88                 // class java/util/Collection
      48: astore        8
      50: iconst_0
      51: istore        10
      53: aload         6
      55: invokeinterface #92,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      60: astore        11
      62: aload         11
      64: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      69: ifeq          155
      72: aload         11
      74: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      79: astore        12
      81: aload         8
      83: aload         12
      85: checkcast     #118                // class java/util/List
      88: astore        13
      90: astore        21
      92: iconst_0
      93: istore        14
      95: aload         13
      97: iconst_0
      98: invokeinterface #122,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     103: checkcast     #124                // class java/lang/Number
     106: invokevirtual #128                // Method java/lang/Number.longValue:()J
     109: lstore        15
     111: aload         13
     113: iconst_1
     114: invokeinterface #122,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     119: checkcast     #124                // class java/lang/Number
     122: invokevirtual #128                // Method java/lang/Number.longValue:()J
     125: lstore        17
     127: new           #132                // class day05/Range
     130: dup
     131: lload         15
     133: lload         15
     135: lload         17
     137: ladd
     138: lconst_1
     139: lsub
     140: invokespecial #135                // Method day05/Range."<init>":(JJ)V
     143: aload         21
     145: swap
     146: invokeinterface #116,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     151: pop
     152: goto          62
     155: aload         8
     157: checkcast     #118                // class java/util/List
     160: nop
     161: checkcast     #88                 // class java/util/Collection
     164: invokestatic  #287                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     167: astore_3
     168: aload_2
     169: invokeinterface #288,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     174: astore        4
     176: aload         4
     178: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     183: ifeq          505
     186: aload         4
     188: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     193: checkcast     #118                // class java/util/List
     196: astore        5
     198: new           #77                 // class java/util/ArrayList
     201: dup
     202: invokespecial #179                // Method java/util/ArrayList."<init>":()V
     205: checkcast     #118                // class java/util/List
     208: astore        6
     210: aload         5
     212: invokeinterface #288,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     217: astore        8
     219: aload         8
     221: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     226: ifeq          490
     229: aload         8
     231: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     236: checkcast     #130                // class day05/Mapping
     239: astore        10
     241: aload         10
     243: invokevirtual #291                // Method day05/Mapping.component1:()Lday05/Range;
     246: astore        11
     248: aload         10
     250: invokevirtual #293                // Method day05/Mapping.component2:()Lday05/Range;
     253: astore        12
     255: new           #77                 // class java/util/ArrayList
     258: dup
     259: invokespecial #179                // Method java/util/ArrayList."<init>":()V
     262: checkcast     #118                // class java/util/List
     265: astore        13
     267: aload_3
     268: invokeinterface #288,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     273: astore        14
     275: aload         14
     277: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     282: ifeq          469
     285: aload         14
     287: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     292: checkcast     #132                // class day05/Range
     295: astore        15
     297: aload         15
     299: aload         11
     301: invokestatic  #312                // Method intersection:(Lday05/Range;Lday05/Range;)Lday05/Range;
     304: astore        16
     306: aload         16
     308: ifnonnull     324
     311: aload         13
     313: aload         15
     315: invokeinterface #313,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     320: pop
     321: goto          275
     324: aload         16
     326: invokevirtual #264                // Method day05/Range.getStart:()J
     329: aload         11
     331: invokevirtual #264                // Method day05/Range.getStart:()J
     334: lsub
     335: lstore        17
     337: aload         16
     339: invokevirtual #261                // Method day05/Range.getEnd:()J
     342: aload         16
     344: invokevirtual #264                // Method day05/Range.getStart:()J
     347: lsub
     348: lstore        19
     350: aload         6
     352: new           #132                // class day05/Range
     355: dup
     356: aload         12
     358: invokevirtual #264                // Method day05/Range.getStart:()J
     361: lload         17
     363: ladd
     364: aload         12
     366: invokevirtual #264                // Method day05/Range.getStart:()J
     369: lload         17
     371: ladd
     372: lload         19
     374: ladd
     375: invokespecial #135                // Method day05/Range."<init>":(JJ)V
     378: invokeinterface #313,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     383: pop
     384: aload         15
     386: invokevirtual #264                // Method day05/Range.getStart:()J
     389: aload         11
     391: invokevirtual #264                // Method day05/Range.getStart:()J
     394: lcmp
     395: ifge          425
     398: aload         13
     400: new           #132                // class day05/Range
     403: dup
     404: aload         15
     406: invokevirtual #264                // Method day05/Range.getStart:()J
     409: aload         11
     411: invokevirtual #264                // Method day05/Range.getStart:()J
     414: lconst_1
     415: lsub
     416: invokespecial #135                // Method day05/Range."<init>":(JJ)V
     419: invokeinterface #313,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     424: pop
     425: aload         15
     427: invokevirtual #261                // Method day05/Range.getEnd:()J
     430: aload         11
     432: invokevirtual #261                // Method day05/Range.getEnd:()J
     435: lcmp
     436: ifle          275
     439: aload         13
     441: new           #132                // class day05/Range
     444: dup
     445: aload         11
     447: invokevirtual #261                // Method day05/Range.getEnd:()J
     450: lconst_1
     451: ladd
     452: aload         15
     454: invokevirtual #261                // Method day05/Range.getEnd:()J
     457: invokespecial #135                // Method day05/Range."<init>":(JJ)V
     460: invokeinterface #313,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     465: pop
     466: goto          275
     469: aload_3
     470: invokeinterface #316,  1          // InterfaceMethod java/util/List.clear:()V
     475: aload_3
     476: aload         13
     478: checkcast     #88                 // class java/util/Collection
     481: invokeinterface #320,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     486: pop
     487: goto          219
     490: aload_3
     491: aload         6
     493: checkcast     #88                 // class java/util/Collection
     496: invokeinterface #320,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     501: pop
     502: goto          176
     505: aload_3
     506: checkcast     #75                 // class java/lang/Iterable
     509: invokeinterface #92,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     514: astore        5
     516: aload         5
     518: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     523: ifne          534
     526: new           #322                // class java/util/NoSuchElementException
     529: dup
     530: invokespecial #323                // Method java/util/NoSuchElementException."<init>":()V
     533: athrow
     534: aload         5
     536: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     541: checkcast     #132                // class day05/Range
     544: astore        6
     546: iconst_0
     547: istore        8
     549: aload         6
     551: invokevirtual #264                // Method day05/Range.getStart:()J
     554: lstore        6
     556: aload         5
     558: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     563: ifeq          603
     566: aload         5
     568: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     573: checkcast     #132                // class day05/Range
     576: astore        8
     578: iconst_0
     579: istore        10
     581: aload         8
     583: invokevirtual #264                // Method day05/Range.getStart:()J
     586: lstore        8
     588: lload         6
     590: lload         8
     592: lcmp
     593: ifle          556
     596: lload         8
     598: lstore        6
     600: goto          556
     603: lload         6
     605: lreturn

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

  private static final java.util.List parse$lambda$2(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #338                // String it
       4: invokestatic  #344                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #63                 // class java/lang/CharSequence
      11: iconst_2
      12: anewarray     #65                 // class java/lang/String
      15: astore_1
      16: aload_1
      17: iconst_0
      18: ldc_w         #346                // String \n
      21: aastore
      22: aload_1
      23: iconst_1
      24: ldc_w         #348                // String \r\n
      27: aastore
      28: aload_1
      29: iconst_0
      30: iconst_0
      31: bipush        6
      33: aconst_null
      34: invokestatic  #73                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      37: areturn

  private static final java.util.List parse$lambda$3(java.util.List);
    Code:
       0: aload_0
       1: ldc_w         #338                // String it
       4: invokestatic  #344                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #75                 // class java/lang/Iterable
      11: iconst_1
      12: invokestatic  #350                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      15: areturn

  private static final java.util.List parse$lambda$5(java.util.List);
    Code:
       0: aload_0
       1: ldc_w         #338                // String it
       4: invokestatic  #344                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #75                 // class java/lang/Iterable
      11: astore_1
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #77                 // class java/util/ArrayList
      19: dup
      20: aload_1
      21: bipush        10
      23: invokestatic  #83                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #86                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #88                 // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload_3
      38: invokeinterface #92,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        6
      45: aload         6
      47: invokeinterface #98,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          95
      55: aload         6
      57: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        7
      64: aload         4
      66: aload         7
      68: checkcast     #65                 // class java/lang/String
      71: astore        8
      73: astore        10
      75: iconst_0
      76: istore        9
      78: aload         8
      80: invokestatic  #352                // Method toMapping:(Ljava/lang/String;)Lday05/Mapping;
      83: aload         10
      85: swap
      86: invokeinterface #116,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: goto          45
      95: aload         4
      97: checkcast     #118                // class java/util/List
     100: nop
     101: areturn
}


package day18

import java.io.File

fun main() {
    val data = parse("src/day18/Day18.txt")

    println("🎄 Day 18 🎄")

    println()

    println("[Part 1]")
    println("Answer: ${part1(data)}")

    println()

    println("[Part 2]")
    println("Answer: ${part2(data)}")
}

enum class Direction {
    U, D, L, R
}

private data class Instruction(
    val direction: Direction,
    val distance: Int,
)

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

private fun solve(data: List<Instruction>): Long {
    val x = mutableListOf<Long>()
    val y = mutableListOf<Long>()

    var px = 0L
    var py = 0L

    for ((direction, meters) in data) {
        when (direction) {
            Direction.D -> py += meters
            Direction.U -> py -= meters
            Direction.L -> px -= meters
            Direction.R -> px += meters
        }

        x += px
        y += py
    }

    val area = (x.indices).sumOf { i ->
        val prev = if (i - 1 < 0) x.lastIndex else i - 1
        val next = if (i + 1 > x.lastIndex) 0 else i + 1
        x[i] * (y[next] - y[prev])
    } / 2

    val exterior = data.sumOf { it.distance }
    val interior = (area - (exterior / 2) + 1)

    return interior + exterior
}

private fun part1(data: List<String>): Long =
    solve(data.map { line ->
        val (directionPart, distancePart, _) = line.split(" ")
        val direction = when (directionPart) {
            "R" -> Direction.R
            "D" -> Direction.D
            "L" -> Direction.L
            "U" -> Direction.U
            else -> error("Invalid direction!")
        }

        val distance = distancePart.toInt()
        Instruction(direction, distance)
    })

private fun part2(data: List<String>): Long =
    solve(data.map { line ->
        val (_, _, colorPart) = line.split(" ")
        val color = colorPart.trim('(', ')', '#')

        val distance = color
            .substring(0, 5)
            .toInt(radix = 16)

        val direction = when (color.last()) {
            '0' -> Direction.R
            '1' -> Direction.D
            '2' -> Direction.L
            '3' -> Direction.U
            else -> error("Invalid direction!")
        }

        Instruction(direction, distance)
    })

Compiled from "Day18.kt"
public final class day18.Day18Kt$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method day18/Direction.values:()[Lday18/Direction;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field day18/Direction.D:Lday18/Direction;
      12: invokevirtual #22                 // Method day18/Direction.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field day18/Direction.U:Lday18/Direction;
      26: invokevirtual #22                 // Method day18/Direction.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field day18/Direction.L:Lday18/Direction;
      40: invokevirtual #22                 // Method day18/Direction.ordinal:()I
      43: iconst_3
      44: iastore
      45: goto          49
      48: astore_1
      49: nop
      50: aload_0
      51: getstatic     #31                 // Field day18/Direction.R:Lday18/Direction;
      54: invokevirtual #22                 // Method day18/Direction.ordinal:()I
      57: iconst_4
      58: iastore
      59: goto          63
      62: astore_1
      63: aload_0
      64: putstatic     #35                 // Field $EnumSwitchMapping$0:[I
      67: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
          35    45    48   Class java/lang/NoSuchFieldError
          49    59    62   Class java/lang/NoSuchFieldError
}

Compiled from "Day18.kt"
public final class day18.Day18Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/day18/Day18.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: ldc           #14                 // String 🎄 Day 18 🎄
       8: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      11: swap
      12: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      15: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      18: invokevirtual #28                 // Method java/io/PrintStream.println:()V
      21: ldc           #30                 // String [Part 1]
      23: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: swap
      27: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: new           #32                 // class java/lang/StringBuilder
      33: dup
      34: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      37: ldc           #37                 // String Answer:
      39: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: aload_0
      43: invokestatic  #45                 // Method part1:(Ljava/util/List;)J
      46: invokevirtual #48                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      49: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      52: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      55: swap
      56: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      59: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: invokevirtual #28                 // Method java/io/PrintStream.println:()V
      65: ldc           #54                 // String [Part 2]
      67: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      70: swap
      71: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      74: new           #32                 // class java/lang/StringBuilder
      77: dup
      78: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      81: ldc           #37                 // String Answer:
      83: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      86: aload_0
      87: invokestatic  #57                 // Method part2:(Ljava/util/List;)J
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      93: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      96: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      99: swap
     100: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: return

  private static final java.util.List<java.lang.String> parse(java.lang.String);
    Code:
       0: new           #62                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #65                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #71                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: areturn

  private static final long solve(java.util.List<day18.Instruction>);
    Code:
       0: new           #77                 // class java/util/ArrayList
       3: dup
       4: invokespecial #78                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #80                 // class java/util/List
      10: astore_1
      11: new           #77                 // class java/util/ArrayList
      14: dup
      15: invokespecial #78                 // Method java/util/ArrayList."<init>":()V
      18: checkcast     #80                 // class java/util/List
      21: astore_2
      22: lconst_0
      23: lstore_3
      24: lconst_0
      25: lstore        5
      27: aload_0
      28: invokeinterface #84,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      33: astore        7
      35: aload         7
      37: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          200
      45: aload         7
      47: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: checkcast     #96                 // class day18/Instruction
      55: astore        8
      57: aload         8
      59: invokevirtual #100                // Method day18/Instruction.component1:()Lday18/Direction;
      62: astore        9
      64: aload         8
      66: invokevirtual #104                // Method day18/Instruction.component2:()I
      69: istore        10
      71: aload         9
      73: getstatic     #110                // Field day18/Day18Kt$WhenMappings.$EnumSwitchMapping$0:[I
      76: swap
      77: invokevirtual #115                // Method day18/Direction.ordinal:()I
      80: iaload
      81: tableswitch   { // 1 to 4
                     1: 112
                     2: 123
                     3: 134
                     4: 143
               default: 152
          }
     112: lload         5
     114: iload         10
     116: i2l
     117: ladd
     118: lstore        5
     120: goto          160
     123: lload         5
     125: iload         10
     127: i2l
     128: lsub
     129: lstore        5
     131: goto          160
     134: lload_3
     135: iload         10
     137: i2l
     138: lsub
     139: lstore_3
     140: goto          160
     143: lload_3
     144: iload         10
     146: i2l
     147: ladd
     148: lstore_3
     149: goto          160
     152: new           #117                // class kotlin/NoWhenBranchMatchedException
     155: dup
     156: invokespecial #118                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     159: athrow
     160: lload_3
     161: invokestatic  #124                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     164: astore        12
     166: aload_1
     167: checkcast     #126                // class java/util/Collection
     170: aload         12
     172: invokeinterface #130,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     177: pop
     178: lload         5
     180: invokestatic  #124                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     183: astore        12
     185: aload_2
     186: checkcast     #126                // class java/util/Collection
     189: aload         12
     191: invokeinterface #130,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     196: pop
     197: goto          35
     200: aload_1
     201: checkcast     #126                // class java/util/Collection
     204: invokestatic  #136                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
     207: checkcast     #138                // class java/lang/Iterable
     210: astore        9
     212: lconst_0
     213: lstore        10
     215: aload         9
     217: invokeinterface #139,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     222: astore        12
     224: aload         12
     226: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     231: ifeq          352
     234: aload         12
     236: checkcast     #141                // class kotlin/collections/IntIterator
     239: invokevirtual #144                // Method kotlin/collections/IntIterator.nextInt:()I
     242: istore        13
     244: lload         10
     246: iload         13
     248: istore        14
     250: lstore        18
     252: iconst_0
     253: istore        15
     255: iload         14
     257: iconst_1
     258: isub
     259: ifge          269
     262: aload_1
     263: invokestatic  #148                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     266: goto          273
     269: iload         14
     271: iconst_1
     272: isub
     273: istore        16
     275: iload         14
     277: iconst_1
     278: iadd
     279: aload_1
     280: invokestatic  #148                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     283: if_icmple     290
     286: iconst_0
     287: goto          294
     290: iload         14
     292: iconst_1
     293: iadd
     294: istore        17
     296: aload_1
     297: iload         14
     299: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     304: checkcast     #154                // class java/lang/Number
     307: invokevirtual #158                // Method java/lang/Number.longValue:()J
     310: aload_2
     311: iload         17
     313: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     318: checkcast     #154                // class java/lang/Number
     321: invokevirtual #158                // Method java/lang/Number.longValue:()J
     324: aload_2
     325: iload         16
     327: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     332: checkcast     #154                // class java/lang/Number
     335: invokevirtual #158                // Method java/lang/Number.longValue:()J
     338: lsub
     339: lmul
     340: lstore        20
     342: lload         18
     344: lload         20
     346: ladd
     347: lstore        10
     349: goto          224
     352: lload         10
     354: iconst_2
     355: i2l
     356: ldiv
     357: lstore        7
     359: aload_0
     360: checkcast     #138                // class java/lang/Iterable
     363: astore        10
     365: iconst_0
     366: istore        11
     368: aload         10
     370: invokeinterface #139,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     375: astore        12
     377: aload         12
     379: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     384: ifeq          427
     387: aload         12
     389: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     394: astore        13
     396: iload         11
     398: aload         13
     400: checkcast     #96                 // class day18/Instruction
     403: astore        14
     405: istore        18
     407: iconst_0
     408: istore        15
     410: aload         14
     412: invokevirtual #161                // Method day18/Instruction.getDistance:()I
     415: istore        19
     417: iload         18
     419: iload         19
     421: iadd
     422: istore        11
     424: goto          377
     427: iload         11
     429: istore        9
     431: lload         7
     433: iload         9
     435: iconst_2
     436: idiv
     437: i2l
     438: lsub
     439: lconst_1
     440: ladd
     441: lstore        10
     443: lload         10
     445: iload         9
     447: i2l
     448: ladd
     449: lreturn

  private static final long part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #138                // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #77                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #184                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #187                // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #126                // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #139,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          297
      48: aload         6
      50: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #189                // class java/lang/String
      64: astore        8
      66: astore        15
      68: iconst_0
      69: istore        9
      71: aload         8
      73: checkcast     #191                // class java/lang/CharSequence
      76: iconst_1
      77: anewarray     #189                // class java/lang/String
      80: astore        10
      82: aload         10
      84: iconst_0
      85: ldc           #193                // String
      87: aastore
      88: aload         10
      90: iconst_0
      91: iconst_0
      92: bipush        6
      94: aconst_null
      95: invokestatic  #199                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      98: astore        11
     100: aload         11
     102: iconst_0
     103: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     108: checkcast     #189                // class java/lang/String
     111: astore        10
     113: aload         11
     115: iconst_1
     116: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     121: checkcast     #189                // class java/lang/String
     124: astore        12
     126: aload         10
     128: astore        13
     130: aload         13
     132: invokevirtual #202                // Method java/lang/String.hashCode:()I
     135: lookupswitch  { // 4
                    68: 189
                    76: 215
                    82: 176
                    85: 202
               default: 252
          }
     176: aload         13
     178: ldc           #204                // String R
     180: invokevirtual #207                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     183: ifne          228
     186: goto          252
     189: aload         13
     191: ldc           #209                // String D
     193: invokevirtual #207                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     196: ifne          234
     199: goto          252
     202: aload         13
     204: ldc           #211                // String U
     206: invokevirtual #207                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     209: ifne          246
     212: goto          252
     215: aload         13
     217: ldc           #213                // String L
     219: invokevirtual #207                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     222: ifne          240
     225: goto          252
     228: getstatic     #215                // Field day18/Direction.R:Lday18/Direction;
     231: goto          265
     234: getstatic     #217                // Field day18/Direction.D:Lday18/Direction;
     237: goto          265
     240: getstatic     #219                // Field day18/Direction.L:Lday18/Direction;
     243: goto          265
     246: getstatic     #221                // Field day18/Direction.U:Lday18/Direction;
     249: goto          265
     252: new           #223                // class java/lang/IllegalStateException
     255: dup
     256: ldc           #225                // String Invalid direction!
     258: invokevirtual #226                // Method java/lang/Object.toString:()Ljava/lang/String;
     261: invokespecial #227                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     264: athrow
     265: astore        14
     267: aload         12
     269: invokestatic  #233                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     272: istore        13
     274: new           #96                 // class day18/Instruction
     277: dup
     278: aload         14
     280: iload         13
     282: invokespecial #236                // Method day18/Instruction."<init>":(Lday18/Direction;I)V
     285: aload         15
     287: swap
     288: invokeinterface #130,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     293: pop
     294: goto          38
     297: aload         4
     299: checkcast     #80                 // class java/util/List
     302: nop
     303: invokestatic  #238                // Method solve:(Ljava/util/List;)J
     306: lreturn

  private static final long part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #138                // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #77                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #184                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #187                // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #126                // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #139,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          266
      48: aload         6
      50: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #189                // class java/lang/String
      64: astore        8
      66: astore        14
      68: iconst_0
      69: istore        9
      71: aload         8
      73: checkcast     #191                // class java/lang/CharSequence
      76: iconst_1
      77: anewarray     #189                // class java/lang/String
      80: astore        10
      82: aload         10
      84: iconst_0
      85: ldc           #193                // String
      87: aastore
      88: aload         10
      90: iconst_0
      91: iconst_0
      92: bipush        6
      94: aconst_null
      95: invokestatic  #199                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      98: iconst_2
      99: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     104: checkcast     #189                // class java/lang/String
     107: astore        10
     109: aload         10
     111: iconst_3
     112: newarray       char
     114: astore        11
     116: aload         11
     118: iconst_0
     119: bipush        40
     121: castore
     122: aload         11
     124: iconst_1
     125: bipush        41
     127: castore
     128: aload         11
     130: iconst_2
     131: bipush        35
     133: castore
     134: aload         11
     136: invokestatic  #256                // Method kotlin/text/StringsKt.trim:(Ljava/lang/String;[C)Ljava/lang/String;
     139: astore        12
     141: aload         12
     143: iconst_0
     144: iconst_5
     145: invokevirtual #260                // Method java/lang/String.substring:(II)Ljava/lang/String;
     148: dup
     149: ldc_w         #262                // String substring(...)
     152: invokestatic  #268                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     155: bipush        16
     157: invokestatic  #274                // Method kotlin/text/CharsKt.checkRadix:(I)I
     160: invokestatic  #277                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     163: istore        11
     165: aload         12
     167: checkcast     #191                // class java/lang/CharSequence
     170: invokestatic  #281                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     173: tableswitch   { // 48 to 51
                    48: 204
                    49: 210
                    50: 216
                    51: 222
               default: 228
          }
     204: getstatic     #215                // Field day18/Direction.R:Lday18/Direction;
     207: goto          241
     210: getstatic     #217                // Field day18/Direction.D:Lday18/Direction;
     213: goto          241
     216: getstatic     #219                // Field day18/Direction.L:Lday18/Direction;
     219: goto          241
     222: getstatic     #221                // Field day18/Direction.U:Lday18/Direction;
     225: goto          241
     228: new           #223                // class java/lang/IllegalStateException
     231: dup
     232: ldc           #225                // String Invalid direction!
     234: invokevirtual #226                // Method java/lang/Object.toString:()Ljava/lang/String;
     237: invokespecial #227                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     240: athrow
     241: astore        13
     243: new           #96                 // class day18/Instruction
     246: dup
     247: aload         13
     249: iload         11
     251: invokespecial #236                // Method day18/Instruction."<init>":(Lday18/Direction;I)V
     254: aload         14
     256: swap
     257: invokeinterface #130,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     262: pop
     263: goto          38
     266: aload         4
     268: checkcast     #80                 // class java/util/List
     271: nop
     272: invokestatic  #238                // Method solve:(Ljava/util/List;)J
     275: lreturn

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