package day3

import java.io.File

data class Count(
    var zeros: Int = 0,
    var ones: Int = 0
)

fun part1() {
    val lines = File("day3.txt").readLines()

    val counts: List<Count> = generateSequence {
        Count()
    }.take(12).toList()

    lines.forEach { line ->
        line.forEachIndexed { index, character ->
            when (character) {
                '0' -> counts[index].zeros++
                '1' -> counts[index].ones++
            }
        }
    }

    val gammaRateRaw = counts.joinToString("") { count ->
        if (count.ones > count.zeros) {
            "1"
        } else if (count.zeros > count.ones) {
            "0"
        } else {
            throw IllegalStateException("No most common bit")
        }
    }

    val epsilonRateRaw = gammaRateRaw.map { character ->
        when (character) {
            '0' -> '1'
            '1' -> '0'
            else -> throw IllegalStateException("Unknown character: $character")
        }
    }.joinToString("")

    val gammaRate = Integer.parseInt(gammaRateRaw, 2)
    val epsilonRate = Integer.parseInt(epsilonRateRaw, 2)

    println("gamma: $gammaRateRaw -> $gammaRate")
    println("gamma: $epsilonRateRaw -> $epsilonRate")
    println("part1 solution = ${gammaRate * epsilonRate}")
}

fun findCount(values: List<String>, position: Int): Count {
    val count = Count()

    values.forEach { line ->
        val character = line[position]
        when (character) {
            '0' -> count.zeros++
            '1' -> count.ones++
        }
    }

    return count
}

fun findRating(
    values: List<String>,
    position: Int,
    filter: (String, Int, Count) -> Boolean
): String {
    val count = findCount(values, position)
    val filteredValues = values.filter { value ->
        filter(value, position, count)
    }
    return if (filteredValues.size == 1) {
        filteredValues[0]
    } else if (filteredValues.size > 1) {
        findRating(filteredValues, position + 1, filter)
    } else {
        throw IllegalStateException("Could not find values")
    }
}

fun findOxygenBit(count: Count): Char {
    return if (count.ones > count.zeros) {
        '1'
    } else if (count.zeros > count.ones) {
        '0'
    } else {
        '1'
    }
}

fun findCo2Bit(count: Count): Char {
    return if (count.ones < count.zeros) {
        '1'
    } else if (count.zeros < count.ones) {
        '0'
    } else {
        '0'
    }
}

fun part2() {
    val values = File("day3.txt").readLines()

    val oxygenRatingRaw = findRating(values, 0) { value, position, count ->
        val valueAtPosition = value[position]
        valueAtPosition == findOxygenBit(count)
    }
    val oxygenRating = Integer.parseInt(oxygenRatingRaw, 2)
    println("oxygen $oxygenRatingRaw -> $oxygenRating")

    val co2RatingRaw = findRating(values, 0) { value, position, count ->
        val valueAtPosition = value[position]
        valueAtPosition == findCo2Bit(count)
    }
    val co2Rating = Integer.parseInt(co2RatingRaw, 2)
    println("co2 $co2RatingRaw -> $co2Rating")

    println("Solution ${oxygenRating * co2Rating}")
}

fun main() {
    part2()
}

