package day4

import java.io.File

fun part1(file: File): List<Int> {
    val pilePoints: MutableList<Int> = mutableListOf()
    val part2AmountOfNumbers: MutableList<Int> = mutableListOf()
    var index = 0

    file.bufferedReader().useLines { readLines -> readLines.forEach { line ->
        val sets = (line.split(Regex(": +"))[1]).split(Regex(" +\\| +"))
        val winNumbers = (sets[0].split(Regex(" +")).map { it.toInt() }).toSet()
        val myNumbers = (sets[1].split(Regex(" +")).map { it.toInt() }).toSet()

        var points = 0

        part2AmountOfNumbers.add(index,0)

        for (number in myNumbers) {
            if (winNumbers.contains(number)) {
                points = if (points == 0) 1 else points * 2
                part2AmountOfNumbers[index] += 1
            }
        }

        index++
        pilePoints += points
    }}

    println(pilePoints.sum())

    return part2AmountOfNumbers.toList()
}

fun part2(file: File) {
    val amountOfNumbers: List<Int> = part1(file)
    val numberOfCopies: MutableList<Int> = MutableList(amountOfNumbers.size) { 1 }

    for ((card, amount) in amountOfNumbers.withIndex()) {
        if (amount == 0) continue

        for (repeat in 1..numberOfCopies[card]) {
            for (index in card + 1..card + amount) {
                numberOfCopies[index]++
            }
        }
    }

    println(numberOfCopies.sum())
}

fun main() {
    val file = File("src/main/kotlin/day4/input.txt")

    part2(file)
}

Compiled from "Day4.kt"
public final class day4.Day4Kt {
  public static final java.util.List<java.lang.Integer> part1(java.io.File);
    Code:
       0: aload_0
       1: ldc           #12                 // String file
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #20                 // class java/util/ArrayList
       9: dup
      10: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      13: checkcast     #26                 // class java/util/List
      16: astore_1
      17: new           #20                 // class java/util/ArrayList
      20: dup
      21: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      24: checkcast     #26                 // class java/util/List
      27: astore_2
      28: iconst_0
      29: istore_3
      30: aload_0
      31: astore        4
      33: getstatic     #32                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      36: astore        5
      38: sipush        8192
      41: istore        6
      43: aload         4
      45: astore        7
      47: new           #34                 // class java/io/InputStreamReader
      50: dup
      51: new           #36                 // class java/io/FileInputStream
      54: dup
      55: aload         7
      57: invokespecial #39                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      60: checkcast     #41                 // class java/io/InputStream
      63: aload         5
      65: invokespecial #44                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      68: checkcast     #46                 // class java/io/Reader
      71: astore        7
      73: aload         7
      75: instanceof    #48                 // class java/io/BufferedReader
      78: ifeq          89
      81: aload         7
      83: checkcast     #48                 // class java/io/BufferedReader
      86: goto          100
      89: new           #48                 // class java/io/BufferedReader
      92: dup
      93: aload         7
      95: iload         6
      97: invokespecial #51                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
     100: checkcast     #46                 // class java/io/Reader
     103: astore        4
     105: nop
     106: iconst_0
     107: istore        5
     109: aload         4
     111: astore        6
     113: sipush        8192
     116: istore        7
     118: aload         6
     120: instanceof    #48                 // class java/io/BufferedReader
     123: ifeq          134
     126: aload         6
     128: checkcast     #48                 // class java/io/BufferedReader
     131: goto          145
     134: new           #48                 // class java/io/BufferedReader
     137: dup
     138: aload         6
     140: iload         7
     142: invokespecial #51                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
     145: checkcast     #53                 // class java/io/Closeable
     148: astore        6
     150: aconst_null
     151: astore        7
     153: nop
     154: aload         6
     156: checkcast     #48                 // class java/io/BufferedReader
     159: astore        8
     161: iconst_0
     162: istore        9
     164: aload         8
     166: invokestatic  #59                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     169: astore        10
     171: iconst_0
     172: istore        11
     174: aload         10
     176: astore        12
     178: iconst_0
     179: istore        13
     181: aload         12
     183: invokeinterface #65,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     188: astore        14
     190: aload         14
     192: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     197: ifeq          721
     200: aload         14
     202: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     207: astore        15
     209: aload         15
     211: checkcast     #77                 // class java/lang/String
     214: astore        16
     216: iconst_0
     217: istore        17
     219: aload         16
     221: checkcast     #79                 // class java/lang/CharSequence
     224: astore        18
     226: new           #81                 // class kotlin/text/Regex
     229: dup
     230: ldc           #83                 // String : +
     232: invokespecial #86                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     235: astore        19
     237: iconst_0
     238: istore        20
     240: aload         19
     242: aload         18
     244: iload         20
     246: invokevirtual #90                 // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
     249: iconst_1
     250: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     255: checkcast     #79                 // class java/lang/CharSequence
     258: astore        18
     260: new           #81                 // class kotlin/text/Regex
     263: dup
     264: ldc           #96                 // String  +\\| +
     266: invokespecial #86                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     269: astore        19
     271: iconst_0
     272: istore        20
     274: aload         19
     276: aload         18
     278: iload         20
     280: invokevirtual #90                 // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
     283: astore        21
     285: aload         21
     287: iconst_0
     288: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     293: checkcast     #79                 // class java/lang/CharSequence
     296: astore        19
     298: new           #81                 // class kotlin/text/Regex
     301: dup
     302: ldc           #98                 // String  +
     304: invokespecial #86                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     307: astore        20
     309: iconst_0
     310: istore        22
     312: aload         20
     314: aload         19
     316: iload         22
     318: invokevirtual #90                 // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
     321: checkcast     #100                // class java/lang/Iterable
     324: astore        19
     326: nop
     327: iconst_0
     328: istore        20
     330: aload         19
     332: astore        22
     334: new           #20                 // class java/util/ArrayList
     337: dup
     338: aload         19
     340: bipush        10
     342: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     345: invokespecial #109                // Method java/util/ArrayList."<init>":(I)V
     348: checkcast     #111                // class java/util/Collection
     351: astore        23
     353: iconst_0
     354: istore        24
     356: aload         22
     358: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     363: astore        25
     365: aload         25
     367: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     372: ifeq          419
     375: aload         25
     377: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     382: astore        26
     384: aload         23
     386: aload         26
     388: checkcast     #77                 // class java/lang/String
     391: astore        27
     393: astore        28
     395: iconst_0
     396: istore        29
     398: aload         27
     400: invokestatic  #118                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     403: nop
     404: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     407: aload         28
     409: swap
     410: invokeinterface #126,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     415: pop
     416: goto          365
     419: aload         23
     421: checkcast     #26                 // class java/util/List
     424: nop
     425: checkcast     #100                // class java/lang/Iterable
     428: invokestatic  #130                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     431: astore        18
     433: aload         21
     435: iconst_1
     436: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     441: checkcast     #79                 // class java/lang/CharSequence
     444: astore        20
     446: new           #81                 // class kotlin/text/Regex
     449: dup
     450: ldc           #98                 // String  +
     452: invokespecial #86                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     455: astore        22
     457: iconst_0
     458: istore        23
     460: aload         22
     462: aload         20
     464: iload         23
     466: invokevirtual #90                 // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
     469: checkcast     #100                // class java/lang/Iterable
     472: astore        20
     474: nop
     475: iconst_0
     476: istore        22
     478: aload         20
     480: astore        23
     482: new           #20                 // class java/util/ArrayList
     485: dup
     486: aload         20
     488: bipush        10
     490: invokestatic  #106                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     493: invokespecial #109                // Method java/util/ArrayList."<init>":(I)V
     496: checkcast     #111                // class java/util/Collection
     499: astore        24
     501: iconst_0
     502: istore        25
     504: aload         23
     506: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     511: astore        26
     513: aload         26
     515: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     520: ifeq          567
     523: aload         26
     525: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     530: astore        27
     532: aload         24
     534: aload         27
     536: checkcast     #77                 // class java/lang/String
     539: astore        29
     541: astore        28
     543: iconst_0
     544: istore        30
     546: aload         29
     548: invokestatic  #118                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     551: nop
     552: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     555: aload         28
     557: swap
     558: invokeinterface #126,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     563: pop
     564: goto          513
     567: aload         24
     569: checkcast     #26                 // class java/util/List
     572: nop
     573: checkcast     #100                // class java/lang/Iterable
     576: invokestatic  #130                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     579: astore        19
     581: iconst_0
     582: istore        20
     584: aload_2
     585: iload_3
     586: iconst_0
     587: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     590: invokeinterface #133,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     595: aload         19
     597: invokeinterface #136,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     602: astore        22
     604: aload         22
     606: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     611: ifeq          693
     614: aload         22
     616: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     621: checkcast     #138                // class java/lang/Number
     624: invokevirtual #142                // Method java/lang/Number.intValue:()I
     627: istore        23
     629: aload         18
     631: iload         23
     633: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     636: invokeinterface #145,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     641: ifeq          604
     644: iload         20
     646: ifne          653
     649: iconst_1
     650: goto          657
     653: iload         20
     655: iconst_2
     656: imul
     657: istore        20
     659: iload_3
     660: istore        24
     662: aload_2
     663: iload         24
     665: aload_2
     666: iload         24
     668: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     673: checkcast     #138                // class java/lang/Number
     676: invokevirtual #142                // Method java/lang/Number.intValue:()I
     679: iconst_1
     680: iadd
     681: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     684: invokeinterface #149,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     689: pop
     690: goto          604
     693: iload_3
     694: iconst_1
     695: iadd
     696: istore_3
     697: iload         20
     699: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     702: astore        23
     704: aload_1
     705: checkcast     #111                // class java/util/Collection
     708: aload         23
     710: invokeinterface #126,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     715: pop
     716: nop
     717: nop
     718: goto          190
     721: nop
     722: nop
     723: getstatic     #155                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     726: astore        8
     728: aload         6
     730: aload         7
     732: invokestatic  #161                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     735: goto          759
     738: astore        9
     740: aload         9
     742: astore        7
     744: aload         9
     746: athrow
     747: astore        9
     749: aload         6
     751: aload         7
     753: invokestatic  #161                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     756: aload         9
     758: athrow
     759: nop
     760: aload_1
     761: checkcast     #100                // class java/lang/Iterable
     764: invokestatic  #165                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     767: istore        4
     769: getstatic     #171                // Field java/lang/System.out:Ljava/io/PrintStream;
     772: iload         4
     774: invokevirtual #176                // Method java/io/PrintStream.println:(I)V
     777: aload_2
     778: checkcast     #100                // class java/lang/Iterable
     781: invokestatic  #180                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     784: areturn
    Exception table:
       from    to  target type
         153   728   738   Class java/lang/Throwable
         153   728   747   any
         738   747   747   any
         747   749   747   any

