package day25

import java.io.File

fun main() {
    val lines = File("src/day25/input.txt").readLines()
    val seafloor = Seafloor(lines[0].length, lines.size,
        Herd.values().associateWith { herd -> herd.parse(lines) }.toMutableMap())

    while (seafloor.move()) {}

    println(seafloor.steps)
}

data class Seafloor(val width: Int, val height: Int, val cucumbers: MutableMap<Herd, Set<Coord>>, var steps: Int = 0)

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

enum class Herd(val ch: Char, val delta: Coord) {
    EAST('>', Coord(1, 0)),
    SOUTH('v', Coord(0, 1))
}

fun Herd.parse(lines: List<String>) =
    lines.mapIndexed { j, row -> row.toList().mapIndexedNotNull { i, c -> if (c == ch) Coord(i, j) else null } }
        .flatten().toSet()

fun Seafloor.empty(coord: Coord) = cucumbers.values.none { coords -> coords.contains(coord) }

fun Seafloor.print() {
    for (y in 0 until height) {
        for (x in 0 until width) {
            print(Herd.values()
                .mapNotNull { if (cucumbers[it]!!.contains(Coord(x, y))) it.ch else null }
                .firstOrNull() ?: '.')
        }
        println()
    }
    println()
}

fun Seafloor.move(): Boolean {
    var moved = false
    Herd.values().forEach { herd ->
        cucumbers[herd] = cucumbers[herd]!!.map { coord ->
            Coord((coord.x + herd.delta.x) % width, (coord.y + herd.delta.y) % height)
                .let { newCoord -> if (empty(newCoord)) newCoord.also { moved = true } else coord }
        }.toSet()
    }
    steps++
    return moved
}