Compiled from "Day3.kt"
public final class day3.Day3Kt {
  public static final void part1();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String day3.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: invokedynamic #39,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function0;
      21: invokestatic  #45                 // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
      24: bipush        12
      26: invokestatic  #49                 // Method kotlin/sequences/SequencesKt.take:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
      29: invokestatic  #53                 // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      32: astore_1
      33: aload_0
      34: checkcast     #55                 // class java/lang/Iterable
      37: astore_2
      38: iconst_0
      39: istore_3
      40: aload_2
      41: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      46: astore        4
      48: aload         4
      50: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      55: ifeq          231
      58: aload         4
      60: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      65: astore        5
      67: aload         5
      69: checkcast     #70                 // class java/lang/String
      72: astore        6
      74: iconst_0
      75: istore        7
      77: aload         6
      79: checkcast     #72                 // class java/lang/CharSequence
      82: astore        8
      84: iconst_0
      85: istore        9
      87: iconst_0
      88: istore        10
      90: iconst_0
      91: istore        11
      93: iload         11
      95: aload         8
      97: invokeinterface #76,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     102: if_icmpge     225
     105: aload         8
     107: iload         11
     109: invokeinterface #80,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     114: istore        12
     116: iload         10
     118: iinc          10, 1
     121: iload         12
     123: istore        13
     125: istore        14
     127: iconst_0
     128: istore        15
     130: iload         13
     132: tableswitch   { // 48 to 49
                    48: 156
                    49: 188
               default: 217
          }
     156: aload_1
     157: iload         14
     159: invokeinterface #86,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     164: checkcast     #88                 // class day3/Count
     167: astore        16
     169: aload         16
     171: invokevirtual #91                 // Method day3/Count.getZeros:()I
     174: istore        17
     176: aload         16
     178: iload         17
     180: iconst_1
     181: iadd
     182: invokevirtual #95                 // Method day3/Count.setZeros:(I)V
     185: goto          217
     188: aload_1
     189: iload         14
     191: invokeinterface #86,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     196: checkcast     #88                 // class day3/Count
     199: astore        16
     201: aload         16
     203: invokevirtual #98                 // Method day3/Count.getOnes:()I
     206: istore        17
     208: aload         16
     210: iload         17
     212: iconst_1
     213: iadd
     214: invokevirtual #101                // Method day3/Count.setOnes:(I)V
     217: nop
     218: nop
     219: iinc          11, 1
     222: goto          93
     225: nop
     226: nop
     227: nop
     228: goto          48
     231: nop
     232: aload_1
     233: checkcast     #55                 // class java/lang/Iterable
     236: ldc           #103                // String
     238: checkcast     #72                 // class java/lang/CharSequence
     241: aconst_null
     242: aconst_null
     243: iconst_0
     244: aconst_null
     245: invokedynamic #114,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
     250: bipush        30
     252: aconst_null
     253: invokestatic  #120                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     256: astore_2
     257: aload_2
     258: checkcast     #72                 // class java/lang/CharSequence
     261: astore        4
     263: iconst_0
     264: istore        5
     266: aload         4
     268: astore        6
     270: new           #122                // class java/util/ArrayList
     273: dup
     274: aload         4
     276: invokeinterface #76,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     281: invokespecial #124                // Method java/util/ArrayList."<init>":(I)V
     284: checkcast     #126                // class java/util/Collection
     287: astore        7
     289: iconst_0
     290: istore        8
     292: iconst_0
     293: istore        9
     295: iload         9
     297: aload         6
     299: invokeinterface #76,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     304: if_icmpge     409
     307: aload         6
     309: iload         9
     311: invokeinterface #80,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     316: istore        10
     318: aload         7
     320: iload         10
     322: istore        11
     324: astore        18
     326: iconst_0
     327: istore        12
     329: iload         11
     331: tableswitch   { // 48 to 49
                    48: 352
                    49: 357
               default: 362
          }
     352: bipush        49
     354: goto          390
     357: bipush        48
     359: goto          390
     362: new           #128                // class java/lang/IllegalStateException
     365: dup
     366: new           #130                // class java/lang/StringBuilder
     369: dup
     370: invokespecial #132                // Method java/lang/StringBuilder."<init>":()V
     373: ldc           #134                // String Unknown character:
     375: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     378: iload         11
     380: invokevirtual #141                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     383: invokevirtual #145                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     386: invokespecial #146                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     389: athrow
     390: nop
     391: invokestatic  #152                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     394: aload         18
     396: swap
     397: invokeinterface #156,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     402: pop
     403: iinc          9, 1
     406: goto          295
     409: aload         7
     411: checkcast     #82                 // class java/util/List
     414: nop
     415: checkcast     #55                 // class java/lang/Iterable
     418: ldc           #103                // String
     420: checkcast     #72                 // class java/lang/CharSequence
     423: aconst_null
     424: aconst_null
     425: iconst_0
     426: aconst_null
     427: aconst_null
     428: bipush        62
     430: aconst_null
     431: invokestatic  #120                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     434: astore_3
     435: aload_2
     436: iconst_2
     437: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     440: istore        4
     442: aload_3
     443: iconst_2
     444: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     447: istore        5
     449: new           #130                // class java/lang/StringBuilder
     452: dup
     453: invokespecial #132                // Method java/lang/StringBuilder."<init>":()V
     456: ldc           #164                // String gamma:
     458: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     461: aload_2
     462: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     465: ldc           #166                // String  ->
     467: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     470: iload         4
     472: invokevirtual #169                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     475: invokevirtual #145                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     478: getstatic     #175                // Field java/lang/System.out:Ljava/io/PrintStream;
     481: swap
     482: invokevirtual #181                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     485: new           #130                // class java/lang/StringBuilder
     488: dup
     489: invokespecial #132                // Method java/lang/StringBuilder."<init>":()V
     492: ldc           #164                // String gamma:
     494: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     497: aload_3
     498: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     501: ldc           #166                // String  ->
     503: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     506: iload         5
     508: invokevirtual #169                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     511: invokevirtual #145                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     514: getstatic     #175                // Field java/lang/System.out:Ljava/io/PrintStream;
     517: swap
     518: invokevirtual #181                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     521: new           #130                // class java/lang/StringBuilder
     524: dup
     525: invokespecial #132                // Method java/lang/StringBuilder."<init>":()V
     528: ldc           #183                // String part1 solution =
     530: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     533: iload         4
     535: iload         5
     537: imul
     538: invokevirtual #169                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     541: invokevirtual #145                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     544: getstatic     #175                // Field java/lang/System.out:Ljava/io/PrintStream;
     547: swap
     548: invokevirtual #181                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     551: return

  public static final day3.Count findCount(java.util.List<java.lang.String>, int);
    Code:
       0: aload_0
       1: ldc           #222                // String values
       3: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #88                 // class day3/Count
       9: dup
      10: iconst_0
      11: iconst_0
      12: iconst_3
      13: aconst_null
      14: invokespecial #231                // Method day3/Count."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
      17: astore_2
      18: aload_0
      19: checkcast     #55                 // class java/lang/Iterable
      22: astore_3
      23: iconst_0
      24: istore        4
      26: aload_3
      27: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      32: astore        5
      34: aload         5
      36: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          132
      44: aload         5
      46: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: astore        6
      53: aload         6
      55: checkcast     #70                 // class java/lang/String
      58: astore        7
      60: iconst_0
      61: istore        8
      63: aload         7
      65: iload_1
      66: invokevirtual #232                // Method java/lang/String.charAt:(I)C
      69: istore        9
      71: iload         9
      73: tableswitch   { // 48 to 49
                    48: 96
                    49: 113
               default: 127
          }
      96: aload_2
      97: invokevirtual #91                 // Method day3/Count.getZeros:()I
     100: istore        10
     102: aload_2
     103: iload         10
     105: iconst_1
     106: iadd
     107: invokevirtual #95                 // Method day3/Count.setZeros:(I)V
     110: goto          127
     113: aload_2
     114: invokevirtual #98                 // Method day3/Count.getOnes:()I
     117: istore        10
     119: aload_2
     120: iload         10
     122: iconst_1
     123: iadd
     124: invokevirtual #101                // Method day3/Count.setOnes:(I)V
     127: nop
     128: nop
     129: goto          34
     132: nop
     133: aload_2
     134: areturn