  public static final void part2(java.io.File);
    Code:
       0: aload_0
       1: ldc           #12                 // String file
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #226                // Method part1:(Ljava/io/File;)Ljava/util/List;
      10: astore_1
      11: aload_1
      12: invokeinterface #229,  1          // InterfaceMethod java/util/List.size:()I
      17: istore_3
      18: new           #20                 // class java/util/ArrayList
      21: dup
      22: iload_3
      23: invokespecial #109                // Method java/util/ArrayList."<init>":(I)V
      26: astore        4
      28: iconst_0
      29: istore        5
      31: iload         5
      33: iload_3
      34: if_icmpge     69
      37: iload         5
      39: istore        6
      41: aload         4
      43: iload         6
      45: istore        7
      47: astore        13
      49: iconst_0
      50: istore        8
      52: iconst_1
      53: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      56: aload         13
      58: swap
      59: invokevirtual #230                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      62: pop
      63: iinc          5, 1
      66: goto          31
      69: aload         4
      71: checkcast     #26                 // class java/util/List
      74: astore_2
      75: aload_1
      76: checkcast     #100                // class java/lang/Iterable
      79: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      84: astore_3
      85: iconst_0
      86: istore        4
      88: aload_3
      89: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      94: ifeq          234
      97: iload         4
      99: istore        5
     101: iload         4
     103: iconst_1
     104: iadd
     105: istore        4
     107: aload_3
     108: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     113: checkcast     #138                // class java/lang/Number
     116: invokevirtual #142                // Method java/lang/Number.intValue:()I
     119: istore        6
     121: iload         6
     123: ifeq          88
     126: iconst_1
     127: istore        7
     129: aload_2
     130: iload         5
     132: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     137: checkcast     #138                // class java/lang/Number
     140: invokevirtual #142                // Method java/lang/Number.intValue:()I
     143: istore        8
     145: iload         7
     147: iload         8
     149: if_icmpgt     88
     152: iload         5
     154: iconst_1
     155: iadd
     156: istore        9
     158: iload         5
     160: iload         6
     162: iadd
     163: istore        10
     165: iload         9
     167: iload         10
     169: if_icmpgt     221
     172: iload         9
     174: istore        11
     176: aload_2
     177: iload         11
     179: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     184: checkcast     #138                // class java/lang/Number
     187: invokevirtual #142                // Method java/lang/Number.intValue:()I
     190: istore        12
     192: aload_2
     193: iload         11
     195: iload         12
     197: iconst_1
     198: iadd
     199: invokestatic  #122                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     202: invokeinterface #149,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     207: pop
     208: iload         9
     210: iload         10
     212: if_icmpeq     221
     215: iinc          9, 1
     218: goto          172
     221: iload         7
     223: iload         8
     225: if_icmpeq     88
     228: iinc          7, 1
     231: goto          152
     234: aload_2
     235: checkcast     #100                // class java/lang/Iterable
     238: invokestatic  #165                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     241: istore_3
     242: getstatic     #171                // Field java/lang/System.out:Ljava/io/PrintStream;
     245: iload_3
     246: invokevirtual #176                // Method java/io/PrintStream.println:(I)V
     249: return

