package day07

import java.io.File

fun main() {
    val data = parse("src/day07/Day07.txt")

    println("🎄 Day 07 🎄")

    println()

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

    println()

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

private data class Hand(
    val cards: String,
    val bid: Int,
)

private fun String.toHand(): Hand {
    val (cards, bid) = split(" ")
    return Hand(cards, bid.toInt())
}

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

// From weakest to strongest.
private val HAND_TYPES = listOf(
    listOf(1, 1, 1, 1, 1),
    listOf(2, 1, 1, 1),
    listOf(2, 2, 1),
    listOf(3, 1, 1),
    listOf(3, 2),
    listOf(4, 1),
    listOf(5),
)

private val PART1_LETTER_MAPPINGS = mapOf(
    'T' to 0x9UL,
    'J' to 0xAUL,
    'Q' to 0xBUL,
    'K' to 0xCUL,
    'A' to 0xDUL,
)

private val PART2_LETTER_MAPPINGS = mapOf(
    'J' to 0x0UL,
    'T' to 0x9UL,
    'Q' to 0xAUL,
    'K' to 0xBUL,
    'A' to 0xCUL,
)

private fun String.toCode(mappings: Map<Char, ULong>): ULong =
    fold(0UL) { acc, card ->
        // If the card doesn't correspond to a letter, it must be a digit.
        (acc shl 4) or (mappings[card] ?: (card.digitToInt() - 1).toULong())
    }

private fun String.toFrequencies(): List<Int> =
    this.groupingBy { it }
        .eachCount()
        .values
        .sortedDescending()

private fun solve(data: List<Pair<ULong, Hand>>): Int =
    data.sortedBy { (code, _) -> code }
        .mapIndexed { index, (_, hand) -> (index + 1) * hand.bid }
        .sum()

private fun Hand.encoded1(): ULong {
    val code = cards.toCode(PART1_LETTER_MAPPINGS)
    val type = HAND_TYPES.indexOf(cards.toFrequencies())
    return (type shl 20).toULong() or code
}

private fun part1(data: List<Hand>): Int =
    solve(data.map { hand -> hand.encoded1() to hand })

private fun Hand.encoded2(): ULong {
    val code = cards.toCode(PART2_LETTER_MAPPINGS)
    val frequencies = cards
        .filter { it != 'J' }
        .toFrequencies()
        .toMutableList()

    val jokers = cards.count { it == 'J' }
    if (frequencies.size > 0) {
        frequencies[0] += jokers
    } else {
        frequencies.add(jokers)
    }

    val type = HAND_TYPES.indexOf(frequencies)
    return (type shl 20).toULong() or code
}

private fun part2(data: List<Hand>): Int =
    solve(data.map { hand -> hand.encoded2() to hand })

Compiled from "Day07.kt"
public final class day07.Day07Kt {
  private static final java.util.List<java.util.List<java.lang.Integer>> HAND_TYPES;

  private static final java.util.Map<java.lang.Character, kotlin.ULong> PART1_LETTER_MAPPINGS;

  private static final java.util.Map<java.lang.Character, kotlin.ULong> PART2_LETTER_MAPPINGS;

  public static final void main();
    Code:
       0: ldc           #8                  // String src/day07/Day07.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: ldc           #14                 // String 🎄 Day 07 🎄
       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;)I
      46: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)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;)I
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)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 day07.Hand toHand(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_2
       9: aload_2
      10: iconst_0
      11: ldc           #67                 // String
      13: aastore
      14: aload_2
      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: astore_1
      24: aload_1
      25: iconst_0
      26: invokeinterface #79,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      31: checkcast     #65                 // class java/lang/String
      34: astore_2
      35: aload_1
      36: iconst_1
      37: invokeinterface #79,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      42: checkcast     #65                 // class java/lang/String
      45: astore_3
      46: new           #81                 // class day07/Hand
      49: dup
      50: aload_2
      51: aload_3
      52: invokestatic  #87                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      55: invokespecial #90                 // Method day07/Hand."<init>":(Ljava/lang/String;I)V
      58: areturn

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

  private static final long toCode(java.lang.String, java.util.Map<java.lang.Character, kotlin.ULong>);
    Code:
       0: aload_0
       1: checkcast     #63                 // class java/lang/CharSequence
       4: astore_2
       5: lconst_0
       6: lstore_3
       7: iconst_0
       8: istore        5
      10: lload_3
      11: lstore        6
      13: iconst_0
      14: istore        8
      16: iload         8
      18: aload_2
      19: invokeinterface #161,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      24: if_icmpge     112
      27: aload_2
      28: iload         8
      30: invokeinterface #165,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      35: istore        9
      37: lload         6
      39: iload         9
      41: istore        10
      43: lstore        11
      45: iconst_0
      46: istore        13
      48: lload         11
      50: iconst_4
      51: lshl
      52: invokestatic  #171                // Method kotlin/ULong."constructor-impl":(J)J
      55: lstore        14
      57: aload_1
      58: iload         10
      60: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      63: invokeinterface #182,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      68: checkcast     #167                // class kotlin/ULong
      71: dup
      72: ifnull        81
      75: invokevirtual #186                // Method kotlin/ULong."unbox-impl":()J
      78: goto          93
      81: pop
      82: iload         10
      84: invokestatic  #192                // Method kotlin/text/CharsKt.digitToInt:(C)I
      87: iconst_1
      88: isub
      89: i2l
      90: invokestatic  #171                // Method kotlin/ULong."constructor-impl":(J)J
      93: lstore        16
      95: lload         14
      97: lload         16
      99: lor
     100: invokestatic  #171                // Method kotlin/ULong."constructor-impl":(J)J
     103: nop
     104: lstore        6
     106: iinc          8, 1
     109: goto          16
     112: lload         6
     114: lreturn

  private static final java.util.List<java.lang.Integer> toFrequencies(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #63                 // class java/lang/CharSequence
       4: astore_1
       5: iconst_0
       6: istore_2
       7: new           #210                // class day07/Day07Kt$toFrequencies$$inlined$groupingBy$1
      10: dup
      11: aload_1
      12: invokespecial #213                // Method day07/Day07Kt$toFrequencies$$inlined$groupingBy$1."<init>":(Ljava/lang/CharSequence;)V
      15: checkcast     #215                // class kotlin/collections/Grouping
      18: invokestatic  #221                // Method kotlin/collections/GroupingKt.eachCount:(Lkotlin/collections/Grouping;)Ljava/util/Map;
      21: invokeinterface #225,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      26: checkcast     #108                // class java/lang/Iterable
      29: invokestatic  #229                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
      32: areturn

  private static final int solve(java.util.List<kotlin.Pair<kotlin.ULong, day07.Hand>>);
    Code:
       0: aload_0
       1: checkcast     #108                // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: new           #236                // class day07/Day07Kt$solve$$inlined$sortedBy$1
      11: dup
      12: invokespecial #237                // Method day07/Day07Kt$solve$$inlined$sortedBy$1."<init>":()V
      15: checkcast     #239                // class java/util/Comparator
      18: invokestatic  #243                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
      21: checkcast     #108                // class java/lang/Iterable
      24: astore_1
      25: nop
      26: iconst_0
      27: istore_2
      28: aload_1
      29: astore_3
      30: new           #110                // class java/util/ArrayList
      33: dup
      34: aload_1
      35: bipush        10
      37: invokestatic  #116                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      40: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
      43: checkcast     #121                // class java/util/Collection
      46: astore        4
      48: iconst_0
      49: istore        5
      51: iconst_0
      52: istore        6
      54: aload_3
      55: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      60: astore        7
      62: aload         7
      64: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      69: ifeq          149
      72: aload         7
      74: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      79: astore        8
      81: aload         4
      83: iload         6
      85: iinc          6, 1
      88: istore        9
      90: iload         9
      92: ifge          98
      95: invokestatic  #246                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      98: iload         9
     100: aload         8
     102: checkcast     #248                // class kotlin/Pair
     105: astore        10
     107: istore        11
     109: astore        14
     111: iconst_0
     112: istore        12
     114: aload         10
     116: invokevirtual #251                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     119: checkcast     #81                 // class day07/Hand
     122: astore        13
     124: iload         11
     126: iconst_1
     127: iadd
     128: aload         13
     130: invokevirtual #254                // Method day07/Hand.getBid:()I
     133: imul
     134: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     137: aload         14
     139: swap
     140: invokeinterface #141,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     145: pop
     146: goto          62
     149: aload         4
     151: checkcast     #75                 // class java/util/List
     154: nop
     155: checkcast     #108                // class java/lang/Iterable
     158: invokestatic  #261                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     161: ireturn

  private static final long encoded1(day07.Hand);
    Code:
       0: aload_0
       1: invokevirtual #277                // Method day07/Hand.getCards:()Ljava/lang/String;
       4: getstatic     #280                // Field PART1_LETTER_MAPPINGS:Ljava/util/Map;
       7: invokestatic  #282                // Method toCode:(Ljava/lang/String;Ljava/util/Map;)J
      10: lstore_1
      11: getstatic     #285                // Field HAND_TYPES:Ljava/util/List;
      14: aload_0
      15: invokevirtual #277                // Method day07/Hand.getCards:()Ljava/lang/String;
      18: invokestatic  #287                // Method toFrequencies:(Ljava/lang/String;)Ljava/util/List;
      21: invokeinterface #291,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
      26: istore_3
      27: nop
      28: iload_3
      29: bipush        20
      31: ishl
      32: i2l
      33: invokestatic  #171                // Method kotlin/ULong."constructor-impl":(J)J
      36: lload_1
      37: lor
      38: invokestatic  #171                // Method kotlin/ULong."constructor-impl":(J)J
      41: lreturn

  private static final int part1(java.util.List<day07.Hand>);
    Code:
       0: aload_0
       1: checkcast     #108                // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #110                // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #116                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #121                // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          96
      48: aload         6
      50: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #81                 // class day07/Hand
      64: astore        8
      66: astore        10
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokestatic  #297                // Method encoded1:(Lday07/Hand;)J
      76: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
      79: aload         8
      81: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      84: aload         10
      86: swap
      87: invokeinterface #141,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      92: pop
      93: goto          38
      96: aload         4
      98: checkcast     #75                 // class java/util/List
     101: nop
     102: invokestatic  #309                // Method solve:(Ljava/util/List;)I
     105: ireturn

  private static final long encoded2(day07.Hand);
    Code:
       0: aload_0
       1: invokevirtual #277                // Method day07/Hand.getCards:()Ljava/lang/String;
       4: getstatic     #314                // Field PART2_LETTER_MAPPINGS:Ljava/util/Map;
       7: invokestatic  #282                // Method toCode:(Ljava/lang/String;Ljava/util/Map;)J
      10: lstore_1
      11: aload_0
      12: invokevirtual #277                // Method day07/Hand.getCards:()Ljava/lang/String;
      15: astore        4
      17: nop
      18: iconst_0
      19: istore        5
      21: aload         4
      23: checkcast     #63                 // class java/lang/CharSequence
      26: astore        6
      28: new           #32                 // class java/lang/StringBuilder
      31: dup
      32: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      35: checkcast     #316                // class java/lang/Appendable
      38: astore        7
      40: iconst_0
      41: istore        8
      43: iconst_0
      44: istore        9
      46: aload         6
      48: invokeinterface #161,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      53: istore        10
      55: iload         9
      57: iload         10
      59: if_icmpge     111
      62: aload         6
      64: iload         9
      66: invokeinterface #165,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      71: istore        11
      73: iload         11
      75: istore        12
      77: iconst_0
      78: istore        13
      80: iload         12
      82: bipush        74
      84: if_icmpeq     91
      87: iconst_1
      88: goto          92
      91: iconst_0
      92: ifeq          105
      95: aload         7
      97: iload         11
      99: invokeinterface #319,  2          // InterfaceMethod java/lang/Appendable.append:(C)Ljava/lang/Appendable;
     104: pop
     105: iinc          9, 1
     108: goto          55
     111: aload         7
     113: checkcast     #32                 // class java/lang/StringBuilder
     116: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     119: invokestatic  #287                // Method toFrequencies:(Ljava/lang/String;)Ljava/util/List;
     122: checkcast     #121                // class java/util/Collection
     125: invokestatic  #323                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     128: astore_3
     129: aload_0
     130: invokevirtual #277                // Method day07/Hand.getCards:()Ljava/lang/String;
     133: checkcast     #63                 // class java/lang/CharSequence
     136: astore        5
     138: iconst_0
     139: istore        6
     141: iconst_0
     142: istore        7
     144: iconst_0
     145: istore        8
     147: iload         8
     149: aload         5
     151: invokeinterface #161,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     156: if_icmpge     201
     159: aload         5
     161: iload         8
     163: invokeinterface #165,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     168: istore        9
     170: iload         9
     172: istore        10
     174: iconst_0
     175: istore        11
     177: iload         10
     179: bipush        74
     181: if_icmpne     188
     184: iconst_1
     185: goto          189
     188: iconst_0
     189: ifeq          195
     192: iinc          7, 1
     195: iinc          8, 1
     198: goto          147
     201: iload         7
     203: istore        4
     205: aload_3
     206: invokeinterface #326,  1          // InterfaceMethod java/util/List.size:()I
     211: ifle          244
     214: aload_3
     215: iconst_0
     216: aload_3
     217: iconst_0
     218: invokeinterface #79,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     223: checkcast     #328                // class java/lang/Number
     226: invokevirtual #331                // Method java/lang/Number.intValue:()I
     229: iload         4
     231: iadd
     232: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     235: invokeinterface #335,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     240: pop
     241: goto          256
     244: aload_3
     245: iload         4
     247: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     250: invokeinterface #336,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     255: pop
     256: getstatic     #285                // Field HAND_TYPES:Ljava/util/List;
     259: aload_3
     260: invokeinterface #291,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     265: istore        5
     267: nop
     268: iload         5
     270: bipush        20
     272: ishl
     273: i2l
     274: invokestatic  #171                // Method kotlin/ULong."constructor-impl":(J)J
     277: lload_1
     278: lor
     279: invokestatic  #171                // Method kotlin/ULong."constructor-impl":(J)J
     282: lreturn

  private static final int part2(java.util.List<day07.Hand>);
    Code:
       0: aload_0
       1: checkcast     #108                // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #110                // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #116                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #121                // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          96
      48: aload         6
      50: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #81                 // class day07/Hand
      64: astore        8
      66: astore        10
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokestatic  #353                // Method encoded2:(Lday07/Hand;)J
      76: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
      79: aload         8
      81: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      84: aload         10
      86: swap
      87: invokeinterface #141,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      92: pop
      93: goto          38
      96: aload         4
      98: checkcast     #75                 // class java/util/List
     101: nop
     102: invokestatic  #309                // Method solve:(Ljava/util/List;)I
     105: ireturn

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

  static {};
    Code:
       0: bipush        7
       2: anewarray     #75                 // class java/util/List
       5: astore_0
       6: aload_0
       7: iconst_0
       8: iconst_5
       9: anewarray     #83                 // class java/lang/Integer
      12: astore_1
      13: aload_1
      14: iconst_0
      15: iconst_1
      16: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      19: aastore
      20: aload_1
      21: iconst_1
      22: iconst_1
      23: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      26: aastore
      27: aload_1
      28: iconst_2
      29: iconst_1
      30: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: aastore
      34: aload_1
      35: iconst_3
      36: iconst_1
      37: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: aastore
      41: aload_1
      42: iconst_4
      43: iconst_1
      44: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: aastore
      48: aload_1
      49: invokestatic  #364                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      52: aastore
      53: aload_0
      54: iconst_1
      55: iconst_4
      56: anewarray     #83                 // class java/lang/Integer
      59: astore_1
      60: aload_1
      61: iconst_0
      62: iconst_2
      63: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: aastore
      67: aload_1
      68: iconst_1
      69: iconst_1
      70: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      73: aastore
      74: aload_1
      75: iconst_2
      76: iconst_1
      77: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aastore
      81: aload_1
      82: iconst_3
      83: iconst_1
      84: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      87: aastore
      88: aload_1
      89: invokestatic  #364                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      92: aastore
      93: aload_0
      94: iconst_2
      95: iconst_3
      96: anewarray     #83                 // class java/lang/Integer
      99: astore_1
     100: aload_1
     101: iconst_0
     102: iconst_2
     103: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: aastore
     107: aload_1
     108: iconst_1
     109: iconst_2
     110: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     113: aastore
     114: aload_1
     115: iconst_2
     116: iconst_1
     117: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     120: aastore
     121: aload_1
     122: invokestatic  #364                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     125: aastore
     126: aload_0
     127: iconst_3
     128: iconst_3
     129: anewarray     #83                 // class java/lang/Integer
     132: astore_1
     133: aload_1
     134: iconst_0
     135: iconst_3
     136: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     139: aastore
     140: aload_1
     141: iconst_1
     142: iconst_1
     143: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     146: aastore
     147: aload_1
     148: iconst_2
     149: iconst_1
     150: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     153: aastore
     154: aload_1
     155: invokestatic  #364                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     158: aastore
     159: aload_0
     160: iconst_4
     161: iconst_2
     162: anewarray     #83                 // class java/lang/Integer
     165: astore_1
     166: aload_1
     167: iconst_0
     168: iconst_3
     169: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     172: aastore
     173: aload_1
     174: iconst_1
     175: iconst_2
     176: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     179: aastore
     180: aload_1
     181: invokestatic  #364                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     184: aastore
     185: aload_0
     186: iconst_5
     187: iconst_2
     188: anewarray     #83                 // class java/lang/Integer
     191: astore_1
     192: aload_1
     193: iconst_0
     194: iconst_4
     195: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     198: aastore
     199: aload_1
     200: iconst_1
     201: iconst_1
     202: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     205: aastore
     206: aload_1
     207: invokestatic  #364                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     210: aastore
     211: aload_0
     212: bipush        6
     214: iconst_5
     215: invokestatic  #257                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     218: invokestatic  #367                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     221: aastore
     222: aload_0
     223: invokestatic  #364                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     226: putstatic     #285                // Field HAND_TYPES:Ljava/util/List;
     229: iconst_5
     230: anewarray     #248                // class kotlin/Pair
     233: astore_0
     234: aload_0
     235: iconst_0
     236: bipush        84
     238: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     241: ldc2_w        #368                // long 9l
     244: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     247: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     250: aastore
     251: aload_0
     252: iconst_1
     253: bipush        74
     255: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     258: ldc2_w        #370                // long 10l
     261: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     264: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     267: aastore
     268: aload_0
     269: iconst_2
     270: bipush        81
     272: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     275: ldc2_w        #372                // long 11l
     278: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     281: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     284: aastore
     285: aload_0
     286: iconst_3
     287: bipush        75
     289: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     292: ldc2_w        #374                // long 12l
     295: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     298: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     301: aastore
     302: aload_0
     303: iconst_4
     304: bipush        65
     306: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     309: ldc2_w        #376                // long 13l
     312: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     315: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     318: aastore
     319: aload_0
     320: invokestatic  #383                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     323: putstatic     #280                // Field PART1_LETTER_MAPPINGS:Ljava/util/Map;
     326: iconst_5
     327: anewarray     #248                // class kotlin/Pair
     330: astore_0
     331: aload_0
     332: iconst_0
     333: bipush        74
     335: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     338: lconst_0
     339: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     342: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     345: aastore
     346: aload_0
     347: iconst_1
     348: bipush        84
     350: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     353: ldc2_w        #368                // long 9l
     356: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     359: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     362: aastore
     363: aload_0
     364: iconst_2
     365: bipush        81
     367: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     370: ldc2_w        #370                // long 10l
     373: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     376: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     379: aastore
     380: aload_0
     381: iconst_3
     382: bipush        75
     384: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     387: ldc2_w        #372                // long 11l
     390: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     393: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     396: aastore
     397: aload_0
     398: iconst_4
     399: bipush        65
     401: invokestatic  #177                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     404: ldc2_w        #374                // long 12l
     407: invokestatic  #301                // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
     410: invokestatic  #307                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     413: aastore
     414: aload_0
     415: invokestatic  #383                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     418: putstatic     #314                // Field PART2_LETTER_MAPPINGS:Ljava/util/Map;
     421: return
}

Compiled from "Comparisons.kt"
public final class day07.Day07Kt$solve$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public day07.Day07Kt$solve$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class kotlin/Pair
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
      12: checkcast     #29                 // class kotlin/ULong
      15: invokevirtual #33                 // Method kotlin/ULong."unbox-impl":()J
      18: lstore        5
      20: lload         5
      22: invokestatic  #37                 // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
      25: checkcast     #39                 // class java/lang/Comparable
      28: aload_2
      29: checkcast     #23                 // class kotlin/Pair
      32: astore_3
      33: astore        7
      35: iconst_0
      36: istore        4
      38: aload_3
      39: invokevirtual #27                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
      42: checkcast     #29                 // class kotlin/ULong
      45: invokevirtual #33                 // Method kotlin/ULong."unbox-impl":()J
      48: lstore        5
      50: lload         5
      52: invokestatic  #37                 // Method kotlin/ULong."box-impl":(J)Lkotlin/ULong;
      55: aload         7
      57: swap
      58: checkcast     #39                 // class java/lang/Comparable
      61: invokestatic  #45                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      64: ireturn
}