  public static final java.lang.String findRating(java.util.List<java.lang.String>, int, kotlin.jvm.functions.Function3<? super java.lang.String, ? super java.lang.Integer, ? super day3.Count, java.lang.Boolean>);
    Code:
       0: aload_0
       1: ldc           #222                // String values
       3: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #241                // String filter
       9: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iload_1
      14: invokestatic  #243                // Method findCount:(Ljava/util/List;I)Lday3/Count;
      17: astore_3
      18: aload_0
      19: checkcast     #55                 // class java/lang/Iterable
      22: astore        5
      24: iconst_0
      25: istore        6
      27: aload         5
      29: astore        7
      31: new           #122                // class java/util/ArrayList
      34: dup
      35: invokespecial #244                // Method java/util/ArrayList."<init>":()V
      38: checkcast     #126                // class java/util/Collection
      41: astore        8
      43: iconst_0
      44: istore        9
      46: aload         7
      48: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        10
      55: aload         10
      57: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          119
      65: aload         10
      67: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: astore        11
      74: aload         11
      76: checkcast     #70                 // class java/lang/String
      79: astore        12
      81: iconst_0
      82: istore        13
      84: aload_2
      85: aload         12
      87: iload_1
      88: invokestatic  #247                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: aload_3
      92: invokeinterface #252,  4          // InterfaceMethod kotlin/jvm/functions/Function3.invoke:(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      97: checkcast     #254                // class java/lang/Boolean
     100: invokevirtual #257                // Method java/lang/Boolean.booleanValue:()Z
     103: ifeq          55
     106: aload         8
     108: aload         11
     110: invokeinterface #156,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     115: pop
     116: goto          55
     119: aload         8
     121: checkcast     #82                 // class java/util/List
     124: nop
     125: astore        4
     127: aload         4
     129: invokeinterface #260,  1          // InterfaceMethod java/util/List.size:()I
     134: iconst_1
     135: if_icmpne     152
     138: aload         4
     140: iconst_0
     141: invokeinterface #86,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     146: checkcast     #70                 // class java/lang/String
     149: goto          186
     152: aload         4
     154: invokeinterface #260,  1          // InterfaceMethod java/util/List.size:()I
     159: iconst_1
     160: if_icmple     175
     163: aload         4
     165: iload_1
     166: iconst_1
     167: iadd
     168: aload_2
     169: invokestatic  #262                // Method findRating:(Ljava/util/List;ILkotlin/jvm/functions/Function3;)Ljava/lang/String;
     172: goto          186
     175: new           #128                // class java/lang/IllegalStateException
     178: dup
     179: ldc_w         #264                // String Could not find values
     182: invokespecial #146                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     185: athrow
     186: areturn

  public static final char findOxygenBit(day3.Count);
    Code:
       0: aload_0
       1: ldc_w         #276                // String count
       4: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #98                 // Method day3/Count.getOnes:()I
      11: aload_0
      12: invokevirtual #91                 // Method day3/Count.getZeros:()I
      15: if_icmple     23
      18: bipush        49
      20: goto          41
      23: aload_0
      24: invokevirtual #91                 // Method day3/Count.getZeros:()I
      27: aload_0
      28: invokevirtual #98                 // Method day3/Count.getOnes:()I
      31: if_icmple     39
      34: bipush        48
      36: goto          41
      39: bipush        49
      41: ireturn

  public static final char findCo2Bit(day3.Count);
    Code:
       0: aload_0
       1: ldc_w         #276                // String count
       4: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #98                 // Method day3/Count.getOnes:()I
      11: aload_0
      12: invokevirtual #91                 // Method day3/Count.getZeros:()I
      15: if_icmpge     23
      18: bipush        49
      20: goto          41
      23: aload_0
      24: invokevirtual #91                 // Method day3/Count.getZeros:()I
      27: aload_0
      28: invokevirtual #98                 // Method day3/Count.getOnes:()I
      31: if_icmpge     39
      34: bipush        48
      36: goto          41
      39: bipush        48
      41: ireturn

  public static final void part2();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String day3.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: iconst_0
      18: invokedynamic #289,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function3;
      23: invokestatic  #262                // Method findRating:(Ljava/util/List;ILkotlin/jvm/functions/Function3;)Ljava/lang/String;
      26: astore_1
      27: aload_1
      28: iconst_2
      29: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      32: istore_2
      33: new           #130                // class java/lang/StringBuilder
      36: dup
      37: invokespecial #132                // Method java/lang/StringBuilder."<init>":()V
      40: ldc_w         #291                // String oxygen
      43: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      46: aload_1
      47: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      50: ldc           #166                // String  ->
      52: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      55: iload_2
      56: invokevirtual #169                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      59: invokevirtual #145                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      62: getstatic     #175                // Field java/lang/System.out:Ljava/io/PrintStream;
      65: swap
      66: invokevirtual #181                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      69: aload_0
      70: iconst_0
      71: invokedynamic #296,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function3;
      76: invokestatic  #262                // Method findRating:(Ljava/util/List;ILkotlin/jvm/functions/Function3;)Ljava/lang/String;
      79: astore_3
      80: aload_3
      81: iconst_2
      82: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      85: istore        4
      87: new           #130                // class java/lang/StringBuilder
      90: dup
      91: invokespecial #132                // Method java/lang/StringBuilder."<init>":()V
      94: ldc_w         #298                // String co2
      97: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     100: aload_3
     101: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     104: ldc           #166                // String  ->
     106: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     109: iload         4
     111: invokevirtual #169                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     114: invokevirtual #145                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     117: getstatic     #175                // Field java/lang/System.out:Ljava/io/PrintStream;
     120: swap
     121: invokevirtual #181                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     124: new           #130                // class java/lang/StringBuilder
     127: dup
     128: invokespecial #132                // Method java/lang/StringBuilder."<init>":()V
     131: ldc_w         #300                // String Solution
     134: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     137: iload_2
     138: iload         4
     140: imul
     141: invokevirtual #169                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     144: invokevirtual #145                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     147: getstatic     #175                // Field java/lang/System.out:Ljava/io/PrintStream;
     150: swap
     151: invokevirtual #181                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     154: return