Compiled from "result.kt"
public final class day25.ResultKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/day25/input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: iconst_0
      18: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      23: checkcast     #28                 // class java/lang/String
      26: invokevirtual #32                 // Method java/lang/String.length:()I
      29: aload_0
      30: invokeinterface #35,  1           // InterfaceMethod java/util/List.size:()I
      35: invokestatic  #41                 // Method day25/Herd.values:()[Lday25/Herd;
      38: astore_2
      39: istore        13
      41: istore        12
      43: iconst_0
      44: istore_3
      45: new           #43                 // class java/util/LinkedHashMap
      48: dup
      49: aload_2
      50: arraylength
      51: invokestatic  #49                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      54: bipush        16
      56: invokestatic  #55                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      59: invokespecial #58                 // Method java/util/LinkedHashMap."<init>":(I)V
      62: astore        4
      64: aload_2
      65: astore        5
      67: iconst_0
      68: istore        6
      70: iconst_0
      71: istore        7
      73: aload         5
      75: arraylength
      76: istore        8
      78: iload         7
      80: iload         8
      82: if_icmpge     136
      85: aload         5
      87: iload         7
      89: aaload
      90: astore        9
      92: aload         4
      94: checkcast     #60                 // class java/util/Map
      97: aload         9
      99: aload         9
     101: astore        10
     103: astore        15
     105: astore        14
     107: iconst_0
     108: istore        11
     110: aload         10
     112: aload_0
     113: invokestatic  #64                 // Method parse:(Lday25/Herd;Ljava/util/List;)Ljava/util/Set;
     116: astore        16
     118: aload         14
     120: aload         15
     122: aload         16
     124: invokeinterface #68,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     129: pop
     130: iinc          7, 1
     133: goto          78
     136: aload         4
     138: checkcast     #60                 // class java/util/Map
     141: nop
     142: astore        14
     144: iload         12
     146: iload         13
     148: aload         14
     150: invokestatic  #72                 // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     153: iconst_0
     154: bipush        8
     156: aconst_null
     157: astore        17
     159: istore        18
     161: istore        19
     163: astore        20
     165: istore        21
     167: istore        22
     169: new           #74                 // class day25/Seafloor
     172: dup
     173: iload         22
     175: iload         21
     177: aload         20
     179: iload         19
     181: iload         18
     183: aload         17
     185: invokespecial #77                 // Method day25/Seafloor."<init>":(IILjava/util/Map;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
     188: astore_1
     189: aload_1
     190: invokestatic  #81                 // Method move:(Lday25/Seafloor;)Z
     193: ifne          189
     196: aload_1
     197: invokevirtual #84                 // Method day25/Seafloor.getSteps:()I
     200: istore_2
     201: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     204: iload_2
     205: invokevirtual #95                 // Method java/io/PrintStream.println:(I)V
     208: return

  public static final java.util.Set<day25.Coord> parse(day25.Herd, java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #118                // String <this>
       3: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #125                // String lines
       9: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: checkcast     #127                // class java/lang/Iterable
      16: astore_2
      17: iconst_0
      18: istore_3
      19: aload_2
      20: astore        4
      22: new           #129                // class java/util/ArrayList
      25: dup
      26: aload_2
      27: bipush        10
      29: invokestatic  #135                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      32: invokespecial #136                // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #138                // class java/util/Collection
      38: astore        5
      40: iconst_0
      41: istore        6
      43: iconst_0
      44: istore        7
      46: aload         4
      48: invokeinterface #142,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        8
      55: aload         8
      57: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          294
      65: aload         8
      67: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: astore        9
      74: aload         5
      76: iload         7
      78: iinc          7, 1
      81: istore        10
      83: iload         10
      85: ifge          91
      88: invokestatic  #155                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      91: iload         10
      93: aload         9
      95: checkcast     #28                 // class java/lang/String
      98: astore        11
     100: istore        12
     102: astore        33
     104: iconst_0
     105: istore        13
     107: aload         11
     109: checkcast     #157                // class java/lang/CharSequence
     112: invokestatic  #163                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
     115: checkcast     #127                // class java/lang/Iterable
     118: astore        14
     120: iconst_0
     121: istore        15
     123: aload         14
     125: astore        16
     127: new           #129                // class java/util/ArrayList
     130: dup
     131: invokespecial #165                // Method java/util/ArrayList."<init>":()V
     134: checkcast     #138                // class java/util/Collection
     137: astore        17
     139: iconst_0
     140: istore        18
     142: aload         16
     144: astore        19
     146: iconst_0
     147: istore        20
     149: iconst_0
     150: istore        21
     152: aload         19
     154: invokeinterface #142,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     159: astore        22
     161: aload         22
     163: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     168: ifeq          274
     171: aload         22
     173: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     178: astore        23
     180: iload         21
     182: iinc          21, 1
     185: istore        24
     187: iload         24
     189: ifge          195
     192: invokestatic  #155                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     195: iload         24
     197: aload         23
     199: astore        25
     201: istore        26
     203: iconst_0
     204: istore        27
     206: iload         26
     208: aload         25
     210: checkcast     #167                // class java/lang/Character
     213: invokevirtual #171                // Method java/lang/Character.charValue:()C
     216: istore        28
     218: istore        29
     220: iconst_0
     221: istore        30
     223: iload         28
     225: aload_0
     226: invokevirtual #174                // Method day25/Herd.getCh:()C
     229: if_icmpne     246
     232: new           #176                // class day25/Coord
     235: dup
     236: iload         29
     238: iload         12
     240: invokespecial #179                // Method day25/Coord."<init>":(II)V
     243: goto          247
     246: aconst_null
     247: dup
     248: ifnull        269
     251: astore        31
     253: iconst_0
     254: istore        32
     256: aload         17
     258: aload         31
     260: invokeinterface #183,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     265: pop
     266: goto          270
     269: pop
     270: nop
     271: goto          161
     274: nop
     275: aload         17
     277: checkcast     #22                 // class java/util/List
     280: nop
     281: nop
     282: aload         33
     284: swap
     285: invokeinterface #183,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     290: pop
     291: goto          55
     294: aload         5
     296: checkcast     #22                 // class java/util/List
     299: nop
     300: checkcast     #127                // class java/lang/Iterable
     303: invokestatic  #187                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     306: checkcast     #127                // class java/lang/Iterable
     309: invokestatic  #191                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     312: areturn

  public static final boolean empty(day25.Seafloor, day25.Coord);
    Code:
       0: aload_0
       1: ldc           #118                // String <this>
       3: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #224                // String coord
       9: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #228                // Method day25/Seafloor.getCucumbers:()Ljava/util/Map;
      16: invokeinterface #231,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      21: checkcast     #127                // class java/lang/Iterable
      24: astore_2
      25: iconst_0
      26: istore_3
      27: aload_2
      28: instanceof    #138                // class java/util/Collection
      31: ifeq          50
      34: aload_2
      35: checkcast     #138                // class java/util/Collection
      38: invokeinterface #234,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      43: ifeq          50
      46: iconst_1
      47: goto          103
      50: aload_2
      51: invokeinterface #142,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        4
      58: aload         4
      60: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          102
      68: aload         4
      70: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        5
      77: aload         5
      79: checkcast     #236                // class java/util/Set
      82: astore        6
      84: iconst_0
      85: istore        7
      87: aload         6
      89: aload_1
      90: invokeinterface #239,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      95: ifeq          58
      98: iconst_0
      99: goto          103
     102: iconst_1
     103: ireturn

  public static final void print(day25.Seafloor);
    Code:
       0: aload_0
       1: ldc           #118                // String <this>
       3: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: invokevirtual #252                // Method day25/Seafloor.getHeight:()I
      12: istore_2
      13: iload_1
      14: iload_2
      15: if_icmpge     234
      18: iconst_0
      19: istore_3
      20: aload_0
      21: invokevirtual #255                // Method day25/Seafloor.getWidth:()I
      24: istore        4
      26: iload_3
      27: iload         4
      29: if_icmpge     222
      32: invokestatic  #41                 // Method day25/Herd.values:()[Lday25/Herd;
      35: astore        6
      37: nop
      38: iconst_0
      39: istore        7
      41: aload         6
      43: astore        8
      45: new           #129                // class java/util/ArrayList
      48: dup
      49: invokespecial #165                // Method java/util/ArrayList."<init>":()V
      52: checkcast     #138                // class java/util/Collection
      55: astore        9
      57: iconst_0
      58: istore        10
      60: aload         8
      62: astore        11
      64: iconst_0
      65: istore        12
      67: iconst_0
      68: istore        13
      70: aload         11
      72: arraylength
      73: istore        14
      75: iload         13
      77: iload         14
      79: if_icmpge     180
      82: aload         11
      84: iload         13
      86: aaload
      87: astore        15
      89: aload         15
      91: astore        16
      93: iconst_0
      94: istore        17
      96: aload         16
      98: astore        18
     100: iconst_0
     101: istore        19
     103: aload_0
     104: invokevirtual #228                // Method day25/Seafloor.getCucumbers:()Ljava/util/Map;
     107: aload         18
     109: invokeinterface #258,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     114: dup
     115: invokestatic  #262                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     118: checkcast     #236                // class java/util/Set
     121: new           #176                // class day25/Coord
     124: dup
     125: iload_3
     126: iload_1
     127: invokespecial #179                // Method day25/Coord."<init>":(II)V
     130: invokeinterface #239,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     135: ifeq          149
     138: aload         18
     140: invokevirtual #174                // Method day25/Herd.getCh:()C
     143: invokestatic  #266                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     146: goto          150
     149: aconst_null
     150: dup
     151: ifnull        172
     154: astore        20
     156: iconst_0
     157: istore        21
     159: aload         9
     161: aload         20
     163: invokeinterface #183,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     168: pop
     169: goto          173
     172: pop
     173: nop
     174: iinc          13, 1
     177: goto          75
     180: nop
     181: aload         9
     183: checkcast     #22                 // class java/util/List
     186: nop
     187: invokestatic  #270                // Method kotlin/collections/CollectionsKt.firstOrNull:(Ljava/util/List;)Ljava/lang/Object;
     190: checkcast     #167                // class java/lang/Character
     193: dup
     194: ifnull        203
     197: invokevirtual #171                // Method java/lang/Character.charValue:()C
     200: goto          206
     203: pop
     204: bipush        46
     206: istore        5
     208: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     211: iload         5
     213: invokevirtual #273                // Method java/io/PrintStream.print:(C)V
     216: iinc          3, 1
     219: goto          26
     222: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     225: invokevirtual #275                // Method java/io/PrintStream.println:()V
     228: iinc          1, 1
     231: goto          13
     234: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     237: invokevirtual #275                // Method java/io/PrintStream.println:()V
     240: return

  public static final boolean move(day25.Seafloor);
    Code:
       0: aload_0
       1: ldc           #118                // String <this>
       3: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: invokestatic  #41                 // Method day25/Herd.values:()[Lday25/Herd;
      11: astore_2
      12: iconst_0
      13: istore_3
      14: iconst_0
      15: istore        4
      17: aload_2
      18: arraylength
      19: istore        5
      21: iload         4
      23: iload         5
      25: if_icmpge     265
      28: aload_2
      29: iload         4
      31: aaload
      32: astore        6
      34: aload         6
      36: astore        7
      38: iconst_0
      39: istore        8
      41: aload_0
      42: invokevirtual #228                // Method day25/Seafloor.getCucumbers:()Ljava/util/Map;
      45: astore        9
      47: aload_0
      48: invokevirtual #228                // Method day25/Seafloor.getCucumbers:()Ljava/util/Map;
      51: aload         7
      53: invokeinterface #258,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      58: dup
      59: invokestatic  #262                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      62: checkcast     #127                // class java/lang/Iterable
      65: astore        10
      67: iconst_0
      68: istore        11
      70: aload         10
      72: astore        12
      74: new           #129                // class java/util/ArrayList
      77: dup
      78: aload         10
      80: bipush        10
      82: invokestatic  #135                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      85: invokespecial #136                // Method java/util/ArrayList."<init>":(I)V
      88: checkcast     #138                // class java/util/Collection
      91: astore        13
      93: iconst_0
      94: istore        14
      96: aload         12
      98: invokeinterface #142,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     103: astore        15
     105: aload         15
     107: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     112: ifeq          231
     115: aload         15
     117: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     122: astore        16
     124: aload         13
     126: aload         16
     128: checkcast     #176                // class day25/Coord
     131: astore        17
     133: astore        18
     135: iconst_0
     136: istore        19
     138: new           #176                // class day25/Coord
     141: dup
     142: aload         17
     144: invokevirtual #292                // Method day25/Coord.getX:()I
     147: aload         7
     149: invokevirtual #296                // Method day25/Herd.getDelta:()Lday25/Coord;
     152: invokevirtual #292                // Method day25/Coord.getX:()I
     155: iadd
     156: aload_0
     157: invokevirtual #255                // Method day25/Seafloor.getWidth:()I
     160: irem
     161: aload         17
     163: invokevirtual #299                // Method day25/Coord.getY:()I
     166: aload         7
     168: invokevirtual #296                // Method day25/Herd.getDelta:()Lday25/Coord;
     171: invokevirtual #299                // Method day25/Coord.getY:()I
     174: iadd
     175: aload_0
     176: invokevirtual #252                // Method day25/Seafloor.getHeight:()I
     179: irem
     180: invokespecial #179                // Method day25/Coord."<init>":(II)V
     183: astore        20
     185: iconst_0
     186: istore        21
     188: aload_0
     189: aload         20
     191: invokestatic  #301                // Method empty:(Lday25/Seafloor;Lday25/Coord;)Z
     194: ifeq          215
     197: aload         20
     199: astore        22
     201: aload         22
     203: astore        23
     205: iconst_0
     206: istore        24
     208: iconst_1
     209: istore_1
     210: aload         22
     212: goto          217
     215: aload         17
     217: nop
     218: nop
     219: aload         18
     221: swap
     222: invokeinterface #183,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     227: pop
     228: goto          105
     231: aload         13
     233: checkcast     #22                 // class java/util/List
     236: nop
     237: checkcast     #127                // class java/lang/Iterable
     240: invokestatic  #191                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     243: astore        10
     245: aload         9
     247: aload         7
     249: aload         10
     251: invokeinterface #68,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     256: pop
     257: nop
     258: nop
     259: iinc          4, 1
     262: goto          21
     265: nop
     266: aload_0
     267: invokevirtual #84                 // Method day25/Seafloor.getSteps:()I
     270: istore_2
     271: aload_0
     272: iload_2
     273: iconst_1
     274: iadd
     275: invokevirtual #304                // Method day25/Seafloor.setSteps:(I)V
     278: iload_1
     279: ireturn

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


package day22

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

data class Line(val min: Int, val max: Int) {
    fun overlap(other: Line): Line? {
        val start = max(min, other.min)
        val end = min(max, other.max)
        return if (start <= end) Line(start, end) else null
    }
}

data class Cuboid(val on: Boolean, val x: Line, val y: Line, val z: Line) {
    fun volume() = (if (on) 1L else -1L) * (1 + x.max - x.min) * (1 + y.max - y.min) * (1 + z.max - z.min)
    fun intersection(other: Cuboid): Cuboid? {
        val overlapX = x.overlap(other.x)
        val overlapY = y.overlap(other.y)
        val overlapZ = z.overlap(other.z)
        if (overlapX != null && overlapY != null && overlapZ != null) {
            return Cuboid(!on, overlapX, overlapY, overlapZ)
        }
        return null
    }
}

fun calculate(cuboids: List<Cuboid>) =
    cuboids.fold(mutableListOf<Cuboid>()) { acc, c ->
        acc.addAll(acc.mapNotNull { existing -> existing.intersection(c) })
        if (c.on) {
            acc.add(c)
        }
        acc
    }.sumOf { it.volume() }

fun main() {
    val cuboids = File("src/day22/input.txt").readLines()
        .map {
            val (on, minX, maxX, minY, maxY, minZ, maxZ) =
                Regex("(on|off) x=(-?[0-9]*)..(-?[0-9]*),y=(-?[0-9]*)..(-?[0-9]*),z=(-?[0-9]*)..(-?[0-9]*)")
                    .matchEntire(it)!!.destructured
            Cuboid(
                on == "on",
                Line(minX.toInt(), maxX.toInt()),
                Line(minY.toInt(), maxY.toInt()),
                Line(minZ.toInt(), maxZ.toInt())
            )
        }

    val cuboidsInRegion = cuboids
        .filter { c ->
            c.x.min >= -50 && c.x.max <= 50
                    && c.y.min >= -50 && c.y.max <= 50
                    && c.z.min >= -50 && c.z.max <= 50
        }

    println(calculate(cuboidsInRegion))
    println(calculate(cuboids))
}

Compiled from "result.kt"
public final class day22.ResultKt {
  public static final long calculate(java.util.List<day22.Cuboid>);
    Code:
       0: aload_0
       1: ldc           #10                 // String cuboids
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_1
      11: new           #20                 // class java/util/ArrayList
      14: dup
      15: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      18: checkcast     #26                 // class java/util/List
      21: astore_2
      22: nop
      23: iconst_0
      24: istore_3
      25: aload_2
      26: astore        4
      28: aload_1
      29: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      34: astore        5
      36: aload         5
      38: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          232
      46: aload         5
      48: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        6
      55: aload         4
      57: aload         6
      59: checkcast     #42                 // class day22/Cuboid
      62: astore        7
      64: astore        8
      66: iconst_0
      67: istore        9
      69: aload         8
      71: aload         8
      73: checkcast     #18                 // class java/lang/Iterable
      76: astore        10
      78: astore        11
      80: iconst_0
      81: istore        12
      83: aload         10
      85: astore        13
      87: new           #20                 // class java/util/ArrayList
      90: dup
      91: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      94: checkcast     #44                 // class java/util/Collection
      97: astore        14
      99: iconst_0
     100: istore        15
     102: aload         13
     104: astore        16
     106: iconst_0
     107: istore        17
     109: aload         16
     111: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        18
     118: aload         18
     120: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          188
     128: aload         18
     130: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: astore        19
     137: aload         19
     139: astore        20
     141: iconst_0
     142: istore        21
     144: aload         20
     146: checkcast     #42                 // class day22/Cuboid
     149: astore        22
     151: iconst_0
     152: istore        23
     154: aload         22
     156: aload         7
     158: invokevirtual #48                 // Method day22/Cuboid.intersection:(Lday22/Cuboid;)Lday22/Cuboid;
     161: dup
     162: ifnull        183
     165: astore        24
     167: iconst_0
     168: istore        25
     170: aload         14
     172: aload         24
     174: invokeinterface #52,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     179: pop
     180: goto          184
     183: pop
     184: nop
     185: goto          118
     188: nop
     189: aload         14
     191: checkcast     #26                 // class java/util/List
     194: nop
     195: aload         11
     197: swap
     198: checkcast     #44                 // class java/util/Collection
     201: invokeinterface #56,  2           // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     206: pop
     207: aload         7
     209: invokevirtual #59                 // Method day22/Cuboid.getOn:()Z
     212: ifeq          225
     215: aload         8
     217: aload         7
     219: invokeinterface #60,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     224: pop
     225: aload         8
     227: astore        4
     229: goto          36
     232: aload         4
     234: checkcast     #18                 // class java/lang/Iterable
     237: astore_1
     238: lconst_0
     239: lstore_2
     240: aload_1
     241: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     246: astore        4
     248: aload         4
     250: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     255: ifeq          296
     258: aload         4
     260: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     265: astore        5
     267: lload_2
     268: aload         5
     270: checkcast     #42                 // class day22/Cuboid
     273: astore        6
     275: lstore        26
     277: iconst_0
     278: istore        7
     280: aload         6
     282: invokevirtual #64                 // Method day22/Cuboid.volume:()J
     285: lstore        28
     287: lload         26
     289: lload         28
     291: ladd
     292: lstore_2
     293: goto          248
     296: lload_2
     297: lreturn

  public static final void main();
    Code:
       0: new           #97                 // class java/io/File
       3: dup
       4: ldc           #99                 // String src/day22/input.txt
       6: invokespecial #102                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #108                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #18                 // class java/lang/Iterable
      18: astore_1
      19: nop
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #20                 // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #114                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #117                // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #44                 // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          341
      63: aload         6
      65: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        7
      72: aload         4
      74: aload         7
      76: checkcast     #119                // class java/lang/String
      79: astore        8
      81: astore        18
      83: iconst_0
      84: istore        9
      86: new           #121                // class kotlin/text/Regex
      89: dup
      90: ldc           #123                // String (on|off) x=(-?[0-9]*)..(-?[0-9]*),y=(-?[0-9]*)..(-?[0-9]*),z=(-?[0-9]*)..(-?[0-9]*)
      92: invokespecial #124                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      95: aload         8
      97: checkcast     #126                // class java/lang/CharSequence
     100: invokevirtual #130                // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
     103: dup
     104: invokestatic  #134                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     107: invokeinterface #140,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     112: astore        10
     114: aload         10
     116: invokevirtual #146                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     119: invokeinterface #150,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     124: iconst_1
     125: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     130: checkcast     #119                // class java/lang/String
     133: astore        11
     135: aload         10
     137: invokevirtual #146                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     140: invokeinterface #150,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     145: iconst_2
     146: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     151: checkcast     #119                // class java/lang/String
     154: astore        12
     156: aload         10
     158: invokevirtual #146                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     161: invokeinterface #150,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     166: iconst_3
     167: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     172: checkcast     #119                // class java/lang/String
     175: astore        13
     177: aload         10
     179: invokevirtual #146                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     182: invokeinterface #150,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     187: iconst_4
     188: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     193: checkcast     #119                // class java/lang/String
     196: astore        14
     198: aload         10
     200: invokevirtual #146                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     203: invokeinterface #150,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     208: iconst_5
     209: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     214: checkcast     #119                // class java/lang/String
     217: astore        15
     219: aload         10
     221: invokevirtual #146                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     224: invokeinterface #150,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     229: bipush        6
     231: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     236: checkcast     #119                // class java/lang/String
     239: astore        16
     241: aload         10
     243: invokevirtual #146                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     246: invokeinterface #150,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     251: bipush        7
     253: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     258: checkcast     #119                // class java/lang/String
     261: astore        17
     263: new           #42                 // class day22/Cuboid
     266: dup
     267: aload         11
     269: ldc           #156                // String on
     271: invokestatic  #160                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     274: new           #162                // class day22/Line
     277: dup
     278: aload         12
     280: invokestatic  #168                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     283: aload         13
     285: invokestatic  #168                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     288: invokespecial #171                // Method day22/Line."<init>":(II)V
     291: new           #162                // class day22/Line
     294: dup
     295: aload         14
     297: invokestatic  #168                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     300: aload         15
     302: invokestatic  #168                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     305: invokespecial #171                // Method day22/Line."<init>":(II)V
     308: new           #162                // class day22/Line
     311: dup
     312: aload         16
     314: invokestatic  #168                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     317: aload         17
     319: invokestatic  #168                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     322: invokespecial #171                // Method day22/Line."<init>":(II)V
     325: invokespecial #174                // Method day22/Cuboid."<init>":(ZLday22/Line;Lday22/Line;Lday22/Line;)V
     328: nop
     329: aload         18
     331: swap
     332: invokeinterface #52,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     337: pop
     338: goto          53
     341: aload         4
     343: checkcast     #26                 // class java/util/List
     346: nop
     347: astore_0
     348: aload_0
     349: checkcast     #18                 // class java/lang/Iterable
     352: astore_2
     353: nop
     354: iconst_0
     355: istore_3
     356: aload_2
     357: astore        4
     359: new           #20                 // class java/util/ArrayList
     362: dup
     363: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
     366: checkcast     #44                 // class java/util/Collection
     369: astore        5
     371: iconst_0
     372: istore        6
     374: aload         4
     376: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     381: astore        7
     383: aload         7
     385: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     390: ifeq          511
     393: aload         7
     395: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     400: astore        8
     402: aload         8
     404: checkcast     #42                 // class day22/Cuboid
     407: astore        9
     409: iconst_0
     410: istore        10
     412: aload         9
     414: invokevirtual #178                // Method day22/Cuboid.getX:()Lday22/Line;
     417: invokevirtual #182                // Method day22/Line.getMin:()I
     420: bipush        -50
     422: if_icmplt     494
     425: aload         9
     427: invokevirtual #178                // Method day22/Cuboid.getX:()Lday22/Line;
     430: invokevirtual #185                // Method day22/Line.getMax:()I
     433: bipush        50
     435: if_icmpgt     494
     438: aload         9
     440: invokevirtual #188                // Method day22/Cuboid.getY:()Lday22/Line;
     443: invokevirtual #182                // Method day22/Line.getMin:()I
     446: bipush        -50
     448: if_icmplt     494
     451: aload         9
     453: invokevirtual #188                // Method day22/Cuboid.getY:()Lday22/Line;
     456: invokevirtual #185                // Method day22/Line.getMax:()I
     459: bipush        50
     461: if_icmpgt     494
     464: aload         9
     466: invokevirtual #191                // Method day22/Cuboid.getZ:()Lday22/Line;
     469: invokevirtual #182                // Method day22/Line.getMin:()I
     472: bipush        -50
     474: if_icmplt     494
     477: aload         9
     479: invokevirtual #191                // Method day22/Cuboid.getZ:()Lday22/Line;
     482: invokevirtual #185                // Method day22/Line.getMax:()I
     485: bipush        50
     487: if_icmpgt     494
     490: iconst_1
     491: goto          495
     494: iconst_0
     495: ifeq          383
     498: aload         5
     500: aload         8
     502: invokeinterface #52,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     507: pop
     508: goto          383
     511: aload         5
     513: checkcast     #26                 // class java/util/List
     516: nop
     517: astore_1
     518: aload_1
     519: invokestatic  #193                // Method calculate:(Ljava/util/List;)J
     522: lstore_2
     523: getstatic     #199                // Field java/lang/System.out:Ljava/io/PrintStream;
     526: lload_2
     527: invokevirtual #205                // Method java/io/PrintStream.println:(J)V
     530: aload_0
     531: invokestatic  #193                // Method calculate:(Ljava/util/List;)J
     534: lstore_2
     535: getstatic     #199                // Field java/lang/System.out:Ljava/io/PrintStream;
     538: lload_2
     539: invokevirtual #205                // Method java/io/PrintStream.println:(J)V
     542: return

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


package day9

import java.io.File

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

fun Map<Coord, Int>.neighbours(coord: Coord) =
    listOf(Pair(-1, 0), Pair(0, -1), Pair(1, 0), Pair(0, 1))
        .map { Coord(coord.x + it.first, coord.y + it.second) }
        .filter { contains(it) }
        .toSet()

fun Map<Coord, Int>.isLowest(coord: Coord) =
    neighbours(coord).map { this[coord]!! < this[it]!! }.all { it }

fun Map<Coord, Int>.basin(coord: Coord, visited: Set<Coord>): Set<Coord> {
    if (visited.contains(coord)) {
        return visited
    }
    return neighbours(coord)
        .filter { this[it] != 9 && this[coord]!! < this[it]!! }
        .fold(visited + coord) { acc, neighbour -> acc + basin(neighbour, acc) }
}

fun main() {
    val grid = File("src/day9/input.txt").readLines()
        .mapIndexed { i, row -> row.toList().mapIndexed { j, ch -> Coord(i, j) to Character.getNumericValue(ch) } }
        .flatten()
        .toMap()

    val lowest = grid.filter { (coord, _) -> grid.isLowest(coord) }
    println(lowest.values.sumOf { it + 1 })
    println(lowest.keys
        .map { grid.basin(it, emptySet()).size }
        .sortedDescending()
        .take(3)
        .reduce(Int::times))
}

Compiled from "result.kt"
public final class day9.ResultKt {
  public static final java.util.Set<day9.Coord> neighbours(java.util.Map<day9.Coord, java.lang.Integer>, day9.Coord);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String coord
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_4
      13: anewarray     #20                 // class kotlin/Pair
      16: astore_2
      17: aload_2
      18: iconst_0
      19: new           #20                 // class kotlin/Pair
      22: dup
      23: iconst_m1
      24: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      27: iconst_0
      28: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      31: invokespecial #30                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      34: aastore
      35: aload_2
      36: iconst_1
      37: new           #20                 // class kotlin/Pair
      40: dup
      41: iconst_0
      42: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      45: iconst_m1
      46: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: invokespecial #30                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      52: aastore
      53: aload_2
      54: iconst_2
      55: new           #20                 // class kotlin/Pair
      58: dup
      59: iconst_1
      60: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      63: iconst_0
      64: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: invokespecial #30                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      70: aastore
      71: aload_2
      72: iconst_3
      73: new           #20                 // class kotlin/Pair
      76: dup
      77: iconst_0
      78: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      81: iconst_1
      82: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      85: invokespecial #30                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      88: aastore
      89: aload_2
      90: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      93: checkcast     #38                 // class java/lang/Iterable
      96: astore_2
      97: nop
      98: iconst_0
      99: istore_3
     100: aload_2
     101: astore        4
     103: new           #40                 // class java/util/ArrayList
     106: dup
     107: aload_2
     108: bipush        10
     110: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     113: invokespecial #47                 // Method java/util/ArrayList."<init>":(I)V
     116: checkcast     #49                 // class java/util/Collection
     119: astore        5
     121: iconst_0
     122: istore        6
     124: aload         4
     126: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     131: astore        7
     133: aload         7
     135: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     140: ifeq          217
     143: aload         7
     145: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     150: astore        8
     152: aload         5
     154: aload         8
     156: checkcast     #20                 // class kotlin/Pair
     159: astore        9
     161: astore        11
     163: iconst_0
     164: istore        10
     166: new           #65                 // class day9/Coord
     169: dup
     170: aload_1
     171: invokevirtual #69                 // Method day9/Coord.getX:()I
     174: aload         9
     176: invokevirtual #72                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     179: checkcast     #74                 // class java/lang/Number
     182: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     185: iadd
     186: aload_1
     187: invokevirtual #80                 // Method day9/Coord.getY:()I
     190: aload         9
     192: invokevirtual #83                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     195: checkcast     #74                 // class java/lang/Number
     198: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     201: iadd
     202: invokespecial #86                 // Method day9/Coord."<init>":(II)V
     205: aload         11
     207: swap
     208: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     213: pop
     214: goto          133
     217: aload         5
     219: checkcast     #92                 // class java/util/List
     222: nop
     223: checkcast     #38                 // class java/lang/Iterable
     226: astore_2
     227: nop
     228: iconst_0
     229: istore_3
     230: aload_2
     231: astore        4
     233: new           #40                 // class java/util/ArrayList
     236: dup
     237: invokespecial #95                 // Method java/util/ArrayList."<init>":()V
     240: checkcast     #49                 // class java/util/Collection
     243: astore        5
     245: iconst_0
     246: istore        6
     248: aload         4
     250: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     255: astore        7
     257: aload         7
     259: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     264: ifeq          311
     267: aload         7
     269: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     274: astore        8
     276: aload         8
     278: checkcast     #65                 // class day9/Coord
     281: astore        9
     283: iconst_0
     284: istore        10
     286: aload_0
     287: aload         9
     289: invokeinterface #100,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     294: nop
     295: ifeq          257
     298: aload         5
     300: aload         8
     302: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     307: pop
     308: goto          257
     311: aload         5
     313: checkcast     #92                 // class java/util/List
     316: nop
     317: checkcast     #38                 // class java/lang/Iterable
     320: invokestatic  #104                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     323: areturn

  public static final boolean isLowest(java.util.Map<day9.Coord, java.lang.Integer>, day9.Coord);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String coord
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokestatic  #131                // Method neighbours:(Ljava/util/Map;Lday9/Coord;)Ljava/util/Set;
      17: checkcast     #38                 // class java/lang/Iterable
      20: astore_2
      21: iconst_0
      22: istore_3
      23: aload_2
      24: astore        4
      26: new           #40                 // class java/util/ArrayList
      29: dup
      30: aload_2
      31: bipush        10
      33: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      36: invokespecial #47                 // Method java/util/ArrayList."<init>":(I)V
      39: checkcast     #49                 // class java/util/Collection
      42: astore        5
      44: iconst_0
      45: istore        6
      47: aload         4
      49: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      54: astore        7
      56: aload         7
      58: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      63: ifeq          147
      66: aload         7
      68: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      73: astore        8
      75: aload         5
      77: aload         8
      79: checkcast     #65                 // class day9/Coord
      82: astore        9
      84: astore        11
      86: iconst_0
      87: istore        10
      89: aload_0
      90: aload_1
      91: invokeinterface #135,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      96: dup
      97: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     100: checkcast     #74                 // class java/lang/Number
     103: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     106: aload_0
     107: aload         9
     109: invokeinterface #135,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     114: dup
     115: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     118: checkcast     #74                 // class java/lang/Number
     121: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     124: if_icmpge     131
     127: iconst_1
     128: goto          132
     131: iconst_0
     132: invokestatic  #144                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     135: aload         11
     137: swap
     138: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     143: pop
     144: goto          56
     147: aload         5
     149: checkcast     #92                 // class java/util/List
     152: nop
     153: checkcast     #38                 // class java/lang/Iterable
     156: astore_2
     157: nop
     158: iconst_0
     159: istore_3
     160: aload_2
     161: instanceof    #49                 // class java/util/Collection
     164: ifeq          183
     167: aload_2
     168: checkcast     #49                 // class java/util/Collection
     171: invokeinterface #147,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     176: ifeq          183
     179: iconst_1
     180: goto          233
     183: aload_2
     184: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     189: astore        4
     191: aload         4
     193: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     198: ifeq          232
     201: aload         4
     203: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     208: astore        5
     210: aload         5
     212: checkcast     #141                // class java/lang/Boolean
     215: invokevirtual #150                // Method java/lang/Boolean.booleanValue:()Z
     218: istore        6
     220: iconst_0
     221: istore        7
     223: iload         6
     225: ifne          191
     228: iconst_0
     229: goto          233
     232: iconst_1
     233: ireturn

  public static final java.util.Set<day9.Coord> basin(java.util.Map<day9.Coord, java.lang.Integer>, day9.Coord, java.util.Set<day9.Coord>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String coord
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_2
      13: ldc           #162                // String visited
      15: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload_2
      19: aload_1
      20: invokeinterface #167,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      25: ifeq          30
      28: aload_2
      29: areturn
      30: aload_0
      31: aload_1
      32: invokestatic  #131                // Method neighbours:(Ljava/util/Map;Lday9/Coord;)Ljava/util/Set;
      35: checkcast     #38                 // class java/lang/Iterable
      38: astore_3
      39: nop
      40: iconst_0
      41: istore        4
      43: aload_3
      44: astore        5
      46: new           #40                 // class java/util/ArrayList
      49: dup
      50: invokespecial #95                 // Method java/util/ArrayList."<init>":()V
      53: checkcast     #49                 // class java/util/Collection
      56: astore        6
      58: iconst_0
      59: istore        7
      61: aload         5
      63: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      68: astore        8
      70: aload         8
      72: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      77: ifeq          189
      80: aload         8
      82: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      87: astore        9
      89: aload         9
      91: checkcast     #65                 // class day9/Coord
      94: astore        10
      96: iconst_0
      97: istore        11
      99: aload_0
     100: aload         10
     102: invokeinterface #135,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     107: checkcast     #22                 // class java/lang/Integer
     110: bipush        9
     112: istore        12
     114: dup
     115: ifnonnull     122
     118: pop
     119: goto          130
     122: invokevirtual #168                // Method java/lang/Integer.intValue:()I
     125: iload         12
     127: if_icmpeq     172
     130: aload_0
     131: aload_1
     132: invokeinterface #135,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     137: dup
     138: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     141: checkcast     #74                 // class java/lang/Number
     144: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     147: aload_0
     148: aload         10
     150: invokeinterface #135,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     155: dup
     156: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     159: checkcast     #74                 // class java/lang/Number
     162: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     165: if_icmpge     172
     168: iconst_1
     169: goto          173
     172: iconst_0
     173: ifeq          70
     176: aload         6
     178: aload         9
     180: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     185: pop
     186: goto          70
     189: aload         6
     191: checkcast     #92                 // class java/util/List
     194: nop
     195: checkcast     #38                 // class java/lang/Iterable
     198: astore_3
     199: aload_2
     200: aload_1
     201: invokestatic  #174                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Object;)Ljava/util/Set;
     204: astore        4
     206: iconst_0
     207: istore        5
     209: aload         4
     211: astore        6
     213: aload_3
     214: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     219: astore        7
     221: aload         7
     223: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     228: ifeq          275
     231: aload         7
     233: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     238: astore        8
     240: aload         6
     242: aload         8
     244: checkcast     #65                 // class day9/Coord
     247: astore        9
     249: astore        10
     251: iconst_0
     252: istore        11
     254: aload         10
     256: aload_0
     257: aload         9
     259: aload         10
     261: invokestatic  #176                // Method basin:(Ljava/util/Map;Lday9/Coord;Ljava/util/Set;)Ljava/util/Set;
     264: checkcast     #38                 // class java/lang/Iterable
     267: invokestatic  #179                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     270: astore        6
     272: goto          221
     275: aload         6
     277: areturn

  public static final void main();
    Code:
       0: new           #192                // class java/io/File
       3: dup
       4: ldc           #194                // String src/day9/input.txt
       6: invokespecial #197                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #203                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #38                 // class java/lang/Iterable
      18: astore_1
      19: nop
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #40                 // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #47                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #49                 // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: iconst_0
      46: istore        6
      48: aload_3
      49: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      54: astore        7
      56: aload         7
      58: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      63: ifeq          270
      66: aload         7
      68: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      73: astore        8
      75: aload         4
      77: iload         6
      79: iinc          6, 1
      82: istore        9
      84: iload         9
      86: ifge          92
      89: invokestatic  #206                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      92: iload         9
      94: aload         8
      96: checkcast     #208                // class java/lang/String
      99: astore        10
     101: istore        11
     103: astore        26
     105: iconst_0
     106: istore        12
     108: aload         10
     110: checkcast     #210                // class java/lang/CharSequence
     113: invokestatic  #216                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
     116: checkcast     #38                 // class java/lang/Iterable
     119: astore        13
     121: iconst_0
     122: istore        14
     124: aload         13
     126: astore        15
     128: new           #40                 // class java/util/ArrayList
     131: dup
     132: aload         13
     134: bipush        10
     136: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     139: invokespecial #47                 // Method java/util/ArrayList."<init>":(I)V
     142: checkcast     #49                 // class java/util/Collection
     145: astore        16
     147: iconst_0
     148: istore        17
     150: iconst_0
     151: istore        18
     153: aload         15
     155: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     160: astore        19
     162: aload         19
     164: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     169: ifeq          251
     172: aload         19
     174: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     179: astore        20
     181: aload         16
     183: iload         18
     185: iinc          18, 1
     188: istore        21
     190: iload         21
     192: ifge          198
     195: invokestatic  #206                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     198: iload         21
     200: aload         20
     202: checkcast     #218                // class java/lang/Character
     205: invokevirtual #222                // Method java/lang/Character.charValue:()C
     208: istore        22
     210: istore        23
     212: astore        24
     214: iconst_0
     215: istore        25
     217: new           #65                 // class day9/Coord
     220: dup
     221: iload         11
     223: iload         23
     225: invokespecial #86                 // Method day9/Coord."<init>":(II)V
     228: iload         22
     230: invokestatic  #226                // Method java/lang/Character.getNumericValue:(C)I
     233: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     236: invokestatic  #232                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     239: aload         24
     241: swap
     242: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     247: pop
     248: goto          162
     251: aload         16
     253: checkcast     #92                 // class java/util/List
     256: nop
     257: nop
     258: aload         26
     260: swap
     261: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     266: pop
     267: goto          56
     270: aload         4
     272: checkcast     #92                 // class java/util/List
     275: nop
     276: checkcast     #38                 // class java/lang/Iterable
     279: invokestatic  #236                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     282: checkcast     #38                 // class java/lang/Iterable
     285: invokestatic  #242                // Method kotlin/collections/MapsKt.toMap:(Ljava/lang/Iterable;)Ljava/util/Map;
     288: astore_0
     289: aload_0
     290: astore_2
     291: iconst_0
     292: istore_3
     293: aload_2
     294: astore        4
     296: new           #244                // class java/util/LinkedHashMap
     299: dup
     300: invokespecial #245                // Method java/util/LinkedHashMap."<init>":()V
     303: checkcast     #97                 // class java/util/Map
     306: astore        5
     308: iconst_0
     309: istore        6
     311: aload         4
     313: invokeinterface #249,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     318: invokeinterface #250,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     323: astore        7
     325: aload         7
     327: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     332: ifeq          400
     335: aload         7
     337: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     342: checkcast     #252                // class java/util/Map$Entry
     345: astore        8
     347: aload         8
     349: astore        9
     351: iconst_0
     352: istore        10
     354: aload         9
     356: invokeinterface #255,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     361: checkcast     #65                 // class day9/Coord
     364: astore        11
     366: aload_0
     367: aload         11
     369: invokestatic  #257                // Method isLowest:(Ljava/util/Map;Lday9/Coord;)Z
     372: ifeq          325
     375: aload         5
     377: aload         8
     379: invokeinterface #255,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     384: aload         8
     386: invokeinterface #260,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     391: invokeinterface #264,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     396: pop
     397: goto          325
     400: aload         5
     402: nop
     403: astore_1
     404: aload_1
     405: invokeinterface #268,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     410: checkcast     #38                 // class java/lang/Iterable
     413: astore_2
     414: iconst_0
     415: istore_3
     416: aload_2
     417: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     422: astore        4
     424: aload         4
     426: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     431: ifeq          474
     434: aload         4
     436: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     441: astore        5
     443: iload_3
     444: aload         5
     446: checkcast     #74                 // class java/lang/Number
     449: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     452: istore        6
     454: istore        26
     456: iconst_0
     457: istore        7
     459: iload         6
     461: iconst_1
     462: iadd
     463: istore        27
     465: iload         26
     467: iload         27
     469: iadd
     470: istore_3
     471: goto          424
     474: iload_3
     475: istore_2
     476: getstatic     #274                // Field java/lang/System.out:Ljava/io/PrintStream;
     479: iload_2
     480: invokevirtual #279                // Method java/io/PrintStream.println:(I)V
     483: aload_1
     484: invokeinterface #282,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     489: checkcast     #38                 // class java/lang/Iterable
     492: astore_2
     493: nop
     494: iconst_0
     495: istore_3
     496: aload_2
     497: astore        4
     499: new           #40                 // class java/util/ArrayList
     502: dup
     503: aload_2
     504: bipush        10
     506: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     509: invokespecial #47                 // Method java/util/ArrayList."<init>":(I)V
     512: checkcast     #49                 // class java/util/Collection
     515: astore        5
     517: iconst_0
     518: istore        6
     520: aload         4
     522: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     527: astore        7
     529: aload         7
     531: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     536: ifeq          591
     539: aload         7
     541: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     546: astore        8
     548: aload         5
     550: aload         8
     552: checkcast     #65                 // class day9/Coord
     555: astore        9
     557: astore        26
     559: iconst_0
     560: istore        10
     562: aload_0
     563: aload         9
     565: invokestatic  #285                // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
     568: invokestatic  #176                // Method basin:(Ljava/util/Map;Lday9/Coord;Ljava/util/Set;)Ljava/util/Set;
     571: invokeinterface #288,  1          // InterfaceMethod java/util/Set.size:()I
     576: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     579: aload         26
     581: swap
     582: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     587: pop
     588: goto          529
     591: aload         5
     593: checkcast     #92                 // class java/util/List
     596: nop
     597: checkcast     #38                 // class java/lang/Iterable
     600: invokestatic  #291                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     603: checkcast     #38                 // class java/lang/Iterable
     606: iconst_3
     607: invokestatic  #295                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     610: checkcast     #38                 // class java/lang/Iterable
     613: astore_2
     614: nop
     615: iconst_0
     616: istore_3
     617: aload_2
     618: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     623: astore        4
     625: aload         4
     627: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     632: ifne          646
     635: new           #297                // class java/lang/UnsupportedOperationException
     638: dup
     639: ldc_w         #299                // String Empty collection can\'t be reduced.
     642: invokespecial #300                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     645: athrow
     646: aload         4
     648: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     653: astore        5
     655: aload         4
     657: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     662: ifeq          706
     665: aload         5
     667: aload         4
     669: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     674: checkcast     #74                 // class java/lang/Number
     677: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     680: istore        6
     682: checkcast     #74                 // class java/lang/Number
     685: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     688: istore        7
     690: iconst_0
     691: istore        8
     693: iload         7
     695: iload         6
     697: imul
     698: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     701: astore        5
     703: goto          655
     706: aload         5
     708: checkcast     #74                 // class java/lang/Number
     711: invokevirtual #77                 // Method java/lang/Number.intValue:()I
     714: istore_2
     715: getstatic     #274                // Field java/lang/System.out:Ljava/io/PrintStream;
     718: iload_2
     719: invokevirtual #279                // Method java/io/PrintStream.println:(I)V
     722: return

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


package day8

import java.io.File

data class Line(val input:Set<Set<Char>>, val output: List<Set<Char>>) {
    private val from: Map<Set<Char>, Int>
    init {
        val to = mutableMapOf(
            1 to input.find { it.size == 2 }!!,
            4 to input.find { it.size == 4 }!!,
            7 to input.find { it.size == 3 }!!,
            8 to input.find { it.size == 7 }!!
        )
        to[6] = (input - to.values).find { it.size == 6 && (it - to[1]!!).size == 5 }!!
        to[3] = (input - to.values).find { it.size == 5 && (to[8]!! - it - to[1]!!).size == 2}!!
        to[5] = (input - to.values).find { it.size == 5 && (it - to[4]!!).size == 2}!!
        to[9] = (input - to.values).find { (it - to[4]!!).size == 2 }!!
        to[2] = (input - to.values).find { it.size == 5 }!!
        to[0] = (input - to.values).single()

        from = to.entries.associate { (k, v) -> v to k }
    }
    fun partOne() = output.map { segments -> if (setOf(1, 4, 7, 8).contains(from[segments])) 1 else 0 }.sum()
    fun partTwo() = output.fold(0) { acc, segments -> acc * 10 + from[segments]!! }
}

fun String.toSegments() = split(" ").map { it.toCharArray().toSet() }

fun main() {
    val lines = File("src/day8/input.txt").readLines()
        .map { it.split(" | ") }
        .map { line -> Line(line[0].toSegments().toSet(), line[1].toSegments())}

    println(lines.sumOf { it.partOne() })
    println(lines.sumOf { it.partTwo() })
}

Compiled from "result.kt"
public final class day8.ResultKt {
  public static final java.util.List<java.util.Set<java.lang.Character>> toSegments(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #20                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #22                 // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #28                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #30                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #32                 // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #38                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #42                 // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #44                 // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: aload_3
      59: invokeinterface #48,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        6
      66: aload         6
      68: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          125
      76: aload         6
      78: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        7
      85: aload         4
      87: aload         7
      89: checkcast     #20                 // class java/lang/String
      92: astore        8
      94: astore        10
      96: iconst_0
      97: istore        9
      99: aload         8
     101: invokevirtual #62                 // Method java/lang/String.toCharArray:()[C
     104: dup
     105: ldc           #64                 // String toCharArray(...)
     107: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     110: invokestatic  #73                 // Method kotlin/collections/ArraysKt.toSet:([C)Ljava/util/Set;
     113: aload         10
     115: swap
     116: invokeinterface #77,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          66
     125: aload         4
     127: checkcast     #79                 // class java/util/List
     130: nop
     131: areturn

  public static final void main();
    Code:
       0: new           #97                 // class java/io/File
       3: dup
       4: ldc           #99                 // String src/day8/input.txt
       6: invokespecial #102                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #108                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #30                 // class java/lang/Iterable
      18: astore_1
      19: nop
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #32                 // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #38                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #42                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #44                 // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #48,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          125
      63: aload         6
      65: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        7
      72: aload         4
      74: aload         7
      76: checkcast     #20                 // class java/lang/String
      79: astore        8
      81: astore        11
      83: iconst_0
      84: istore        9
      86: aload         8
      88: checkcast     #18                 // class java/lang/CharSequence
      91: iconst_1
      92: anewarray     #20                 // class java/lang/String
      95: astore        10
      97: aload         10
      99: iconst_0
     100: ldc           #110                // String  |
     102: aastore
     103: aload         10
     105: iconst_0
     106: iconst_0
     107: bipush        6
     109: aconst_null
     110: invokestatic  #28                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     113: aload         11
     115: swap
     116: invokeinterface #77,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          53
     125: aload         4
     127: checkcast     #79                 // class java/util/List
     130: nop
     131: checkcast     #30                 // class java/lang/Iterable
     134: astore_1
     135: nop
     136: iconst_0
     137: istore_2
     138: aload_1
     139: astore_3
     140: new           #32                 // class java/util/ArrayList
     143: dup
     144: aload_1
     145: bipush        10
     147: invokestatic  #38                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     150: invokespecial #42                 // Method java/util/ArrayList."<init>":(I)V
     153: checkcast     #44                 // class java/util/Collection
     156: astore        4
     158: iconst_0
     159: istore        5
     161: aload_3
     162: invokeinterface #48,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     167: astore        6
     169: aload         6
     171: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     176: ifeq          255
     179: aload         6
     181: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     186: astore        7
     188: aload         4
     190: aload         7
     192: checkcast     #79                 // class java/util/List
     195: astore        8
     197: astore        11
     199: iconst_0
     200: istore        9
     202: new           #112                // class day8/Line
     205: dup
     206: aload         8
     208: iconst_0
     209: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     214: checkcast     #20                 // class java/lang/String
     217: invokestatic  #118                // Method toSegments:(Ljava/lang/String;)Ljava/util/List;
     220: checkcast     #30                 // class java/lang/Iterable
     223: invokestatic  #121                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     226: aload         8
     228: iconst_1
     229: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     234: checkcast     #20                 // class java/lang/String
     237: invokestatic  #118                // Method toSegments:(Ljava/lang/String;)Ljava/util/List;
     240: invokespecial #124                // Method day8/Line."<init>":(Ljava/util/Set;Ljava/util/List;)V
     243: aload         11
     245: swap
     246: invokeinterface #77,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     251: pop
     252: goto          169
     255: aload         4
     257: checkcast     #79                 // class java/util/List
     260: nop
     261: astore_0
     262: aload_0
     263: checkcast     #30                 // class java/lang/Iterable
     266: astore_1
     267: iconst_0
     268: istore_2
     269: aload_1
     270: invokeinterface #48,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     275: astore_3
     276: aload_3
     277: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     282: ifeq          322
     285: aload_3
     286: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     291: astore        4
     293: iload_2
     294: aload         4
     296: checkcast     #112                // class day8/Line
     299: astore        5
     301: istore        11
     303: iconst_0
     304: istore        6
     306: aload         5
     308: invokevirtual #128                // Method day8/Line.partOne:()I
     311: istore        12
     313: iload         11
     315: iload         12
     317: iadd
     318: istore_2
     319: goto          276
     322: iload_2
     323: istore_1
     324: getstatic     #134                // Field java/lang/System.out:Ljava/io/PrintStream;
     327: iload_1
     328: invokevirtual #139                // Method java/io/PrintStream.println:(I)V
     331: aload_0
     332: checkcast     #30                 // class java/lang/Iterable
     335: astore_1
     336: iconst_0
     337: istore_2
     338: aload_1
     339: invokeinterface #48,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     344: astore_3
     345: aload_3
     346: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     351: ifeq          391
     354: aload_3
     355: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     360: astore        4
     362: iload_2
     363: aload         4
     365: checkcast     #112                // class day8/Line
     368: astore        5
     370: istore        11
     372: iconst_0
     373: istore        6
     375: aload         5
     377: invokevirtual #142                // Method day8/Line.partTwo:()I
     380: istore        12
     382: iload         11
     384: iload         12
     386: iadd
     387: istore_2
     388: goto          345
     391: iload_2
     392: istore_1
     393: getstatic     #134                // Field java/lang/System.out:Ljava/io/PrintStream;
     396: iload_1
     397: invokevirtual #139                // Method java/io/PrintStream.println:(I)V
     400: return

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