Compiled from "_Strings.kt"
public final class day07.Day07Kt$toFrequencies$$inlined$groupingBy$1 implements kotlin.collections.Grouping<java.lang.Character, java.lang.Character> {
  final java.lang.CharSequence $this_groupingBy;

  public day07.Day07Kt$toFrequencies$$inlined$groupingBy$1(java.lang.CharSequence);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_groupingBy:Ljava/lang/CharSequence;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public java.util.Iterator<java.lang.Character> sourceIterator();
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_groupingBy:Ljava/lang/CharSequence;
       4: invokestatic  #33                 // Method kotlin/text/StringsKt.iterator:(Ljava/lang/CharSequence;)Lkotlin/collections/CharIterator;
       7: checkcast     #35                 // class java/util/Iterator
      10: areturn

  public java.lang.Character keyOf(char);
    Code:
       0: iload_1
       1: istore_2
       2: iconst_0
       3: istore_3
       4: iload_2
       5: invokestatic  #43                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
       8: areturn

  public java.lang.Object keyOf(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #40                 // class java/lang/Character
       5: invokevirtual #53                 // Method java/lang/Character.charValue:()C
       8: invokevirtual #55                 // Method keyOf:(C)Ljava/lang/Object;
      11: areturn
}


package day09

import java.io.File

fun main() {
    val data = parse("src/day09/Day09.txt")

    println("🎄 Day 09 🎄")

    println()

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

    println()

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

private fun parse(path: String): List<List<Int>> =
    File(path)
        .readLines()
        .map { it.split(" ").map(String::toInt) }

private fun part1(data: List<List<Int>>): Int =
    data.sumOf { history ->
        generateSequence(history) { it.zipWithNext { a, b -> b - a } }
            .takeWhile { !it.all { diff -> diff == 0 } }
            .sumOf { it.last() }
    }

private fun part2(data: List<List<Int>>): Int =
    data.sumOf { history ->
        generateSequence(history) { it.zipWithNext { a, b -> b - a } }
            .takeWhile { !it.all { diff -> diff == 0 } }
            .toList()
            .foldRight(0) { it, acc -> it.first() - acc }.toInt()
    }

Compiled from "Day09.kt"
public final class day09.Day09Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/day09/Day09.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: ldc           #14                 // String 🎄 Day 09 🎄
       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;)I
      46: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)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;)I
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)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.util.List<java.lang.Integer>> 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: checkcast     #73                 // class java/lang/Iterable
      17: astore_1
      18: nop
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #75                 // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #81                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #84                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #86                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          228
      62: aload         6
      64: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         4
      73: aload         7
      75: checkcast     #102                // class java/lang/String
      78: astore        8
      80: astore        20
      82: iconst_0
      83: istore        9
      85: aload         8
      87: checkcast     #104                // class java/lang/CharSequence
      90: iconst_1
      91: anewarray     #102                // class java/lang/String
      94: astore        10
      96: aload         10
      98: iconst_0
      99: ldc           #106                // String
     101: aastore
     102: aload         10
     104: iconst_0
     105: iconst_0
     106: bipush        6
     108: aconst_null
     109: invokestatic  #112                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     112: checkcast     #73                 // class java/lang/Iterable
     115: astore        10
     117: iconst_0
     118: istore        11
     120: aload         10
     122: astore        12
     124: new           #75                 // class java/util/ArrayList
     127: dup
     128: aload         10
     130: bipush        10
     132: invokestatic  #81                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     135: invokespecial #84                 // Method java/util/ArrayList."<init>":(I)V
     138: checkcast     #86                 // class java/util/Collection
     141: astore        13
     143: iconst_0
     144: istore        14
     146: aload         12
     148: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     153: astore        15
     155: aload         15
     157: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     162: ifeq          209
     165: aload         15
     167: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     172: astore        16
     174: aload         13
     176: aload         16
     178: checkcast     #102                // class java/lang/String
     181: astore        17
     183: astore        18
     185: iconst_0
     186: istore        19
     188: aload         17
     190: invokestatic  #118                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     193: nop
     194: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     197: aload         18
     199: swap
     200: invokeinterface #126,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     205: pop
     206: goto          155
     209: aload         13
     211: checkcast     #128                // class java/util/List
     214: nop
     215: nop
     216: aload         20
     218: swap
     219: invokeinterface #126,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     224: pop
     225: goto          52
     228: aload         4
     230: checkcast     #128                // class java/util/List
     233: nop
     234: areturn

  private static final int part1(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: aload_0
       1: checkcast     #73                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      13: astore_3
      14: aload_3
      15: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      20: ifeq          146
      23: aload_3
      24: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      29: astore        4
      31: iload_2
      32: aload         4
      34: checkcast     #128                // class java/util/List
      37: astore        5
      39: istore        15
      41: iconst_0
      42: istore        6
      44: aload         5
      46: invokedynamic #164,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      51: invokestatic  #170                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      54: invokedynamic #178,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      59: invokestatic  #182                // Method kotlin/sequences/SequencesKt.takeWhile:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      62: astore        7
      64: iconst_0
      65: istore        8
      67: aload         7
      69: invokeinterface #185,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      74: astore        9
      76: aload         9
      78: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      83: ifeq          132
      86: aload         9
      88: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      93: astore        10
      95: iload         8
      97: aload         10
      99: checkcast     #128                // class java/util/List
     102: astore        11
     104: istore        12
     106: iconst_0
     107: istore        13
     109: aload         11
     111: invokestatic  #189                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     114: checkcast     #191                // class java/lang/Number
     117: invokevirtual #195                // Method java/lang/Number.intValue:()I
     120: istore        14
     122: iload         12
     124: iload         14
     126: iadd
     127: istore        8
     129: goto          76
     132: iload         8
     134: nop
     135: istore        16
     137: iload         15
     139: iload         16
     141: iadd
     142: istore_2
     143: goto          14
     146: iload_2
     147: ireturn

  private static final int part2(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: aload_0
       1: checkcast     #73                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      13: astore_3
      14: aload_3
      15: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      20: ifeq          165
      23: aload_3
      24: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      29: astore        4
      31: iload_2
      32: aload         4
      34: checkcast     #128                // class java/util/List
      37: astore        5
      39: istore        15
      41: iconst_0
      42: istore        6
      44: aload         5
      46: invokedynamic #203,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
      51: invokestatic  #170                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      54: invokedynamic #208,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function1;
      59: invokestatic  #182                // Method kotlin/sequences/SequencesKt.takeWhile:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      62: invokestatic  #212                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      65: astore        7
      67: iconst_0
      68: istore        8
      70: iconst_0
      71: istore        9
      73: iload         8
      75: istore        10
      77: aload         7
      79: invokeinterface #215,  1          // InterfaceMethod java/util/List.isEmpty:()Z
      84: ifne          151
      87: aload         7
      89: aload         7
      91: invokeinterface #218,  1          // InterfaceMethod java/util/List.size:()I
      96: invokeinterface #222,  2          // InterfaceMethod java/util/List.listIterator:(I)Ljava/util/ListIterator;
     101: astore        11
     103: aload         11
     105: invokeinterface #227,  1          // InterfaceMethod java/util/ListIterator.hasPrevious:()Z
     110: ifeq          151
     113: aload         11
     115: invokeinterface #230,  1          // InterfaceMethod java/util/ListIterator.previous:()Ljava/lang/Object;
     120: iload         10
     122: istore        12
     124: checkcast     #128                // class java/util/List
     127: astore        13
     129: iconst_0
     130: istore        14
     132: aload         13
     134: invokestatic  #233                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     137: checkcast     #191                // class java/lang/Number
     140: invokevirtual #195                // Method java/lang/Number.intValue:()I
     143: iload         12
     145: isub
     146: istore        10
     148: goto          103
     151: iload         10
     153: nop
     154: istore        16
     156: iload         15
     158: iload         16
     160: iadd
     161: istore_2
     162: goto          14
     165: iload_2
     166: ireturn

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

  private static final java.util.List part1$lambda$6$lambda$2(java.util.List);
    Code:
       0: aload_0
       1: ldc           #248                // String it
       3: invokestatic  #254                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #73                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifne          35
      29: invokestatic  #258                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      32: goto          125
      35: new           #75                 // class java/util/ArrayList
      38: dup
      39: invokespecial #259                // Method java/util/ArrayList."<init>":()V
      42: checkcast     #128                // class java/util/List
      45: astore        4
      47: aload_3
      48: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        5
      55: aload_3
      56: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          123
      64: aload_3
      65: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        6
      72: aload         4
      74: aload         5
      76: aload         6
      78: checkcast     #191                // class java/lang/Number
      81: invokevirtual #195                // Method java/lang/Number.intValue:()I
      84: istore        7
      86: checkcast     #191                // class java/lang/Number
      89: invokevirtual #195                // Method java/lang/Number.intValue:()I
      92: istore        8
      94: astore        10
      96: iconst_0
      97: istore        9
      99: iload         7
     101: iload         8
     103: isub
     104: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     107: aload         10
     109: swap
     110: invokeinterface #260,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     115: pop
     116: aload         6
     118: astore        5
     120: goto          55
     123: aload         4
     125: areturn

  private static final boolean part1$lambda$6$lambda$4(java.util.List);
    Code:
       0: aload_0
       1: ldc           #248                // String it
       3: invokestatic  #254                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #73                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: instanceof    #86                 // class java/util/Collection
      17: ifeq          36
      20: aload_1
      21: checkcast     #86                 // class java/util/Collection
      24: invokeinterface #270,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      29: ifeq          36
      32: iconst_1
      33: goto          91
      36: aload_1
      37: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore_3
      43: aload_3
      44: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          90
      52: aload_3
      53: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        4
      60: aload         4
      62: checkcast     #191                // class java/lang/Number
      65: invokevirtual #195                // Method java/lang/Number.intValue:()I
      68: istore        5
      70: iconst_0
      71: istore        6
      73: iload         5
      75: ifne          82
      78: iconst_1
      79: goto          83
      82: iconst_0
      83: ifne          43
      86: iconst_0
      87: goto          91
      90: iconst_1
      91: ifne          98
      94: iconst_1
      95: goto          99
      98: iconst_0
      99: ireturn

  private static final java.util.List part2$lambda$12$lambda$8(java.util.List);
    Code:
       0: aload_0
       1: ldc           #248                // String it
       3: invokestatic  #254                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #73                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifne          35
      29: invokestatic  #258                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      32: goto          125
      35: new           #75                 // class java/util/ArrayList
      38: dup
      39: invokespecial #259                // Method java/util/ArrayList."<init>":()V
      42: checkcast     #128                // class java/util/List
      45: astore        4
      47: aload_3
      48: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        5
      55: aload_3
      56: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          123
      64: aload_3
      65: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        6
      72: aload         4
      74: aload         5
      76: aload         6
      78: checkcast     #191                // class java/lang/Number
      81: invokevirtual #195                // Method java/lang/Number.intValue:()I
      84: istore        7
      86: checkcast     #191                // class java/lang/Number
      89: invokevirtual #195                // Method java/lang/Number.intValue:()I
      92: istore        8
      94: astore        10
      96: iconst_0
      97: istore        9
      99: iload         7
     101: iload         8
     103: isub
     104: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     107: aload         10
     109: swap
     110: invokeinterface #260,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     115: pop
     116: aload         6
     118: astore        5
     120: goto          55
     123: aload         4
     125: areturn

  private static final boolean part2$lambda$12$lambda$10(java.util.List);
    Code:
       0: aload_0
       1: ldc           #248                // String it
       3: invokestatic  #254                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #73                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: instanceof    #86                 // class java/util/Collection
      17: ifeq          36
      20: aload_1
      21: checkcast     #86                 // class java/util/Collection
      24: invokeinterface #270,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      29: ifeq          36
      32: iconst_1
      33: goto          91
      36: aload_1
      37: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore_3
      43: aload_3
      44: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          90
      52: aload_3
      53: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        4
      60: aload         4
      62: checkcast     #191                // class java/lang/Number
      65: invokevirtual #195                // Method java/lang/Number.intValue:()I
      68: istore        5
      70: iconst_0
      71: istore        6
      73: iload         5
      75: ifne          82
      78: iconst_1
      79: goto          83
      82: iconst_0
      83: ifne          43
      86: iconst_0
      87: goto          91
      90: iconst_1
      91: ifne          98
      94: iconst_1
      95: goto          99
      98: iconst_0
      99: ireturn
}


package day08

import java.io.File

fun main() {
    val data = parse("src/day08/Day08.txt")

    println("🎄 Day 08 🎄")

    println()

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

    println()

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

private data class Instructions(
    val directions: String,
    val network: Map<String, Pair<String, String>>,
)

private fun parse(path: String): Instructions {
    val lines = File(path).readLines()

    val directions = lines.first()
    val network = lines.drop(2)
        .mapNotNull { """(\w+) = \((\w+), (\w+)\)""".toRegex().find(it)?.destructured }
        .associate { (key, left, right) -> key to (left to right) }

    return Instructions(directions, network)
}

private fun lcm(a: Long, b: Long): Long {
    var n1 = a
    var n2 = b
    while (n2 != 0L) {
        n1 = n2.also { n2 = n1 % n2 }
    }
    return (a * b) / n1
}

private fun Instructions.generateNodeSequence(start: String): Sequence<Pair<Int, String>> =
    generateSequence(seed = 0 to start) { (index, node) ->
        val nextDirection = directions[index % directions.length]
        val nextNode = if (nextDirection == 'L') {
            network.getValue(node).let { (next, _) -> next }
        } else {
            network.getValue(node).let { (_, next) -> next }
        }

        (index + 1) to nextNode
    }

private fun part1(data: Instructions): Long =
    data.generateNodeSequence(start = "AAA")
        .dropWhile { (_, node) -> node != "ZZZ" }
        .first().let { (index, _) -> index.toLong() }

private fun Instructions.periodFrom(start: String): Long {
    val path = mutableMapOf<Pair<String, Int>, Long>()
    return generateNodeSequence(start)
        .dropWhile { (index, node) ->
            val key = node to index % directions.length
            if (key !in path) {
                true.also { path[key] = index.toLong() }
            } else {
                false
            }
        }
        .first().let { (index, node) ->
            val directionIndex = index % directions.length
            val startingIndex = path.getValue(node to directionIndex)
            index.toLong() - startingIndex
        }
}

private fun part2(data: Instructions): Long =
    data.network.keys
        .filter { it.last() == 'A' }
        .map(data::periodFrom)
        .reduce(::lcm)

Compiled from "Day08.kt"
public final class day08.Day08Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/day08/Day08.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Lday08/Instructions;
       5: astore_0
       6: ldc           #14                 // String 🎄 Day 08 🎄
       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:(Lday08/Instructions;)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:(Lday08/Instructions;)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 day08.Instructions parse(java.lang.String);
    Code:
       0: new           #61                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #64                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #70                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: astore_1
      15: aload_1
      16: invokestatic  #76                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      19: checkcast     #78                 // class java/lang/String
      22: astore_2
      23: aload_1
      24: checkcast     #80                 // class java/lang/Iterable
      27: iconst_2
      28: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      31: checkcast     #80                 // class java/lang/Iterable
      34: astore        4
      36: nop
      37: iconst_0
      38: istore        5
      40: aload         4
      42: astore        6
      44: new           #86                 // class java/util/ArrayList
      47: dup
      48: invokespecial #87                 // Method java/util/ArrayList."<init>":()V
      51: checkcast     #89                 // class java/util/Collection
      54: astore        7
      56: iconst_0
      57: istore        8
      59: aload         6
      61: astore        9
      63: iconst_0
      64: istore        10
      66: aload         9
      68: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      73: astore        11
      75: aload         11
      77: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      82: ifeq          172
      85: aload         11
      87: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      92: astore        12
      94: aload         12
      96: astore        13
      98: iconst_0
      99: istore        14
     101: aload         13
     103: checkcast     #78                 // class java/lang/String
     106: astore        15
     108: iconst_0
     109: istore        16
     111: new           #105                // class kotlin/text/Regex
     114: dup
     115: ldc           #107                // String (\\w+) = \\((\\w+), (\\w+)\\)
     117: invokespecial #108                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     120: aload         15
     122: checkcast     #110                // class java/lang/CharSequence
     125: iconst_0
     126: iconst_2
     127: aconst_null
     128: invokestatic  #114                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     131: dup
     132: ifnull        143
     135: invokeinterface #120,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     140: goto          145
     143: pop
     144: aconst_null
     145: dup
     146: ifnull        167
     149: astore        17
     151: iconst_0
     152: istore        18
     154: aload         7
     156: aload         17
     158: invokeinterface #124,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     163: pop
     164: goto          168
     167: pop
     168: nop
     169: goto          75
     172: nop
     173: aload         7
     175: checkcast     #126                // class java/util/List
     178: nop
     179: checkcast     #80                 // class java/lang/Iterable
     182: astore        4
     184: nop
     185: iconst_0
     186: istore        5
     188: aload         4
     190: bipush        10
     192: invokestatic  #130                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     195: invokestatic  #136                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     198: bipush        16
     200: invokestatic  #142                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     203: istore        6
     205: aload         4
     207: astore        7
     209: new           #144                // class java/util/LinkedHashMap
     212: dup
     213: iload         6
     215: invokespecial #147                // Method java/util/LinkedHashMap."<init>":(I)V
     218: checkcast     #149                // class java/util/Map
     221: astore        8
     223: iconst_0
     224: istore        9
     226: aload         7
     228: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     233: astore        10
     235: aload         10
     237: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     242: ifeq          366
     245: aload         10
     247: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     252: astore        11
     254: aload         8
     256: astore        12
     258: aload         11
     260: checkcast     #151                // class kotlin/text/MatchResult$Destructured
     263: astore        13
     265: iconst_0
     266: istore        14
     268: aload         13
     270: invokevirtual #155                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     273: invokeinterface #159,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     278: iconst_1
     279: invokeinterface #163,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     284: checkcast     #78                 // class java/lang/String
     287: astore        15
     289: aload         13
     291: invokevirtual #155                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     294: invokeinterface #159,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     299: iconst_2
     300: invokeinterface #163,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     305: checkcast     #78                 // class java/lang/String
     308: astore        16
     310: aload         13
     312: invokevirtual #155                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     315: invokeinterface #159,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     320: iconst_3
     321: invokeinterface #163,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     326: checkcast     #78                 // class java/lang/String
     329: astore        17
     331: aload         15
     333: aload         16
     335: aload         17
     337: invokestatic  #169                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     340: invokestatic  #169                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     343: astore        13
     345: aload         12
     347: aload         13
     349: invokevirtual #174                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     352: aload         13
     354: invokevirtual #177                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     357: invokeinterface #181,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     362: pop
     363: goto          235
     366: aload         8
     368: nop
     369: astore_3
     370: new           #183                // class day08/Instructions
     373: dup
     374: aload_2
     375: aload_3
     376: invokespecial #186                // Method day08/Instructions."<init>":(Ljava/lang/String;Ljava/util/Map;)V
     379: areturn

  private static final long lcm(long, long);
    Code:
       0: lconst_0
       1: lstore        9
       3: lload_0
       4: lstore        9
       6: lconst_0
       7: lstore        11
       9: lload_2
      10: lstore        11
      12: lload         11
      14: lconst_0
      15: lcmp
      16: ifeq          44
      19: lload         11
      21: lstore        4
      23: lload         4
      25: lstore        6
      27: iconst_0
      28: istore        8
      30: lload         9
      32: lload         11
      34: lrem
      35: lstore        11
      37: lload         4
      39: lstore        9
      41: goto          12
      44: lload_0
      45: lload_2
      46: lmul
      47: lload         9
      49: ldiv
      50: lreturn

  private static final kotlin.sequences.Sequence<kotlin.Pair<java.lang.Integer, java.lang.String>> generateNodeSequence(day08.Instructions, java.lang.String);
    Code:
       0: iconst_0
       1: invokestatic  #237                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       4: aload_1
       5: invokestatic  #169                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
       8: aload_0
       9: invokedynamic #257,  0            // InvokeDynamic #0:invoke:(Lday08/Instructions;)Lkotlin/jvm/functions/Function1;
      14: invokestatic  #263                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      17: areturn

  private static final long part1(day08.Instructions);
    Code:
       0: aload_0
       1: ldc_w         #267                // String AAA
       4: invokestatic  #269                // Method generateNodeSequence:(Lday08/Instructions;Ljava/lang/String;)Lkotlin/sequences/Sequence;
       7: invokedynamic #279,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      12: invokestatic  #283                // Method kotlin/sequences/SequencesKt.dropWhile:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      15: invokestatic  #286                // Method kotlin/sequences/SequencesKt.first:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
      18: checkcast     #171                // class kotlin/Pair
      21: astore_1
      22: iconst_0
      23: istore_2
      24: aload_1
      25: invokevirtual #289                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      28: checkcast     #291                // class java/lang/Number
      31: invokevirtual #295                // Method java/lang/Number.intValue:()I
      34: istore_3
      35: iload_3
      36: i2l
      37: nop
      38: lreturn

  private static final long periodFrom(day08.Instructions, java.lang.String);
    Code:
       0: new           #144                // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #300                // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #149                // class java/util/Map
      10: astore_2
      11: aload_0
      12: aload_1
      13: invokestatic  #269                // Method generateNodeSequence:(Lday08/Instructions;Ljava/lang/String;)Lkotlin/sequences/Sequence;
      16: aload_0
      17: aload_2
      18: invokedynamic #308,  0            // InvokeDynamic #2:invoke:(Lday08/Instructions;Ljava/util/Map;)Lkotlin/jvm/functions/Function1;
      23: invokestatic  #283                // Method kotlin/sequences/SequencesKt.dropWhile:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      26: invokestatic  #286                // Method kotlin/sequences/SequencesKt.first:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
      29: checkcast     #171                // class kotlin/Pair
      32: astore_3
      33: iconst_0
      34: istore        4
      36: aload_3
      37: invokevirtual #289                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      40: checkcast     #291                // class java/lang/Number
      43: invokevirtual #295                // Method java/lang/Number.intValue:()I
      46: istore        5
      48: aload_3
      49: invokevirtual #311                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      52: checkcast     #78                 // class java/lang/String
      55: astore        6
      57: iload         5
      59: aload_0
      60: invokevirtual #314                // Method day08/Instructions.getDirections:()Ljava/lang/String;
      63: invokevirtual #317                // Method java/lang/String.length:()I
      66: irem
      67: istore        7
      69: aload_2
      70: aload         6
      72: iload         7
      74: invokestatic  #237                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      77: invokestatic  #169                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      80: invokestatic  #321                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      83: checkcast     #291                // class java/lang/Number
      86: invokevirtual #325                // Method java/lang/Number.longValue:()J
      89: lstore        8
      91: iload         5
      93: i2l
      94: lload         8
      96: lsub
      97: nop
      98: lreturn

  private static final long part2(day08.Instructions);
    Code:
       0: aload_0
       1: invokevirtual #334                // Method day08/Instructions.getNetwork:()Ljava/util/Map;
       4: invokeinterface #338,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
       9: checkcast     #80                 // class java/lang/Iterable
      12: astore_1
      13: nop
      14: iconst_0
      15: istore_2
      16: aload_1
      17: astore_3
      18: new           #86                 // class java/util/ArrayList
      21: dup
      22: invokespecial #87                 // Method java/util/ArrayList."<init>":()V
      25: checkcast     #89                 // class java/util/Collection
      28: astore        4
      30: iconst_0
      31: istore        5
      33: aload_3
      34: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        6
      41: aload         6
      43: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          104
      51: aload         6
      53: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        7
      60: aload         7
      62: checkcast     #78                 // class java/lang/String
      65: astore        8
      67: iconst_0
      68: istore        9
      70: aload         8
      72: checkcast     #110                // class java/lang/CharSequence
      75: invokestatic  #344                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
      78: bipush        65
      80: if_icmpne     87
      83: iconst_1
      84: goto          88
      87: iconst_0
      88: ifeq          41
      91: aload         4
      93: aload         7
      95: invokeinterface #124,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     100: pop
     101: goto          41
     104: aload         4
     106: checkcast     #126                // class java/util/List
     109: nop
     110: checkcast     #80                 // class java/lang/Iterable
     113: astore_1
     114: nop
     115: iconst_0
     116: istore_2
     117: aload_1
     118: astore_3
     119: new           #86                 // class java/util/ArrayList
     122: dup
     123: aload_1
     124: bipush        10
     126: invokestatic  #130                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     129: invokespecial #345                // Method java/util/ArrayList."<init>":(I)V
     132: checkcast     #89                 // class java/util/Collection
     135: astore        4
     137: iconst_0
     138: istore        5
     140: aload_3
     141: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     146: astore        6
     148: aload         6
     150: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     155: ifeq          202
     158: aload         6
     160: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     165: astore        7
     167: aload         4
     169: aload         7
     171: checkcast     #78                 // class java/lang/String
     174: astore        8
     176: astore        10
     178: iconst_0
     179: istore        9
     181: aload_0
     182: aload         8
     184: invokestatic  #347                // Method periodFrom:(Lday08/Instructions;Ljava/lang/String;)J
     187: invokestatic  #352                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     190: aload         10
     192: swap
     193: invokeinterface #124,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     198: pop
     199: goto          148
     202: aload         4
     204: checkcast     #126                // class java/util/List
     207: nop
     208: checkcast     #80                 // class java/lang/Iterable
     211: astore_1
     212: nop
     213: iconst_0
     214: istore_2
     215: aload_1
     216: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     221: astore_3
     222: aload_3
     223: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     228: ifne          242
     231: new           #354                // class java/lang/UnsupportedOperationException
     234: dup
     235: ldc_w         #356                // String Empty collection can\'t be reduced.
     238: invokespecial #357                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     241: athrow
     242: aload_3
     243: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     248: astore        4
     250: aload_3
     251: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     256: ifeq          301
     259: aload         4
     261: aload_3
     262: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     267: checkcast     #291                // class java/lang/Number
     270: invokevirtual #325                // Method java/lang/Number.longValue:()J
     273: lstore        5
     275: checkcast     #291                // class java/lang/Number
     278: invokevirtual #325                // Method java/lang/Number.longValue:()J
     281: lstore        7
     283: iconst_0
     284: istore        9
     286: lload         7
     288: lload         5
     290: invokestatic  #359                // Method lcm:(JJ)J
     293: invokestatic  #352                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     296: astore        4
     298: goto          250
     301: aload         4
     303: checkcast     #291                // class java/lang/Number
     306: invokevirtual #325                // Method java/lang/Number.longValue:()J
     309: lreturn

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

  private static final kotlin.Pair generateNodeSequence$lambda$5(day08.Instructions, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #385                // String <destruct>
       4: invokestatic  #391                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokevirtual #289                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      11: checkcast     #291                // class java/lang/Number
      14: invokevirtual #295                // Method java/lang/Number.intValue:()I
      17: istore_2
      18: aload_1
      19: invokevirtual #311                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      22: checkcast     #78                 // class java/lang/String
      25: astore_3
      26: aload_0
      27: invokevirtual #314                // Method day08/Instructions.getDirections:()Ljava/lang/String;
      30: iload_2
      31: aload_0
      32: invokevirtual #314                // Method day08/Instructions.getDirections:()Ljava/lang/String;
      35: invokevirtual #317                // Method java/lang/String.length:()I
      38: irem
      39: invokevirtual #395                // Method java/lang/String.charAt:(I)C
      42: istore        4
      44: iload         4
      46: bipush        76
      48: if_icmpne     82
      51: aload_0
      52: invokevirtual #334                // Method day08/Instructions.getNetwork:()Ljava/util/Map;
      55: aload_3
      56: invokestatic  #321                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      59: checkcast     #171                // class kotlin/Pair
      62: astore        6
      64: iconst_0
      65: istore        7
      67: aload         6
      69: invokevirtual #289                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      72: checkcast     #78                 // class java/lang/String
      75: astore        8
      77: aload         8
      79: goto          111
      82: aload_0
      83: invokevirtual #334                // Method day08/Instructions.getNetwork:()Ljava/util/Map;
      86: aload_3
      87: invokestatic  #321                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      90: checkcast     #171                // class kotlin/Pair
      93: astore        6
      95: iconst_0
      96: istore        7
      98: aload         6
     100: invokevirtual #311                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     103: checkcast     #78                 // class java/lang/String
     106: astore        8
     108: aload         8
     110: nop
     111: astore        5
     113: iload_2
     114: iconst_1
     115: iadd
     116: invokestatic  #237                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     119: aload         5
     121: invokestatic  #169                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     124: areturn

  private static final boolean part1$lambda$6(kotlin.Pair);
    Code:
       0: aload_0
       1: ldc_w         #385                // String <destruct>
       4: invokestatic  #391                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #311                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      11: checkcast     #78                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: ldc_w         #403                // String ZZZ
      19: invokestatic  #407                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      22: ifne          29
      25: iconst_1
      26: goto          30
      29: iconst_0
      30: ireturn

  private static final boolean periodFrom$lambda$9(day08.Instructions, java.util.Map, kotlin.Pair);
    Code:
       0: aload_2
       1: ldc_w         #385                // String <destruct>
       4: invokestatic  #391                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_2
       8: invokevirtual #289                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      11: checkcast     #291                // class java/lang/Number
      14: invokevirtual #295                // Method java/lang/Number.intValue:()I
      17: istore_3
      18: aload_2
      19: invokevirtual #311                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      22: checkcast     #78                 // class java/lang/String
      25: astore        4
      27: aload         4
      29: iload_3
      30: aload_0
      31: invokevirtual #314                // Method day08/Instructions.getDirections:()Ljava/lang/String;
      34: invokevirtual #317                // Method java/lang/String.length:()I
      37: irem
      38: invokestatic  #237                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokestatic  #169                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      44: astore        5
      46: aload_1
      47: aload         5
      49: invokeinterface #410,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      54: ifne          87
      57: iconst_1
      58: istore        6
      60: iload         6
      62: istore        7
      64: iconst_0
      65: istore        8
      67: aload_1
      68: aload         5
      70: iload_3
      71: i2l
      72: invokestatic  #352                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      75: invokeinterface #181,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      80: pop
      81: nop
      82: iload         6
      84: goto          88
      87: iconst_0
      88: ireturn
}