  public static final void main();
    Code:
       0: invokestatic  #307                // Method part2:()V
       3: return

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

  private static final day3.Count part1$lambda$0();
    Code:
       0: new           #88                 // class day3/Count
       3: dup
       4: iconst_0
       5: iconst_0
       6: iconst_3
       7: aconst_null
       8: invokespecial #231                // Method day3/Count."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
      11: areturn

  private static final java.lang.CharSequence part1$lambda$3(day3.Count);
    Code:
       0: aload_0
       1: ldc_w         #276                // String count
       4: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #98                 // Method day3/Count.getOnes:()I
      11: aload_0
      12: invokevirtual #91                 // Method day3/Count.getZeros:()I
      15: if_icmple     27
      18: ldc_w         #314                // String 1
      21: checkcast     #72                 // class java/lang/CharSequence
      24: goto          58
      27: aload_0
      28: invokevirtual #91                 // Method day3/Count.getZeros:()I
      31: aload_0
      32: invokevirtual #98                 // Method day3/Count.getOnes:()I
      35: if_icmple     47
      38: ldc_w         #316                // String 0
      41: checkcast     #72                 // class java/lang/CharSequence
      44: goto          58
      47: new           #128                // class java/lang/IllegalStateException
      50: dup
      51: ldc_w         #318                // String No most common bit
      54: invokespecial #146                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      57: athrow
      58: areturn

  private static final boolean part2$lambda$7(java.lang.String, int, day3.Count);
    Code:
       0: aload_0
       1: ldc_w         #319                // String value
       4: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_2
       8: ldc_w         #276                // String count
      11: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_0
      15: iload_1
      16: invokevirtual #232                // Method java/lang/String.charAt:(I)C
      19: istore_3
      20: iload_3
      21: aload_2
      22: invokestatic  #321                // Method findOxygenBit:(Lday3/Count;)C
      25: if_icmpne     32
      28: iconst_1
      29: goto          33
      32: iconst_0
      33: ireturn

  private static final boolean part2$lambda$8(java.lang.String, int, day3.Count);
    Code:
       0: aload_0
       1: ldc_w         #319                // String value
       4: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_2
       8: ldc_w         #276                // String count
      11: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_0
      15: iload_1
      16: invokevirtual #232                // Method java/lang/String.charAt:(I)C
      19: istore_3
      20: iload_3
      21: aload_2
      22: invokestatic  #324                // Method findCo2Bit:(Lday3/Count;)C
      25: if_icmpne     32
      28: iconst_1
      29: goto          33
      32: iconst_0
      33: ireturn
}


package day2

import java.io.File

sealed interface Command {
    data class Forward(
        val steps: Int
    ): Command

    data class Down(
        val steps: Int
    ) : Command

    data class Up(
        val steps: Int
    ) : Command
}

fun readCourse(): List<Command> {
    val lines = File("day2.txt").readLines()
    return lines.map { line ->
        val (command, steps) = line.split(" ").let { raw ->
            Pair(raw[0], raw[1].toInt())
        }
        when (command) {
            "forward" -> Command.Forward(steps)
            "down" -> Command.Down(steps)
            "up" -> Command.Up(steps)
            else -> throw IllegalStateException("Unknown command: $command")
        }
    }
}

class Submarine {
    var horizontalPosition = 0
        private set
    var depth = 0
        private set
    var aim = 0
        private set

    fun process(course: List<Command>) {
        course.forEach { command ->
            when (command) {
                is Command.Forward -> horizontalPosition += command.steps
                is Command.Up -> depth -= command.steps
                is Command.Down -> depth += command.steps
            }
        }
    }

    fun processNew(course: List<Command>) {
        course.forEach { command ->
            when (command) {
                is Command.Forward -> {
                    horizontalPosition += command.steps
                    depth += aim * command.steps
                }
                is Command.Up -> {
                    aim -= command.steps
                }
                is Command.Down -> {
                    aim += command.steps
                }
            }
        }
    }

    fun getSolution(): Int {
        return horizontalPosition * depth
    }
}

fun part1() {
    val course = readCourse()

    println("Size: " + course.size)

    val submarine = Submarine()
    submarine.process(course)

    println("Position: " + submarine.horizontalPosition)
    println("Depth: " + submarine.depth)

    println(submarine.getSolution())
}

fun part2() {
    val course = readCourse()

    println("Size: " + course.size)

    val submarine = Submarine()
    submarine.processNew(course)

    println("Position: " + submarine.horizontalPosition)
    println("Depth: " + submarine.depth)
    println("Aim: " + submarine.aim)

    println("Solution: " + submarine.getSolution())
}

fun main() {
    part2()
}