  public static final void main();
    Code:
       0: new           #221                // class java/io/File
       3: dup
       4: ldc           #239                // String src/main/kotlin/day4/input.txt
       6: invokespecial #240                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: aload_0
      11: invokestatic  #242                // Method part2:(Ljava/io/File;)V
      14: return

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


package day2

import java.io.File

fun part1(file: File) {
    var correctGames: Array<Int> = arrayOf()

    lineLoop@
    for ((currentGame, line) in file.readLines().withIndex()) {
        val sets = (line.split(": ")[1]).split("; ")

        for (set in sets) {
            val cubes = set.split(", ")

            for (colorAmount in cubes) {
                val amount = colorAmount.split(' ')[0].toInt()
                val color = colorAmount.split(' ')[1]

                if (amount > 14) continue@lineLoop
                if (amount > 13 && (color == "red" || color == "green")) continue@lineLoop
                if (amount > 12 && color == "red") continue@lineLoop
            }
        }

        correctGames += currentGame + 1
    }

    println(correctGames.sum())
}

fun part2(file: File) {
    var gamePower: Array<Int> = arrayOf()

    for (line in file.readLines()) {
        val sets = (line.split(": ")[1]).split("; ")
        val fewest = mutableMapOf(Pair("red", 1), Pair("green", 1), Pair("blue", 1))
        var power = 1

        for (set in sets) {
            val cubes = set.split(", ")

            for (colorAmount in cubes) {
                val amount = colorAmount.split(' ')[0].toInt()
                val color = colorAmount.split(' ')[1]

                if (amount > fewest[color]!!) fewest[color] = amount
            }
        }

        fewest.values.forEach { power *= it }
        gamePower += power
    }

    println(gamePower.sum())
}

fun main() {
    val file = File("src/main/kotlin/day2/input.txt")

    part1(file)
    part2(file)
}

Compiled from "Day2.kt"
public final class day2.Day2Kt {
  public static final void part1(java.io.File);
    Code:
       0: aload_0
       1: ldc           #9                  // String file
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: anewarray     #17                 // class java/lang/Integer
      10: astore_1
      11: aload_0
      12: aconst_null
      13: iconst_1
      14: aconst_null
      15: invokestatic  #23                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      18: checkcast     #25                 // class java/lang/Iterable
      21: invokeinterface #29,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      26: astore_2
      27: iconst_0
      28: istore_3
      29: aload_2
      30: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      35: ifeq          359
      38: iload_3
      39: istore        4
      41: iload_3
      42: iconst_1
      43: iadd
      44: istore_3
      45: aload_2
      46: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: checkcast     #41                 // class java/lang/String
      54: astore        5
      56: aload         5
      58: checkcast     #43                 // class java/lang/CharSequence
      61: iconst_1
      62: anewarray     #41                 // class java/lang/String
      65: astore        7
      67: aload         7
      69: iconst_0
      70: ldc           #45                 // String :
      72: aastore
      73: aload         7
      75: iconst_0
      76: iconst_0
      77: bipush        6
      79: aconst_null
      80: invokestatic  #51                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      83: iconst_1
      84: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      89: checkcast     #43                 // class java/lang/CharSequence
      92: iconst_1
      93: anewarray     #41                 // class java/lang/String
      96: astore        7
      98: aload         7
     100: iconst_0
     101: ldc           #59                 // String ;
     103: aastore
     104: aload         7
     106: iconst_0
     107: iconst_0
     108: bipush        6
     110: aconst_null
     111: invokestatic  #51                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     114: astore        6
     116: aload         6
     118: invokeinterface #60,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     123: astore        7
     125: aload         7
     127: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     132: ifeq          341
     135: aload         7
     137: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     142: checkcast     #41                 // class java/lang/String
     145: astore        8
     147: aload         8
     149: checkcast     #43                 // class java/lang/CharSequence
     152: iconst_1
     153: anewarray     #41                 // class java/lang/String
     156: astore        10
     158: aload         10
     160: iconst_0
     161: ldc           #62                 // String ,
     163: aastore
     164: aload         10
     166: iconst_0
     167: iconst_0
     168: bipush        6
     170: aconst_null
     171: invokestatic  #51                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     174: astore        9
     176: aload         9
     178: invokeinterface #60,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     183: astore        10
     185: aload         10
     187: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     192: ifeq          125
     195: aload         10
     197: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     202: checkcast     #41                 // class java/lang/String
     205: astore        11
     207: aload         11
     209: checkcast     #43                 // class java/lang/CharSequence
     212: iconst_1
     213: newarray       char
     215: astore        13
     217: aload         13
     219: iconst_0
     220: bipush        32
     222: castore
     223: aload         13
     225: iconst_0
     226: iconst_0
     227: bipush        6
     229: aconst_null
     230: invokestatic  #65                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     233: iconst_0
     234: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     239: checkcast     #41                 // class java/lang/String
     242: invokestatic  #69                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     245: istore        12
     247: aload         11
     249: checkcast     #43                 // class java/lang/CharSequence
     252: iconst_1
     253: newarray       char
     255: astore        14
     257: aload         14
     259: iconst_0
     260: bipush        32
     262: castore
     263: aload         14
     265: iconst_0
     266: iconst_0
     267: bipush        6
     269: aconst_null
     270: invokestatic  #65                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     273: iconst_1
     274: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     279: checkcast     #41                 // class java/lang/String
     282: astore        13
     284: iload         12
     286: bipush        14
     288: if_icmpgt     29
     291: iload         12
     293: bipush        13
     295: if_icmple     321
     298: aload         13
     300: ldc           #71                 // String red
     302: invokestatic  #75                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     305: ifne          29
     308: aload         13
     310: ldc           #77                 // String green
     312: invokestatic  #75                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     315: ifeq          321
     318: goto          29
     321: iload         12
     323: bipush        12
     325: if_icmple     185
     328: aload         13
     330: ldc           #71                 // String red
     332: invokestatic  #75                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     335: ifeq          185
     338: goto          29
     341: aload_1
     342: iload         4
     344: iconst_1
     345: iadd
     346: invokestatic  #81                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     349: invokestatic  #87                 // Method kotlin/collections/ArraysKt.plus:([Ljava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;
     352: checkcast     #89                 // class "[Ljava/lang/Integer;"
     355: astore_1
     356: goto          29
     359: aload_1
     360: invokestatic  #93                 // Method kotlin/collections/ArraysKt.sumOfInt:([Ljava/lang/Integer;)I
     363: istore_2
     364: getstatic     #99                 // Field java/lang/System.out:Ljava/io/PrintStream;
     367: iload_2
     368: invokevirtual #105                // Method java/io/PrintStream.println:(I)V
     371: return