Compiled from "Day2.kt"
public final class day2.Day2Kt {
  public static final java.util.List<day2.Command> readCourse();
    Code:
       0: new           #10                 // class java/io/File
       3: dup
       4: ldc           #12                 // String day2.txt
       6: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #22                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: checkcast     #24                 // class java/lang/Iterable
      20: astore_1
      21: iconst_0
      22: istore_2
      23: aload_1
      24: astore_3
      25: new           #26                 // class java/util/ArrayList
      28: dup
      29: aload_1
      30: bipush        10
      32: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      35: invokespecial #35                 // Method java/util/ArrayList."<init>":(I)V
      38: checkcast     #37                 // class java/util/Collection
      41: astore        4
      43: iconst_0
      44: istore        5
      46: aload_3
      47: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        6
      54: aload         6
      56: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          345
      64: aload         6
      66: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: astore        7
      73: aload         4
      75: aload         7
      77: checkcast     #53                 // class java/lang/String
      80: astore        8
      82: astore        14
      84: iconst_0
      85: istore        9
      87: aload         8
      89: checkcast     #55                 // class java/lang/CharSequence
      92: iconst_1
      93: anewarray     #53                 // class java/lang/String
      96: astore        10
      98: aload         10
     100: iconst_0
     101: ldc           #57                 // String
     103: aastore
     104: aload         10
     106: iconst_0
     107: iconst_0
     108: bipush        6
     110: aconst_null
     111: invokestatic  #63                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     114: astore        11
     116: iconst_0
     117: istore        12
     119: new           #65                 // class kotlin/Pair
     122: dup
     123: aload         11
     125: iconst_0
     126: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     131: aload         11
     133: iconst_1
     134: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     139: checkcast     #53                 // class java/lang/String
     142: invokestatic  #77                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     145: invokestatic  #81                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     148: invokespecial #84                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     151: nop
     152: astore        13
     154: aload         13
     156: invokevirtual #87                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     159: checkcast     #53                 // class java/lang/String
     162: astore        10
     164: aload         13
     166: invokevirtual #90                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     169: checkcast     #92                 // class java/lang/Number
     172: invokevirtual #96                 // Method java/lang/Number.intValue:()I
     175: istore        11
     177: aload         10
     179: astore        12
     181: aload         12
     183: invokevirtual #99                 // Method java/lang/String.hashCode:()I
     186: lookupswitch  { // 3
            -677145915: 220
                  3739: 233
               3089570: 246
               default: 304
          }
     220: aload         12
     222: ldc           #101                // String forward
     224: invokevirtual #105                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     227: ifne          259
     230: goto          304
     233: aload         12
     235: ldc           #107                // String up
     237: invokevirtual #105                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     240: ifne          289
     243: goto          304
     246: aload         12
     248: ldc           #109                // String down
     250: invokevirtual #105                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     253: ifne          274
     256: goto          304
     259: new           #111                // class day2/Command$Forward
     262: dup
     263: iload         11
     265: invokespecial #112                // Method day2/Command$Forward."<init>":(I)V
     268: checkcast     #114                // class day2/Command
     271: goto          332
     274: new           #116                // class day2/Command$Down
     277: dup
     278: iload         11
     280: invokespecial #117                // Method day2/Command$Down."<init>":(I)V
     283: checkcast     #114                // class day2/Command
     286: goto          332
     289: new           #119                // class day2/Command$Up
     292: dup
     293: iload         11
     295: invokespecial #120                // Method day2/Command$Up."<init>":(I)V
     298: checkcast     #114                // class day2/Command
     301: goto          332
     304: new           #122                // class java/lang/IllegalStateException
     307: dup
     308: new           #124                // class java/lang/StringBuilder
     311: dup
     312: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
     315: ldc           #129                // String Unknown command:
     317: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     320: aload         10
     322: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     325: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     328: invokespecial #138                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     331: athrow
     332: nop
     333: aload         14
     335: swap
     336: invokeinterface #141,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     341: pop
     342: goto          54
     345: aload         4
     347: checkcast     #67                 // class java/util/List
     350: nop
     351: areturn

  public static final void part1();
    Code:
       0: invokestatic  #163                // Method readCourse:()Ljava/util/List;
       3: astore_0
       4: new           #124                // class java/lang/StringBuilder
       7: dup
       8: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
      11: ldc           #165                // String Size:
      13: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      16: aload_0
      17: invokeinterface #168,  1          // InterfaceMethod java/util/List.size:()I
      22: invokevirtual #171                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      25: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      28: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
      31: swap
      32: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      35: new           #185                // class day2/Submarine
      38: dup
      39: invokespecial #186                // Method day2/Submarine."<init>":()V
      42: astore_1
      43: aload_1
      44: aload_0
      45: invokevirtual #190                // Method day2/Submarine.process:(Ljava/util/List;)V
      48: new           #124                // class java/lang/StringBuilder
      51: dup
      52: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
      55: ldc           #192                // String Position:
      57: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      60: aload_1
      61: invokevirtual #195                // Method day2/Submarine.getHorizontalPosition:()I
      64: invokevirtual #171                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      67: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      70: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
      73: swap
      74: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      77: new           #124                // class java/lang/StringBuilder
      80: dup
      81: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
      84: ldc           #197                // String Depth:
      86: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      89: aload_1
      90: invokevirtual #200                // Method day2/Submarine.getDepth:()I
      93: invokevirtual #171                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      96: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      99: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
     102: swap
     103: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     106: aload_1
     107: invokevirtual #203                // Method day2/Submarine.getSolution:()I
     110: istore_2
     111: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
     114: iload_2
     115: invokevirtual #205                // Method java/io/PrintStream.println:(I)V
     118: return

  public static final void part2();
    Code:
       0: invokestatic  #163                // Method readCourse:()Ljava/util/List;
       3: astore_0
       4: new           #124                // class java/lang/StringBuilder
       7: dup
       8: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
      11: ldc           #165                // String Size:
      13: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      16: aload_0
      17: invokeinterface #168,  1          // InterfaceMethod java/util/List.size:()I
      22: invokevirtual #171                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      25: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      28: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
      31: swap
      32: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      35: new           #185                // class day2/Submarine
      38: dup
      39: invokespecial #186                // Method day2/Submarine."<init>":()V
      42: astore_1
      43: aload_1
      44: aload_0
      45: invokevirtual #212                // Method day2/Submarine.processNew:(Ljava/util/List;)V
      48: new           #124                // class java/lang/StringBuilder
      51: dup
      52: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
      55: ldc           #192                // String Position:
      57: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      60: aload_1
      61: invokevirtual #195                // Method day2/Submarine.getHorizontalPosition:()I
      64: invokevirtual #171                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      67: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      70: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
      73: swap
      74: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      77: new           #124                // class java/lang/StringBuilder
      80: dup
      81: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
      84: ldc           #197                // String Depth:
      86: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      89: aload_1
      90: invokevirtual #200                // Method day2/Submarine.getDepth:()I
      93: invokevirtual #171                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      96: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      99: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
     102: swap
     103: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     106: new           #124                // class java/lang/StringBuilder
     109: dup
     110: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
     113: ldc           #214                // String Aim:
     115: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     118: aload_1
     119: invokevirtual #217                // Method day2/Submarine.getAim:()I
     122: invokevirtual #171                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     125: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     128: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
     131: swap
     132: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     135: new           #124                // class java/lang/StringBuilder
     138: dup
     139: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
     142: ldc           #219                // String Solution:
     144: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     147: aload_1
     148: invokevirtual #203                // Method day2/Submarine.getSolution:()I
     151: invokevirtual #171                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     154: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     157: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
     160: swap
     161: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     164: return

  public static final void main();
    Code:
       0: invokestatic  #222                // Method part2:()V
       3: return

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


package day5

import java.io.File

data class Line(
    val x1: Int,
    val y1: Int,
    val x2: Int,
    val y2: Int
) {
    private fun isHorizontal(): Boolean = y1 == y2
    private fun isVertical(): Boolean = x1 == x2
    private fun isDiagonal(): Boolean = !isHorizontal() && !isVertical()
    fun isHorizontalOrVertical(): Boolean = isHorizontal() || isVertical()

    fun getPoints(): List<Pair<Int, Int>> {
        return if (isHorizontal()) {
            val points = mutableListOf<Pair<Int, Int>>()
            val startX = x1.coerceAtMost(x2)
            val endX = x1.coerceAtLeast(x2)
            for (x in startX..endX) {
                points.add(Pair(x, y1))
            }
            points
        } else if (isVertical()) {
            val points = mutableListOf<Pair<Int, Int>>()
            val startY = y1.coerceAtMost(y2)
            val endY = y1.coerceAtLeast(y2)
            for (y in startY..endY) {
                points.add(Pair(x1, y))
            }
            points
        } else if (isDiagonal()) {
            getDiagonalPoints(x1, y1, x2, y2)
        } else {
            throw IllegalStateException("Line is not horizontal, vertical or diagonal")
        }
    }
}

fun getDiagonalPoints(startX: Int, startY: Int, endX: Int, endY: Int): List<Pair<Int, Int>> {
    val points = mutableListOf<Pair<Int, Int>>()
    val start = Pair(startX, startY)
    val end = Pair(endX, endY)
    val xDiff = end.first - start.first
    val yDiff = end.second - start.second
    val xStep = if (xDiff > 0) 1 else -1
    val yStep = if (yDiff > 0) 1 else -1
    var x = start.first
    var y = start.second
    while (x != end.first || y != end.second) {
        points.add(Pair(x, y))
        x += xStep
        y += yStep
    }
    points.add(Pair(x, y))
    return points
}

fun readLines(): List<Line> {
    val values = File("day5.txt").readLines()

    return values.map { line ->
        val (point1, point2) = line.split(" -> ")
        val (x1, y1) = point1.split(",")
        val (x2, y2) = point2.split(",")
        Line(x1.toInt(), y1.toInt(), x2.toInt(), y2.toInt())
    }
}

fun List<Pair<Int, Int>>.getDuplicates(): Set<Pair<Int, Int>> {
    val counts = mutableMapOf<Pair<Int, Int>, Int>()
    for (point in this) {
        val count = counts.getOrDefault(point, 0)
        counts[point] = count + 1
    }
    return counts.filter { it.value > 1 }.keys
}

fun part1() {
    val points = readLines()
        .filter { it.isHorizontalOrVertical() }
        .map { it.getPoints() }
        .flatten()
        .getDuplicates()

    println(points.size)
}

fun part2() {
    val points = readLines()
        .map { it.getPoints() }
        .flatten()
        .getDuplicates()

    // Wong: 22982
    // Right: 21406

    println(points.size)
}

fun main() {
    part2()
}

Compiled from "Day5.kt"
public final class day5.Day5Kt {
  public static final java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>> getDiagonalPoints(int, int, int, int);
    Code:
       0: new           #10                 // class java/util/ArrayList
       3: dup
       4: invokespecial #14                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #16                 // class java/util/List
      10: astore        4
      12: new           #18                 // class kotlin/Pair
      15: dup
      16: iload_0
      17: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      20: iload_1
      21: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      24: invokespecial #27                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      27: astore        5
      29: new           #18                 // class kotlin/Pair
      32: dup
      33: iload_2
      34: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      37: iload_3
      38: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokespecial #27                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      44: astore        6
      46: aload         6
      48: invokevirtual #31                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      51: checkcast     #33                 // class java/lang/Number
      54: invokevirtual #37                 // Method java/lang/Number.intValue:()I
      57: aload         5
      59: invokevirtual #31                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      62: checkcast     #33                 // class java/lang/Number
      65: invokevirtual #37                 // Method java/lang/Number.intValue:()I
      68: isub
      69: istore        7
      71: aload         6
      73: invokevirtual #40                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      76: checkcast     #33                 // class java/lang/Number
      79: invokevirtual #37                 // Method java/lang/Number.intValue:()I
      82: aload         5
      84: invokevirtual #40                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      87: checkcast     #33                 // class java/lang/Number
      90: invokevirtual #37                 // Method java/lang/Number.intValue:()I
      93: isub
      94: istore        8
      96: iload         7
      98: ifle          105
     101: iconst_1
     102: goto          106
     105: iconst_m1
     106: istore        9
     108: iload         8
     110: ifle          117
     113: iconst_1
     114: goto          118
     117: iconst_m1
     118: istore        10
     120: aload         5
     122: invokevirtual #31                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     125: checkcast     #33                 // class java/lang/Number
     128: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     131: istore        11
     133: aload         5
     135: invokevirtual #40                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     138: checkcast     #33                 // class java/lang/Number
     141: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     144: istore        12
     146: iload         11
     148: aload         6
     150: invokevirtual #31                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     153: checkcast     #33                 // class java/lang/Number
     156: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     159: if_icmpne     178
     162: iload         12
     164: aload         6
     166: invokevirtual #40                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     169: checkcast     #33                 // class java/lang/Number
     172: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     175: if_icmpeq     220
     178: aload         4
     180: new           #18                 // class kotlin/Pair
     183: dup
     184: iload         11
     186: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     189: iload         12
     191: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     194: invokespecial #27                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     197: invokeinterface #44,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     202: pop
     203: iload         11
     205: iload         9
     207: iadd
     208: istore        11
     210: iload         12
     212: iload         10
     214: iadd
     215: istore        12
     217: goto          146
     220: aload         4
     222: new           #18                 // class kotlin/Pair
     225: dup
     226: iload         11
     228: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     231: iload         12
     233: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     236: invokespecial #27                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     239: invokeinterface #44,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     244: pop
     245: aload         4
     247: areturn