  public static final void part2(java.io.File);
    Code:
       0: aload_0
       1: ldc           #9                  // String file
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: anewarray     #17                 // class java/lang/Integer
      10: astore_1
      11: aload_0
      12: aconst_null
      13: iconst_1
      14: aconst_null
      15: invokestatic  #23                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      18: invokeinterface #60,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      23: astore_2
      24: aload_2
      25: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          470
      33: aload_2
      34: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #41                 // class java/lang/String
      42: astore_3
      43: aload_3
      44: checkcast     #43                 // class java/lang/CharSequence
      47: iconst_1
      48: anewarray     #41                 // class java/lang/String
      51: astore        5
      53: aload         5
      55: iconst_0
      56: ldc           #45                 // String :
      58: aastore
      59: aload         5
      61: iconst_0
      62: iconst_0
      63: bipush        6
      65: aconst_null
      66: invokestatic  #51                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      69: iconst_1
      70: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      75: checkcast     #43                 // class java/lang/CharSequence
      78: iconst_1
      79: anewarray     #41                 // class java/lang/String
      82: astore        5
      84: aload         5
      86: iconst_0
      87: ldc           #59                 // String ;
      89: aastore
      90: aload         5
      92: iconst_0
      93: iconst_0
      94: bipush        6
      96: aconst_null
      97: invokestatic  #51                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     100: astore        4
     102: iconst_3
     103: anewarray     #125                // class kotlin/Pair
     106: astore        6
     108: aload         6
     110: iconst_0
     111: new           #125                // class kotlin/Pair
     114: dup
     115: ldc           #71                 // String red
     117: iconst_1
     118: invokestatic  #81                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     121: invokespecial #129                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     124: aastore
     125: aload         6
     127: iconst_1
     128: new           #125                // class kotlin/Pair
     131: dup
     132: ldc           #77                 // String green
     134: iconst_1
     135: invokestatic  #81                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: invokespecial #129                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     141: aastore
     142: aload         6
     144: iconst_2
     145: new           #125                // class kotlin/Pair
     148: dup
     149: ldc           #131                // String blue
     151: iconst_1
     152: invokestatic  #81                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     155: invokespecial #129                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     158: aastore
     159: aload         6
     161: invokestatic  #137                // Method kotlin/collections/MapsKt.mutableMapOf:([Lkotlin/Pair;)Ljava/util/Map;
     164: astore        5
     166: iconst_0
     167: istore        6
     169: iconst_1
     170: istore        6
     172: aload         4
     174: invokeinterface #60,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     179: astore        7
     181: aload         7
     183: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     188: ifeq          386
     191: aload         7
     193: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     198: checkcast     #41                 // class java/lang/String
     201: astore        8
     203: aload         8
     205: checkcast     #43                 // class java/lang/CharSequence
     208: iconst_1
     209: anewarray     #41                 // class java/lang/String
     212: astore        10
     214: aload         10
     216: iconst_0
     217: ldc           #62                 // String ,
     219: aastore
     220: aload         10
     222: iconst_0
     223: iconst_0
     224: bipush        6
     226: aconst_null
     227: invokestatic  #51                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     230: astore        9
     232: aload         9
     234: invokeinterface #60,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     239: astore        10
     241: aload         10
     243: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     248: ifeq          181
     251: aload         10
     253: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     258: checkcast     #41                 // class java/lang/String
     261: astore        11
     263: aload         11
     265: checkcast     #43                 // class java/lang/CharSequence
     268: iconst_1
     269: newarray       char
     271: astore        13
     273: aload         13
     275: iconst_0
     276: bipush        32
     278: castore
     279: aload         13
     281: iconst_0
     282: iconst_0
     283: bipush        6
     285: aconst_null
     286: invokestatic  #65                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     289: iconst_0
     290: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     295: checkcast     #41                 // class java/lang/String
     298: invokestatic  #69                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     301: istore        12
     303: aload         11
     305: checkcast     #43                 // class java/lang/CharSequence
     308: iconst_1
     309: newarray       char
     311: astore        14
     313: aload         14
     315: iconst_0
     316: bipush        32
     318: castore
     319: aload         14
     321: iconst_0
     322: iconst_0
     323: bipush        6
     325: aconst_null
     326: invokestatic  #65                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     329: iconst_1
     330: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     335: checkcast     #41                 // class java/lang/String
     338: astore        13
     340: iload         12
     342: aload         5
     344: aload         13
     346: invokeinterface #142,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     351: dup
     352: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     355: checkcast     #148                // class java/lang/Number
     358: invokevirtual #152                // Method java/lang/Number.intValue:()I
     361: if_icmple     241
     364: iload         12
     366: invokestatic  #81                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     369: astore        15
     371: aload         5
     373: aload         13
     375: aload         15
     377: invokeinterface #156,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     382: pop
     383: goto          241
     386: aload         5
     388: invokeinterface #160,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     393: checkcast     #25                 // class java/lang/Iterable
     396: astore        7
     398: iconst_0
     399: istore        8
     401: aload         7
     403: invokeinterface #29,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     408: astore        9
     410: aload         9
     412: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     417: ifeq          453
     420: aload         9
     422: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     427: astore        10
     429: aload         10
     431: checkcast     #148                // class java/lang/Number
     434: invokevirtual #152                // Method java/lang/Number.intValue:()I
     437: istore        11
     439: iconst_0
     440: istore        12
     442: iload         6
     444: iload         11
     446: imul
     447: istore        6
     449: nop
     450: goto          410
     453: nop
     454: aload_1
     455: iload         6
     457: invokestatic  #81                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     460: invokestatic  #87                 // Method kotlin/collections/ArraysKt.plus:([Ljava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;
     463: checkcast     #89                 // class "[Ljava/lang/Integer;"
     466: astore_1
     467: goto          24
     470: aload_1
     471: invokestatic  #93                 // Method kotlin/collections/ArraysKt.sumOfInt:([Ljava/lang/Integer;)I
     474: istore_2
     475: getstatic     #99                 // Field java/lang/System.out:Ljava/io/PrintStream;
     478: iload_2
     479: invokevirtual #105                // Method java/io/PrintStream.println:(I)V
     482: return

  public static final void main();
    Code:
       0: new           #120                // class java/io/File
       3: dup
       4: ldc           #175                // String src/main/kotlin/day2/input.txt
       6: invokespecial #178                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: aload_0
      11: invokestatic  #180                // Method part1:(Ljava/io/File;)V
      14: aload_0
      15: invokestatic  #182                // Method part2:(Ljava/io/File;)V
      18: return

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


package day1

import java.io.File

fun part1(file: File) {
    var numbers: Array<Int> = arrayOf()

    for (line in file.readLines()) {
        val firstNum = line.indexOfFirst { it.isDigit() }
        val lastNum = line.indexOfLast { it.isDigit() }
        val number = "${line[firstNum]}${line[lastNum]}"

        numbers += number.toInt()
    }

    println(numbers.sum())
}

fun part2(file: File) {
    val dictionary: Map<String, Int> = mapOf(
        Pair("one", 1), Pair("two", 2),Pair("three", 3),
        Pair("four", 4), Pair("five", 5),Pair("six", 6),
        Pair("seven", 7), Pair("eight", 8),Pair("nine", 9),
        Pair("1", 1), Pair("2", 2),Pair("3", 3),
        Pair("4", 4), Pair("5", 5),Pair("6", 6),
        Pair("7", 7), Pair("8", 8),Pair("9", 9),
        )
    var numbers: Array<Int> = arrayOf()

    for (line in file.readLines()) {
        var firstNum = 0
        var lastNum = 0
        var minIndex = Int.MAX_VALUE
        var maxIndex = 0

        for (key in dictionary.keys) {
            val firstIndex = line.indexOf(key)

            if (firstIndex == -1) continue

            val lastIndex = line.lastIndexOf(key)

            if (firstIndex <= minIndex) {
                firstNum = dictionary[key]!!
                minIndex = firstIndex
            }

            if (lastIndex >= maxIndex) {
                lastNum = dictionary[key]!!
                maxIndex = lastIndex
            }
        }

        numbers += ((firstNum * 10) + lastNum)
    }

    println(numbers.sum())
}

fun main() {
    val file = File("src/main/kotlin/day1/input.txt")

    part1(file)
    part2(file)
}

Compiled from "Day1.kt"
public final class day1.Day1Kt {
  public static final void part1(java.io.File);
    Code:
       0: aload_0
       1: ldc           #9                  // String file
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: anewarray     #17                 // class java/lang/Integer
      10: astore_1
      11: aload_0
      12: aconst_null
      13: iconst_1
      14: aconst_null
      15: invokestatic  #23                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      18: invokeinterface #29,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      23: astore_2
      24: aload_2
      25: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          227
      33: aload_2
      34: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #41                 // class java/lang/String
      42: astore_3
      43: aload_3
      44: checkcast     #43                 // class java/lang/CharSequence
      47: astore        5
      49: iconst_0
      50: istore        6
      52: iconst_0
      53: istore        7
      55: aload         5
      57: invokeinterface #47,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      62: istore        8
      64: iload         7
      66: iload         8
      68: if_icmpge     105
      71: aload         5
      73: iload         7
      75: invokeinterface #51,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      80: istore        9
      82: iconst_0
      83: istore        10
      85: iload         9
      87: invokestatic  #57                 // Method java/lang/Character.isDigit:(C)Z
      90: nop
      91: ifeq          99
      94: iload         7
      96: goto          106
      99: iinc          7, 1
     102: goto          64
     105: iconst_m1
     106: istore        4
     108: aload_3
     109: checkcast     #43                 // class java/lang/CharSequence
     112: astore        6
     114: iconst_0
     115: istore        7
     117: aload         6
     119: invokeinterface #47,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     124: iconst_m1
     125: iadd
     126: istore        8
     128: iconst_0
     129: iload         8
     131: if_icmpgt     175
     134: iload         8
     136: istore        9
     138: iinc          8, -1
     141: aload         6
     143: iload         9
     145: invokeinterface #51,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     150: istore        10
     152: iconst_0
     153: istore        11
     155: iload         10
     157: invokestatic  #57                 // Method java/lang/Character.isDigit:(C)Z
     160: nop
     161: ifeq          169
     164: iload         9
     166: goto          176
     169: iconst_0
     170: iload         8
     172: if_icmple     134
     175: iconst_m1
     176: istore        5
     178: new           #59                 // class java/lang/StringBuilder
     181: dup
     182: invokespecial #63                 // Method java/lang/StringBuilder."<init>":()V
     185: aload_3
     186: iload         4
     188: invokevirtual #64                 // Method java/lang/String.charAt:(I)C
     191: invokevirtual #68                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     194: aload_3
     195: iload         5
     197: invokevirtual #64                 // Method java/lang/String.charAt:(I)C
     200: invokevirtual #68                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     203: invokevirtual #72                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     206: astore        6
     208: aload_1
     209: aload         6
     211: invokestatic  #76                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     214: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     217: invokestatic  #86                 // Method kotlin/collections/ArraysKt.plus:([Ljava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;
     220: checkcast     #88                 // class "[Ljava/lang/Integer;"
     223: astore_1
     224: goto          24
     227: aload_1
     228: invokestatic  #92                 // Method kotlin/collections/ArraysKt.sumOfInt:([Ljava/lang/Integer;)I
     231: istore_2
     232: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
     235: iload_2
     236: invokevirtual #104                // Method java/io/PrintStream.println:(I)V
     239: return

  public static final void part2(java.io.File);
    Code:
       0: aload_0
       1: ldc           #9                  // String file
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: bipush        18
       8: anewarray     #127                // class kotlin/Pair
      11: astore_2
      12: aload_2
      13: iconst_0
      14: new           #127                // class kotlin/Pair
      17: dup
      18: ldc           #129                // String one
      20: iconst_1
      21: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      24: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      27: aastore
      28: aload_2
      29: iconst_1
      30: new           #127                // class kotlin/Pair
      33: dup
      34: ldc           #134                // String two
      36: iconst_2
      37: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      43: aastore
      44: aload_2
      45: iconst_2
      46: new           #127                // class kotlin/Pair
      49: dup
      50: ldc           #136                // String three
      52: iconst_3
      53: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      56: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      59: aastore
      60: aload_2
      61: iconst_3
      62: new           #127                // class kotlin/Pair
      65: dup
      66: ldc           #138                // String four
      68: iconst_4
      69: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      75: aastore
      76: aload_2
      77: iconst_4
      78: new           #127                // class kotlin/Pair
      81: dup
      82: ldc           #140                // String five
      84: iconst_5
      85: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      91: aastore
      92: aload_2
      93: iconst_5
      94: new           #127                // class kotlin/Pair
      97: dup
      98: ldc           #142                // String six
     100: bipush        6
     102: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     108: aastore
     109: aload_2
     110: bipush        6
     112: new           #127                // class kotlin/Pair
     115: dup
     116: ldc           #144                // String seven
     118: bipush        7
     120: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     123: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     126: aastore
     127: aload_2
     128: bipush        7
     130: new           #127                // class kotlin/Pair
     133: dup
     134: ldc           #146                // String eight
     136: bipush        8
     138: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     141: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     144: aastore
     145: aload_2
     146: bipush        8
     148: new           #127                // class kotlin/Pair
     151: dup
     152: ldc           #148                // String nine
     154: bipush        9
     156: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     159: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     162: aastore
     163: aload_2
     164: bipush        9
     166: new           #127                // class kotlin/Pair
     169: dup
     170: ldc           #150                // String 1
     172: iconst_1
     173: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     176: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     179: aastore
     180: aload_2
     181: bipush        10
     183: new           #127                // class kotlin/Pair
     186: dup
     187: ldc           #152                // String 2
     189: iconst_2
     190: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     193: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     196: aastore
     197: aload_2
     198: bipush        11
     200: new           #127                // class kotlin/Pair
     203: dup
     204: ldc           #154                // String 3
     206: iconst_3
     207: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     210: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     213: aastore
     214: aload_2
     215: bipush        12
     217: new           #127                // class kotlin/Pair
     220: dup
     221: ldc           #156                // String 4
     223: iconst_4
     224: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     227: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     230: aastore
     231: aload_2
     232: bipush        13
     234: new           #127                // class kotlin/Pair
     237: dup
     238: ldc           #158                // String 5
     240: iconst_5
     241: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     244: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     247: aastore
     248: aload_2
     249: bipush        14
     251: new           #127                // class kotlin/Pair
     254: dup
     255: ldc           #160                // String 6
     257: bipush        6
     259: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     262: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     265: aastore
     266: aload_2
     267: bipush        15
     269: new           #127                // class kotlin/Pair
     272: dup
     273: ldc           #162                // String 7
     275: bipush        7
     277: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     280: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     283: aastore
     284: aload_2
     285: bipush        16
     287: new           #127                // class kotlin/Pair
     290: dup
     291: ldc           #164                // String 8
     293: bipush        8
     295: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     298: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     301: aastore
     302: aload_2
     303: bipush        17
     305: new           #127                // class kotlin/Pair
     308: dup
     309: ldc           #166                // String 9
     311: bipush        9
     313: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     316: invokespecial #132                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     319: aastore
     320: aload_2
     321: invokestatic  #172                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     324: astore_1
     325: iconst_0
     326: anewarray     #17                 // class java/lang/Integer
     329: astore_2
     330: aload_0
     331: aconst_null
     332: iconst_1
     333: aconst_null
     334: invokestatic  #23                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
     337: invokeinterface #29,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     342: astore_3
     343: aload_3
     344: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     349: ifeq          538
     352: aload_3
     353: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     358: checkcast     #41                 // class java/lang/String
     361: astore        4
     363: iconst_0
     364: istore        5
     366: iconst_0
     367: istore        6
     369: ldc           #173                // int 2147483647
     371: istore        7
     373: iconst_0
     374: istore        8
     376: aload_1
     377: invokeinterface #179,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     382: invokeinterface #182,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     387: astore        9
     389: aload         9
     391: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     396: ifeq          516
     399: aload         9
     401: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     406: checkcast     #41                 // class java/lang/String
     409: astore        10
     411: aload         4
     413: checkcast     #43                 // class java/lang/CharSequence
     416: aload         10
     418: iconst_0
     419: iconst_0
     420: bipush        6
     422: aconst_null
     423: invokestatic  #188                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
     426: istore        11
     428: iload         11
     430: iconst_m1
     431: if_icmpeq     389
     434: aload         4
     436: checkcast     #43                 // class java/lang/CharSequence
     439: aload         10
     441: iconst_0
     442: iconst_0
     443: bipush        6
     445: aconst_null
     446: invokestatic  #191                // Method kotlin/text/StringsKt.lastIndexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
     449: istore        12
     451: iload         11
     453: iload         7
     455: if_icmpgt     482
     458: aload_1
     459: aload         10
     461: invokeinterface #195,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     466: dup
     467: invokestatic  #199                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     470: checkcast     #201                // class java/lang/Number
     473: invokevirtual #204                // Method java/lang/Number.intValue:()I
     476: istore        5
     478: iload         11
     480: istore        7
     482: iload         12
     484: iload         8
     486: if_icmplt     389
     489: aload_1
     490: aload         10
     492: invokeinterface #195,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     497: dup
     498: invokestatic  #199                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     501: checkcast     #201                // class java/lang/Number
     504: invokevirtual #204                // Method java/lang/Number.intValue:()I
     507: istore        6
     509: iload         12
     511: istore        8
     513: goto          389
     516: aload_2
     517: iload         5
     519: bipush        10
     521: imul
     522: iload         6
     524: iadd
     525: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     528: invokestatic  #86                 // Method kotlin/collections/ArraysKt.plus:([Ljava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;
     531: checkcast     #88                 // class "[Ljava/lang/Integer;"
     534: astore_2
     535: goto          343
     538: aload_2
     539: invokestatic  #92                 // Method kotlin/collections/ArraysKt.sumOfInt:([Ljava/lang/Integer;)I
     542: istore_3
     543: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
     546: iload_3
     547: invokevirtual #104                // Method java/io/PrintStream.println:(I)V
     550: return