  public static final java.util.List<day5.Line> readLines();
    Code:
       0: new           #65                 // class java/io/File
       3: dup
       4: ldc           #67                 // String day5.txt
       6: invokespecial #70                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #76                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: checkcast     #78                 // class java/lang/Iterable
      20: astore_1
      21: iconst_0
      22: istore_2
      23: aload_1
      24: astore_3
      25: new           #10                 // class java/util/ArrayList
      28: dup
      29: aload_1
      30: bipush        10
      32: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      35: invokespecial #87                 // Method java/util/ArrayList."<init>":(I)V
      38: checkcast     #89                 // class java/util/Collection
      41: astore        4
      43: iconst_0
      44: istore        5
      46: aload_3
      47: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        6
      54: aload         6
      56: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          291
      64: aload         6
      66: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: astore        7
      73: aload         4
      75: aload         7
      77: checkcast     #104                // class java/lang/String
      80: astore        8
      82: astore        19
      84: iconst_0
      85: istore        9
      87: aload         8
      89: checkcast     #106                // class java/lang/CharSequence
      92: iconst_1
      93: anewarray     #104                // class java/lang/String
      96: astore        10
      98: aload         10
     100: iconst_0
     101: ldc           #108                // String  ->
     103: aastore
     104: aload         10
     106: iconst_0
     107: iconst_0
     108: bipush        6
     110: aconst_null
     111: invokestatic  #114                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     114: astore        11
     116: aload         11
     118: iconst_0
     119: invokeinterface #118,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     124: checkcast     #104                // class java/lang/String
     127: astore        10
     129: aload         11
     131: iconst_1
     132: invokeinterface #118,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     137: checkcast     #104                // class java/lang/String
     140: astore        12
     142: aload         10
     144: checkcast     #106                // class java/lang/CharSequence
     147: iconst_1
     148: anewarray     #104                // class java/lang/String
     151: astore        13
     153: aload         13
     155: iconst_0
     156: ldc           #120                // String ,
     158: aastore
     159: aload         13
     161: iconst_0
     162: iconst_0
     163: bipush        6
     165: aconst_null
     166: invokestatic  #114                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     169: astore        14
     171: aload         14
     173: iconst_0
     174: invokeinterface #118,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     179: checkcast     #104                // class java/lang/String
     182: astore        13
     184: aload         14
     186: iconst_1
     187: invokeinterface #118,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     192: checkcast     #104                // class java/lang/String
     195: astore        15
     197: aload         12
     199: checkcast     #106                // class java/lang/CharSequence
     202: iconst_1
     203: anewarray     #104                // class java/lang/String
     206: astore        16
     208: aload         16
     210: iconst_0
     211: ldc           #120                // String ,
     213: aastore
     214: aload         16
     216: iconst_0
     217: iconst_0
     218: bipush        6
     220: aconst_null
     221: invokestatic  #114                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     224: astore        17
     226: aload         17
     228: iconst_0
     229: invokeinterface #118,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     234: checkcast     #104                // class java/lang/String
     237: astore        16
     239: aload         17
     241: iconst_1
     242: invokeinterface #118,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     247: checkcast     #104                // class java/lang/String
     250: astore        18
     252: new           #122                // class day5/Line
     255: dup
     256: aload         13
     258: invokestatic  #126                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     261: aload         15
     263: invokestatic  #126                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     266: aload         16
     268: invokestatic  #126                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     271: aload         18
     273: invokestatic  #126                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     276: invokespecial #129                // Method day5/Line."<init>":(IIII)V
     279: aload         19
     281: swap
     282: invokeinterface #130,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     287: pop
     288: goto          54
     291: aload         4
     293: checkcast     #16                 // class java/util/List
     296: nop
     297: areturn