  public static final void main();
    Code:
       0: new           #124                // class java/io/File
       3: dup
       4: ldc           #214                // String src/main/kotlin/day1/input.txt
       6: invokespecial #217                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: aload_0
      11: invokestatic  #219                // Method part1:(Ljava/io/File;)V
      14: aload_0
      15: invokestatic  #221                // Method part2:(Ljava/io/File;)V
      18: return

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


package org.davetcode.aoc2021.day9

import java.io.File

fun main() {
    val testData = processFile("c:\\code\\home\\aoc2021day9\\test.txt")
    val inputData = processFile("c:\\code\\home\\aoc2021day9\\input.txt")
    println(part1(testData))
    println(part1(inputData))
    println(part2(testData))
    println(part2(inputData))
}

fun processFile(file: String): Array<Array<Int>> {
    return File(file)
        .readLines()
        .map { line -> line.toCharArray().map { it - '0' }.toTypedArray() }
        .toTypedArray()
}

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

fun getLowPoints(data: Array<Array<Int>>): List<Point> {
    val lowPoints = mutableListOf<Point>()
    for (y in data.indices) {
        for (x in data[0].indices) {
            val dataPoint = data[y][x]
            if (x > 0 && data[y][x - 1] <= dataPoint) continue
            if (x < data[0].size - 1 && data[y][x + 1] <= dataPoint) continue
            if (y > 0 && data[y - 1][x] <= dataPoint) continue
            if (y < data.size - 1 && data[y + 1][x] <= dataPoint) continue
            lowPoints.add(Point(x, y))
        }
    }

    return lowPoints
}

fun calculateBasinSize(data: Array<Array<Int>>, startPoint: Point): Int {
    fun inner(currentPoint: Point, basinPoints: MutableSet<Point>) {
        val (x, y) = currentPoint

        // Up
        if (y > 0 && data[y][x] < data[y - 1][x] && data[y - 1][x] != 9) {
            basinPoints.add(Point(x, y - 1))
            inner(Point(currentPoint.x, currentPoint.y - 1), basinPoints)
        }

        // Down
        if (y < (data.size - 1) && data[y][x] < data[y + 1][x] && data[y + 1][x] != 9) {
            basinPoints.add(Point(x, y + 1))
            inner(Point(currentPoint.x, currentPoint.y + 1), basinPoints)
        }

        // Left
        if (x > 0 && data[y][x] < data[y][x - 1] && data[y][x - 1] != 9) {
            basinPoints.add(Point(x - 1, y))
            inner(Point(currentPoint.x - 1, currentPoint.y), basinPoints)
        }

        // Right
        if (x < (data[y].size - 1) && data[y][x] < data[y][x + 1] && data[y][x + 1] != 9) {
            basinPoints.add(Point(x + 1, y))
            inner(Point(currentPoint.x + 1, currentPoint.y), basinPoints)
        }
    }

    val basinPoints = mutableSetOf(startPoint)
    inner(startPoint, basinPoints)
    return basinPoints.size
}

fun part2(data: Array<Array<Int>>): Int {
    val lowPoints = getLowPoints(data)

    val basins = lowPoints
        .map { calculateBasinSize(data, it) }
        .sortedDescending()
    println(basins)

    // Assume that all low points are in their own basin, no saddles
    return lowPoints
        .map { calculateBasinSize(data, it) }
        .sortedDescending()
        .take(3)
        .reduce { acc, i -> acc * i }
}

fun part1(data: Array<Array<Int>>): Int {
    val lowPoints = getLowPoints(data)
    return lowPoints.sumOf { data[it.y][it.x] + 1 }
}

Compiled from "Program.kt"
public final class org.davetcode.aoc2021.day9.ProgramKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String c:\\code\\home\\aoc2021day9\\test.txt
       2: invokestatic  #12                 // Method processFile:(Ljava/lang/String;)[[Ljava/lang/Integer;
       5: astore_0
       6: ldc           #14                 // String c:\\code\\home\\aoc2021day9\\input.txt
       8: invokestatic  #12                 // Method processFile:(Ljava/lang/String;)[[Ljava/lang/Integer;
      11: astore_1
      12: aload_0
      13: invokestatic  #18                 // Method part1:([[Ljava/lang/Integer;)I
      16: istore_2
      17: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      20: iload_2
      21: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      24: aload_1
      25: invokestatic  #18                 // Method part1:([[Ljava/lang/Integer;)I
      28: istore_2
      29: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      32: iload_2
      33: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      36: aload_0
      37: invokestatic  #33                 // Method part2:([[Ljava/lang/Integer;)I
      40: istore_2
      41: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      44: iload_2
      45: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      48: aload_1
      49: invokestatic  #33                 // Method part2:([[Ljava/lang/Integer;)I
      52: istore_2
      53: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      56: iload_2
      57: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      60: return