  public static final java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>> getDuplicates(java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #154                // String <this>
       3: invokestatic  #160                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #162                // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #163                // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #165                // class java/util/Map
      16: astore_1
      17: aload_0
      18: invokeinterface #166,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      23: astore_2
      24: aload_2
      25: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          80
      33: aload_2
      34: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #18                 // class kotlin/Pair
      42: astore_3
      43: aload_1
      44: aload_3
      45: iconst_0
      46: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: invokeinterface #170,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      54: checkcast     #33                 // class java/lang/Number
      57: invokevirtual #37                 // Method java/lang/Number.intValue:()I
      60: istore        4
      62: aload_1
      63: aload_3
      64: iload         4
      66: iconst_1
      67: iadd
      68: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      71: invokeinterface #173,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      76: pop
      77: goto          24
      80: aload_1
      81: astore_2
      82: iconst_0
      83: istore_3
      84: aload_2
      85: astore        4
      87: new           #162                // class java/util/LinkedHashMap
      90: dup
      91: invokespecial #163                // Method java/util/LinkedHashMap."<init>":()V
      94: checkcast     #165                // class java/util/Map
      97: astore        5
      99: iconst_0
     100: istore        6
     102: aload         4
     104: invokeinterface #177,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     109: invokeinterface #180,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     114: astore        7
     116: aload         7
     118: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     123: ifeq          195
     126: aload         7
     128: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     133: checkcast     #182                // class java/util/Map$Entry
     136: astore        8
     138: aload         8
     140: astore        9
     142: iconst_0
     143: istore        10
     145: aload         9
     147: invokeinterface #185,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     152: checkcast     #33                 // class java/lang/Number
     155: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     158: iconst_1
     159: if_icmple     166
     162: iconst_1
     163: goto          167
     166: iconst_0
     167: ifeq          116
     170: aload         5
     172: aload         8
     174: invokeinterface #188,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     179: aload         8
     181: invokeinterface #185,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     186: invokeinterface #173,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     191: pop
     192: goto          116
     195: aload         5
     197: nop
     198: invokeinterface #191,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     203: areturn

  public static final void part1();
    Code:
       0: invokestatic  #207                // Method readLines:()Ljava/util/List;
       3: checkcast     #78                 // class java/lang/Iterable
       6: astore_1
       7: nop
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #10                 // class java/util/ArrayList
      15: dup
      16: invokespecial #14                 // Method java/util/ArrayList."<init>":()V
      19: checkcast     #89                 // class java/util/Collection
      22: astore        4
      24: iconst_0
      25: istore        5
      27: aload_3
      28: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        6
      35: aload         6
      37: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          85
      45: aload         6
      47: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        7
      54: aload         7
      56: checkcast     #122                // class day5/Line
      59: astore        8
      61: iconst_0
      62: istore        9
      64: aload         8
      66: invokevirtual #210                // Method day5/Line.isHorizontalOrVertical:()Z
      69: ifeq          35
      72: aload         4
      74: aload         7
      76: invokeinterface #130,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      81: pop
      82: goto          35
      85: aload         4
      87: checkcast     #16                 // class java/util/List
      90: nop
      91: checkcast     #78                 // class java/lang/Iterable
      94: astore_1
      95: nop
      96: iconst_0
      97: istore_2
      98: aload_1
      99: astore_3
     100: new           #10                 // class java/util/ArrayList
     103: dup
     104: aload_1
     105: bipush        10
     107: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     110: invokespecial #87                 // Method java/util/ArrayList."<init>":(I)V
     113: checkcast     #89                 // class java/util/Collection
     116: astore        4
     118: iconst_0
     119: istore        5
     121: aload_3
     122: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     127: astore        6
     129: aload         6
     131: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     136: ifeq          179
     139: aload         6
     141: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     146: astore        7
     148: aload         4
     150: aload         7
     152: checkcast     #122                // class day5/Line
     155: astore        8
     157: astore        10
     159: iconst_0
     160: istore        9
     162: aload         8
     164: invokevirtual #213                // Method day5/Line.getPoints:()Ljava/util/List;
     167: aload         10
     169: swap
     170: invokeinterface #130,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     175: pop
     176: goto          129
     179: aload         4
     181: checkcast     #16                 // class java/util/List
     184: nop
     185: checkcast     #78                 // class java/lang/Iterable
     188: invokestatic  #217                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     191: invokestatic  #219                // Method getDuplicates:(Ljava/util/List;)Ljava/util/Set;
     194: astore_0
     195: aload_0
     196: invokeinterface #222,  1          // InterfaceMethod java/util/Set.size:()I
     201: istore_1
     202: getstatic     #228                // Field java/lang/System.out:Ljava/io/PrintStream;
     205: iload_1
     206: invokevirtual #233                // Method java/io/PrintStream.println:(I)V
     209: return

  public static final void part2();
    Code:
       0: invokestatic  #207                // Method readLines:()Ljava/util/List;
       3: checkcast     #78                 // class java/lang/Iterable
       6: astore_1
       7: nop
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #10                 // class java/util/ArrayList
      15: dup
      16: aload_1
      17: bipush        10
      19: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      22: invokespecial #87                 // Method java/util/ArrayList."<init>":(I)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          91
      51: aload         6
      53: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        7
      60: aload         4
      62: aload         7
      64: checkcast     #122                // class day5/Line
      67: astore        8
      69: astore        10
      71: iconst_0
      72: istore        9
      74: aload         8
      76: invokevirtual #213                // Method day5/Line.getPoints:()Ljava/util/List;
      79: aload         10
      81: swap
      82: invokeinterface #130,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      87: pop
      88: goto          41
      91: aload         4
      93: checkcast     #16                 // class java/util/List
      96: nop
      97: checkcast     #78                 // class java/lang/Iterable
     100: invokestatic  #217                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     103: invokestatic  #219                // Method getDuplicates:(Ljava/util/List;)Ljava/util/Set;
     106: astore_0
     107: aload_0
     108: invokeinterface #222,  1          // InterfaceMethod java/util/Set.size:()I
     113: istore_1
     114: getstatic     #228                // Field java/lang/System.out:Ljava/io/PrintStream;
     117: iload_1
     118: invokevirtual #233                // Method java/io/PrintStream.println:(I)V
     121: return

  public static final void main();
    Code:
       0: invokestatic  #242                // Method part2:()V
       3: return

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