  public static final java.lang.Integer[][] processFile(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #39                 // String file
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #47                 // class java/io/File
       9: dup
      10: aload_0
      11: invokespecial #51                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      14: aconst_null
      15: iconst_1
      16: aconst_null
      17: invokestatic  #57                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      20: checkcast     #59                 // class java/lang/Iterable
      23: astore_1
      24: nop
      25: iconst_0
      26: istore_2
      27: aload_1
      28: astore_3
      29: new           #61                 // class java/util/ArrayList
      32: dup
      33: aload_1
      34: bipush        10
      36: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      39: invokespecial #69                 // Method java/util/ArrayList."<init>":(I)V
      42: checkcast     #71                 // class java/util/Collection
      45: astore        4
      47: iconst_0
      48: istore        5
      50: aload_3
      51: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        6
      58: aload         6
      60: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          232
      68: aload         6
      70: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        7
      77: aload         4
      79: aload         7
      81: checkcast     #87                 // class java/lang/String
      84: astore        8
      86: astore        21
      88: iconst_0
      89: istore        9
      91: aload         8
      93: invokevirtual #91                 // Method java/lang/String.toCharArray:()[C
      96: dup
      97: ldc           #93                 // String toCharArray(...)
      99: invokestatic  #96                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     102: astore        10
     104: nop
     105: iconst_0
     106: istore        11
     108: aload         10
     110: astore        12
     112: new           #61                 // class java/util/ArrayList
     115: dup
     116: aload         10
     118: arraylength
     119: invokespecial #69                 // Method java/util/ArrayList."<init>":(I)V
     122: checkcast     #71                 // class java/util/Collection
     125: astore        13
     127: iconst_0
     128: istore        14
     130: iconst_0
     131: istore        15
     133: aload         12
     135: arraylength
     136: istore        16
     138: iload         15
     140: iload         16
     142: if_icmpge     186
     145: aload         12
     147: iload         15
     149: caload
     150: istore        17
     152: aload         13
     154: iload         17
     156: istore        18
     158: astore        19
     160: iconst_0
     161: istore        20
     163: iload         18
     165: bipush        48
     167: isub
     168: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     171: aload         19
     173: swap
     174: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     179: pop
     180: iinc          15, 1
     183: goto          138
     186: aload         13
     188: checkcast     #108                // class java/util/List
     191: nop
     192: checkcast     #71                 // class java/util/Collection
     195: astore        10
     197: nop
     198: iconst_0
     199: istore        11
     201: aload         10
     203: astore        12
     205: aload         12
     207: iconst_0
     208: anewarray     #98                 // class java/lang/Integer
     211: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     216: checkcast     #114                // class "[Ljava/lang/Integer;"
     219: nop
     220: aload         21
     222: swap
     223: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     228: pop
     229: goto          58
     232: aload         4
     234: checkcast     #108                // class java/util/List
     237: nop
     238: checkcast     #71                 // class java/util/Collection
     241: astore_1
     242: nop
     243: iconst_0
     244: istore_2
     245: aload_1
     246: astore_3
     247: aload_3
     248: iconst_0
     249: anewarray     #114                // class "[Ljava/lang/Integer;"
     252: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     257: checkcast     #115                // class "[[Ljava/lang/Integer;"
     260: areturn

  public static final java.util.List<org.davetcode.aoc2021.day9.Point> getLowPoints(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc           #141                // String data
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #61                 // class java/util/ArrayList
       9: dup
      10: invokespecial #143                // Method java/util/ArrayList."<init>":()V
      13: checkcast     #108                // class java/util/List
      16: astore_1
      17: iconst_0
      18: istore_2
      19: aload_0
      20: checkcast     #145                // class "[Ljava/lang/Object;"
      23: arraylength
      24: istore_3
      25: iload_2
      26: iload_3
      27: if_icmpge     181
      30: iconst_0
      31: istore        4
      33: aload_0
      34: iconst_0
      35: aaload
      36: arraylength
      37: istore        5
      39: iload         4
      41: iload         5
      43: if_icmpge     175
      46: aload_0
      47: iload_2
      48: aaload
      49: iload         4
      51: aaload
      52: invokevirtual #149                // Method java/lang/Integer.intValue:()I
      55: istore        6
      57: iload         4
      59: ifle          78
      62: aload_0
      63: iload_2
      64: aaload
      65: iload         4
      67: iconst_1
      68: isub
      69: aaload
      70: invokevirtual #149                // Method java/lang/Integer.intValue:()I
      73: iload         6
      75: if_icmple     169
      78: iload         4
      80: aload_0
      81: iconst_0
      82: aaload
      83: arraylength
      84: iconst_1
      85: isub
      86: if_icmpge     105
      89: aload_0
      90: iload_2
      91: aaload
      92: iload         4
      94: iconst_1
      95: iadd
      96: aaload
      97: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     100: iload         6
     102: if_icmple     169
     105: iload_2
     106: ifle          125
     109: aload_0
     110: iload_2
     111: iconst_1
     112: isub
     113: aaload
     114: iload         4
     116: aaload
     117: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     120: iload         6
     122: if_icmple     169
     125: iload_2
     126: aload_0
     127: checkcast     #145                // class "[Ljava/lang/Object;"
     130: arraylength
     131: iconst_1
     132: isub
     133: if_icmpge     152
     136: aload_0
     137: iload_2
     138: iconst_1
     139: iadd
     140: aaload
     141: iload         4
     143: aaload
     144: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     147: iload         6
     149: if_icmple     169
     152: aload_1
     153: new           #151                // class org/davetcode/aoc2021/day9/Point
     156: dup
     157: iload         4
     159: iload_2
     160: invokespecial #154                // Method org/davetcode/aoc2021/day9/Point."<init>":(II)V
     163: invokeinterface #155,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     168: pop
     169: iinc          4, 1
     172: goto          39
     175: iinc          2, 1
     178: goto          25
     181: aload_1
     182: areturn

  public static final int calculateBasinSize(java.lang.Integer[][], org.davetcode.aoc2021.day9.Point);
    Code:
       0: aload_0
       1: ldc           #141                // String data
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #164                // String startPoint
       9: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_1
      13: anewarray     #151                // class org/davetcode/aoc2021/day9/Point
      16: astore_3
      17: aload_3
      18: iconst_0
      19: aload_1
      20: aastore
      21: aload_3
      22: invokestatic  #170                // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
      25: astore_2
      26: aload_0
      27: aload_1
      28: aload_2
      29: invokestatic  #174                // Method calculateBasinSize$inner:([[Ljava/lang/Integer;Lorg/davetcode/aoc2021/day9/Point;Ljava/util/Set;)V
      32: aload_2
      33: invokeinterface #179,  1          // InterfaceMethod java/util/Set.size:()I
      38: ireturn

  public static final int part2(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc           #141                // String data
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #184                // Method getLowPoints:([[Ljava/lang/Integer;)Ljava/util/List;
      10: astore_1
      11: aload_1
      12: checkcast     #59                 // class java/lang/Iterable
      15: astore_3
      16: nop
      17: iconst_0
      18: istore        4
      20: aload_3
      21: astore        5
      23: new           #61                 // class java/util/ArrayList
      26: dup
      27: aload_3
      28: bipush        10
      30: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #69                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #71                 // class java/util/Collection
      39: astore        6
      41: iconst_0
      42: istore        7
      44: aload         5
      46: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        8
      53: aload         8
      55: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          107
      63: aload         8
      65: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        9
      72: aload         6
      74: aload         9
      76: checkcast     #151                // class org/davetcode/aoc2021/day9/Point
      79: astore        10
      81: astore        12
      83: iconst_0
      84: istore        11
      86: aload_0
      87: aload         10
      89: invokestatic  #186                // Method calculateBasinSize:([[Ljava/lang/Integer;Lorg/davetcode/aoc2021/day9/Point;)I
      92: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      95: aload         12
      97: swap
      98: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     103: pop
     104: goto          53
     107: aload         6
     109: checkcast     #108                // class java/util/List
     112: nop
     113: checkcast     #59                 // class java/lang/Iterable
     116: invokestatic  #190                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     119: astore_2
     120: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
     123: aload_2
     124: invokevirtual #193                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     127: aload_1
     128: checkcast     #59                 // class java/lang/Iterable
     131: astore_3
     132: nop
     133: iconst_0
     134: istore        4
     136: aload_3
     137: astore        5
     139: new           #61                 // class java/util/ArrayList
     142: dup
     143: aload_3
     144: bipush        10
     146: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     149: invokespecial #69                 // Method java/util/ArrayList."<init>":(I)V
     152: checkcast     #71                 // class java/util/Collection
     155: astore        6
     157: iconst_0
     158: istore        7
     160: aload         5
     162: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     167: astore        8
     169: aload         8
     171: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     176: ifeq          223
     179: aload         8
     181: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     186: astore        9
     188: aload         6
     190: aload         9
     192: checkcast     #151                // class org/davetcode/aoc2021/day9/Point
     195: astore        10
     197: astore        12
     199: iconst_0
     200: istore        11
     202: aload_0
     203: aload         10
     205: invokestatic  #186                // Method calculateBasinSize:([[Ljava/lang/Integer;Lorg/davetcode/aoc2021/day9/Point;)I
     208: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     211: aload         12
     213: swap
     214: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     219: pop
     220: goto          169
     223: aload         6
     225: checkcast     #108                // class java/util/List
     228: nop
     229: checkcast     #59                 // class java/lang/Iterable
     232: invokestatic  #190                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     235: checkcast     #59                 // class java/lang/Iterable
     238: iconst_3
     239: invokestatic  #197                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     242: checkcast     #59                 // class java/lang/Iterable
     245: astore_3
     246: nop
     247: iconst_0
     248: istore        4
     250: aload_3
     251: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     256: astore        5
     258: aload         5
     260: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     265: ifne          278
     268: new           #199                // class java/lang/UnsupportedOperationException
     271: dup
     272: ldc           #201                // String Empty collection can\'t be reduced.
     274: invokespecial #202                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     277: athrow
     278: aload         5
     280: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     285: astore        6
     287: aload         5
     289: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     294: ifeq          338
     297: aload         6
     299: aload         5
     301: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     306: checkcast     #204                // class java/lang/Number
     309: invokevirtual #205                // Method java/lang/Number.intValue:()I
     312: istore        7
     314: checkcast     #204                // class java/lang/Number
     317: invokevirtual #205                // Method java/lang/Number.intValue:()I
     320: istore        8
     322: iconst_0
     323: istore        9
     325: iload         8
     327: iload         7
     329: imul
     330: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     333: astore        6
     335: goto          287
     338: aload         6
     340: checkcast     #204                // class java/lang/Number
     343: invokevirtual #205                // Method java/lang/Number.intValue:()I
     346: ireturn

  public static final int part1(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc           #141                // String data
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #184                // Method getLowPoints:([[Ljava/lang/Integer;)Ljava/util/List;
      10: astore_1
      11: aload_1
      12: checkcast     #59                 // class java/lang/Iterable
      15: astore_2
      16: iconst_0
      17: istore_3
      18: aload_2
      19: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      24: astore        4
      26: aload         4
      28: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      33: ifeq          87
      36: aload         4
      38: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      43: astore        5
      45: iload_3
      46: aload         5
      48: checkcast     #151                // class org/davetcode/aoc2021/day9/Point
      51: astore        6
      53: istore        8
      55: iconst_0
      56: istore        7
      58: aload_0
      59: aload         6
      61: invokevirtual #219                // Method org/davetcode/aoc2021/day9/Point.getY:()I
      64: aaload
      65: aload         6
      67: invokevirtual #222                // Method org/davetcode/aoc2021/day9/Point.getX:()I
      70: aaload
      71: invokevirtual #149                // Method java/lang/Integer.intValue:()I
      74: iconst_1
      75: iadd
      76: istore        9
      78: iload         8
      80: iload         9
      82: iadd
      83: istore_3
      84: goto          26
      87: iload_3
      88: ireturn

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

  private static final void calculateBasinSize$inner(java.lang.Integer[][], org.davetcode.aoc2021.day9.Point, java.util.Set<org.davetcode.aoc2021.day9.Point>);
    Code:
       0: aload_1
       1: invokevirtual #232                // Method org/davetcode/aoc2021/day9/Point.component1:()I
       4: istore_3
       5: aload_1
       6: invokevirtual #235                // Method org/davetcode/aoc2021/day9/Point.component2:()I
       9: istore        4
      11: iload         4
      13: ifle          96
      16: aload_0
      17: iload         4
      19: aaload
      20: iload_3
      21: aaload
      22: invokevirtual #149                // Method java/lang/Integer.intValue:()I
      25: aload_0
      26: iload         4
      28: iconst_1
      29: isub
      30: aaload
      31: iload_3
      32: aaload
      33: invokevirtual #149                // Method java/lang/Integer.intValue:()I
      36: if_icmpge     96
      39: aload_0
      40: iload         4
      42: iconst_1
      43: isub
      44: aaload
      45: iload_3
      46: aaload
      47: invokevirtual #149                // Method java/lang/Integer.intValue:()I
      50: bipush        9
      52: if_icmpeq     96
      55: aload_2
      56: new           #151                // class org/davetcode/aoc2021/day9/Point
      59: dup
      60: iload_3
      61: iload         4
      63: iconst_1
      64: isub
      65: invokespecial #154                // Method org/davetcode/aoc2021/day9/Point."<init>":(II)V
      68: invokeinterface #236,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      73: pop
      74: aload_0
      75: new           #151                // class org/davetcode/aoc2021/day9/Point
      78: dup
      79: aload_1
      80: invokevirtual #222                // Method org/davetcode/aoc2021/day9/Point.getX:()I
      83: aload_1
      84: invokevirtual #219                // Method org/davetcode/aoc2021/day9/Point.getY:()I
      87: iconst_1
      88: isub
      89: invokespecial #154                // Method org/davetcode/aoc2021/day9/Point."<init>":(II)V
      92: aload_2
      93: invokestatic  #174                // Method calculateBasinSize$inner:([[Ljava/lang/Integer;Lorg/davetcode/aoc2021/day9/Point;Ljava/util/Set;)V
      96: iload         4
      98: aload_0
      99: checkcast     #145                // class "[Ljava/lang/Object;"
     102: arraylength
     103: iconst_1
     104: isub
     105: if_icmpge     188
     108: aload_0
     109: iload         4
     111: aaload
     112: iload_3
     113: aaload
     114: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     117: aload_0
     118: iload         4
     120: iconst_1
     121: iadd
     122: aaload
     123: iload_3
     124: aaload
     125: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     128: if_icmpge     188
     131: aload_0
     132: iload         4
     134: iconst_1
     135: iadd
     136: aaload
     137: iload_3
     138: aaload
     139: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     142: bipush        9
     144: if_icmpeq     188
     147: aload_2
     148: new           #151                // class org/davetcode/aoc2021/day9/Point
     151: dup
     152: iload_3
     153: iload         4
     155: iconst_1
     156: iadd
     157: invokespecial #154                // Method org/davetcode/aoc2021/day9/Point."<init>":(II)V
     160: invokeinterface #236,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     165: pop
     166: aload_0
     167: new           #151                // class org/davetcode/aoc2021/day9/Point
     170: dup
     171: aload_1
     172: invokevirtual #222                // Method org/davetcode/aoc2021/day9/Point.getX:()I
     175: aload_1
     176: invokevirtual #219                // Method org/davetcode/aoc2021/day9/Point.getY:()I
     179: iconst_1
     180: iadd
     181: invokespecial #154                // Method org/davetcode/aoc2021/day9/Point."<init>":(II)V
     184: aload_2
     185: invokestatic  #174                // Method calculateBasinSize$inner:([[Ljava/lang/Integer;Lorg/davetcode/aoc2021/day9/Point;Ljava/util/Set;)V
     188: iload_3
     189: ifle          272
     192: aload_0
     193: iload         4
     195: aaload
     196: iload_3
     197: aaload
     198: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     201: aload_0
     202: iload         4
     204: aaload
     205: iload_3
     206: iconst_1
     207: isub
     208: aaload
     209: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     212: if_icmpge     272
     215: aload_0
     216: iload         4
     218: aaload
     219: iload_3
     220: iconst_1
     221: isub
     222: aaload
     223: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     226: bipush        9
     228: if_icmpeq     272
     231: aload_2
     232: new           #151                // class org/davetcode/aoc2021/day9/Point
     235: dup
     236: iload_3
     237: iconst_1
     238: isub
     239: iload         4
     241: invokespecial #154                // Method org/davetcode/aoc2021/day9/Point."<init>":(II)V
     244: invokeinterface #236,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     249: pop
     250: aload_0
     251: new           #151                // class org/davetcode/aoc2021/day9/Point
     254: dup
     255: aload_1
     256: invokevirtual #222                // Method org/davetcode/aoc2021/day9/Point.getX:()I
     259: iconst_1
     260: isub
     261: aload_1
     262: invokevirtual #219                // Method org/davetcode/aoc2021/day9/Point.getY:()I
     265: invokespecial #154                // Method org/davetcode/aoc2021/day9/Point."<init>":(II)V
     268: aload_2
     269: invokestatic  #174                // Method calculateBasinSize$inner:([[Ljava/lang/Integer;Lorg/davetcode/aoc2021/day9/Point;Ljava/util/Set;)V
     272: iload_3
     273: aload_0
     274: iload         4
     276: aaload
     277: arraylength
     278: iconst_1
     279: isub
     280: if_icmpge     363
     283: aload_0
     284: iload         4
     286: aaload
     287: iload_3
     288: aaload
     289: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     292: aload_0
     293: iload         4
     295: aaload
     296: iload_3
     297: iconst_1
     298: iadd
     299: aaload
     300: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     303: if_icmpge     363
     306: aload_0
     307: iload         4
     309: aaload
     310: iload_3
     311: iconst_1
     312: iadd
     313: aaload
     314: invokevirtual #149                // Method java/lang/Integer.intValue:()I
     317: bipush        9
     319: if_icmpeq     363
     322: aload_2
     323: new           #151                // class org/davetcode/aoc2021/day9/Point
     326: dup
     327: iload_3
     328: iconst_1
     329: iadd
     330: iload         4
     332: invokespecial #154                // Method org/davetcode/aoc2021/day9/Point."<init>":(II)V
     335: invokeinterface #236,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     340: pop
     341: aload_0
     342: new           #151                // class org/davetcode/aoc2021/day9/Point
     345: dup
     346: aload_1
     347: invokevirtual #222                // Method org/davetcode/aoc2021/day9/Point.getX:()I
     350: iconst_1
     351: iadd
     352: aload_1
     353: invokevirtual #219                // Method org/davetcode/aoc2021/day9/Point.getY:()I
     356: invokespecial #154                // Method org/davetcode/aoc2021/day9/Point."<init>":(II)V
     359: aload_2
     360: invokestatic  #174                // Method calculateBasinSize$inner:([[Ljava/lang/Integer;Lorg/davetcode/aoc2021/day9/Point;Ljava/util/Set;)V
     363: return
}