package day20

import java.io.File

fun main() {
    val lines = File("src/main/kotlin/day20/input.txt").readLines()
    val imageEnhancementAlgorithm: BooleanArray = lines[0].map { it == '#' }.toBooleanArray()
    val imageYSize = lines.size + 2
    val imageXSize = lines[2].length + 4
    val image = InfiniteImage(
        Array(imageYSize) { i ->
            if (i in (0..1) || i in (imageYSize - 2 until imageYSize)) {
                BooleanArray(imageXSize)
            } else {
                (".." + lines[i] + "..").map { it == '#' }.toBooleanArray()
            }
        },
        false
    )
    val enhancedImage = (0..1).fold(image) { acc, _ ->
        enhanceImage(acc, imageEnhancementAlgorithm)
    }
    println(enhancedImage.innerData.sumOf { imageLine -> imageLine.count { it } })

    val enhancedImage2 = (0..49).fold(image) { acc, _ ->
        enhanceImage(acc, imageEnhancementAlgorithm)
    }
    println(enhancedImage2.innerData.sumOf { imageLine -> imageLine.count { it } })
}

fun enhanceImage(image: InfiniteImage, imageEnhancementAlgorithm: BooleanArray): InfiniteImage {
    val imageYResolution = image.innerData.size + 2
    val imageXResolution = image.innerData[0].size + 2
    val newOuterPixelValue = image.outerPixelValue.not()
    val newInnerData = Array(imageYResolution) { y ->
        if (y in (0..1) || y in (imageYResolution - 2 until imageYResolution)) {
            BooleanArray(imageXResolution) { newOuterPixelValue }
        } else {
            BooleanArray(imageXResolution) { x ->
                if (x in (0..1) || x in (imageXResolution - 2 until imageXResolution)) {
                    newOuterPixelValue
                } else {
                    val pixelValueArray = BooleanArray(9)
                    pixelValueArray[0] = image.innerData[y - 2][x - 2]
                    pixelValueArray[1] = image.innerData[y - 2][x - 1]
                    pixelValueArray[2] = image.innerData[y - 2][x]
                    pixelValueArray[3] = image.innerData[y - 1][x - 2]
                    pixelValueArray[4] = image.innerData[y - 1][x - 1]
                    pixelValueArray[5] = image.innerData[y - 1][x]
                    pixelValueArray[6] = image.innerData[y][x - 2]
                    pixelValueArray[7] = image.innerData[y][x - 1]
                    pixelValueArray[8] = image.innerData[y][x]
                    imageEnhancementAlgorithm[pixelValueArray.toInt()]
                }
            }
        }
    }
    return InfiniteImage(
        newInnerData,
        newOuterPixelValue
    )
}

fun BooleanArray.toInt(): Int = this.map { if (it) 1 else 0 }.joinToString("").toInt(2)

data class InfiniteImage(val innerData: Array<BooleanArray>, val outerPixelValue: Boolean)

Compiled from "solution.kt"
public final class day20.SolutionKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/main/kotlin/day20/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/CharSequence
      26: astore_2
      27: iconst_0
      28: istore_3
      29: aload_2
      30: astore        4
      32: new           #30                 // class java/util/ArrayList
      35: dup
      36: aload_2
      37: invokeinterface #34,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      42: invokespecial #37                 // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #39                 // class java/util/Collection
      48: astore        5
      50: iconst_0
      51: istore        6
      53: iconst_0
      54: istore        7
      56: iload         7
      58: aload         4
      60: invokeinterface #34,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      65: if_icmpge     120
      68: aload         4
      70: iload         7
      72: invokeinterface #43,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      77: istore        8
      79: aload         5
      81: iload         8
      83: istore        9
      85: astore        22
      87: iconst_0
      88: istore        10
      90: iload         9
      92: bipush        35
      94: if_icmpne     101
      97: iconst_1
      98: goto          102
     101: iconst_0
     102: invokestatic  #49                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     105: aload         22
     107: swap
     108: invokeinterface #53,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     113: pop
     114: iinc          7, 1
     117: goto          56
     120: aload         5
     122: checkcast     #22                 // class java/util/List
     125: nop
     126: checkcast     #39                 // class java/util/Collection
     129: invokestatic  #59                 // Method kotlin/collections/CollectionsKt.toBooleanArray:(Ljava/util/Collection;)[Z
     132: astore_1
     133: aload_0
     134: invokeinterface #62,  1           // InterfaceMethod java/util/List.size:()I
     139: iconst_2
     140: iadd
     141: istore_2
     142: aload_0
     143: iconst_2
     144: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     149: checkcast     #64                 // class java/lang/String
     152: invokevirtual #65                 // Method java/lang/String.length:()I
     155: iconst_4
     156: iadd
     157: istore_3
     158: iconst_0
     159: istore        5
     161: iload_2
     162: anewarray     #67                 // class "[Z"
     165: astore        6
     167: iload         5
     169: iload_2
     170: if_icmpge     403
     173: iload         5
     175: istore        7
     177: aload         6
     179: iload         7
     181: iconst_0
     182: iload         7
     184: if_icmpgt     201
     187: iload         7
     189: iconst_2
     190: if_icmpge     197
     193: iconst_1
     194: goto          202
     197: iconst_0
     198: goto          202
     201: iconst_0
     202: ifne          231
     205: iload_2
     206: iconst_2
     207: isub
     208: iload         7
     210: if_icmpgt     227
     213: iload         7
     215: iload_2
     216: if_icmpge     223
     219: iconst_1
     220: goto          228
     223: iconst_0
     224: goto          228
     227: iconst_0
     228: ifeq          237
     231: iload_3
     232: newarray       boolean
     234: goto          396
     237: new           #69                 // class java/lang/StringBuilder
     240: dup
     241: invokespecial #71                 // Method java/lang/StringBuilder."<init>":()V
     244: ldc           #73                 // String ..
     246: invokevirtual #77                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     249: aload_0
     250: iload         7
     252: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     257: checkcast     #64                 // class java/lang/String
     260: invokevirtual #77                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     263: ldc           #73                 // String ..
     265: invokevirtual #77                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     268: invokevirtual #81                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     271: checkcast     #28                 // class java/lang/CharSequence
     274: astore        8
     276: istore        25
     278: astore        24
     280: iconst_0
     281: istore        9
     283: aload         8
     285: astore        10
     287: new           #30                 // class java/util/ArrayList
     290: dup
     291: aload         8
     293: invokeinterface #34,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     298: invokespecial #37                 // Method java/util/ArrayList."<init>":(I)V
     301: checkcast     #39                 // class java/util/Collection
     304: astore        11
     306: iconst_0
     307: istore        12
     309: iconst_0
     310: istore        13
     312: iload         13
     314: aload         10
     316: invokeinterface #34,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     321: if_icmpge     376
     324: aload         10
     326: iload         13
     328: invokeinterface #43,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     333: istore        14
     335: aload         11
     337: iload         14
     339: istore        15
     341: astore        26
     343: iconst_0
     344: istore        16
     346: iload         15
     348: bipush        35
     350: if_icmpne     357
     353: iconst_1
     354: goto          358
     357: iconst_0
     358: invokestatic  #49                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     361: aload         26
     363: swap
     364: invokeinterface #53,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     369: pop
     370: iinc          13, 1
     373: goto          312
     376: aload         11
     378: checkcast     #22                 // class java/util/List
     381: nop
     382: astore        26
     384: aload         24
     386: iload         25
     388: aload         26
     390: checkcast     #39                 // class java/util/Collection
     393: invokestatic  #59                 // Method kotlin/collections/CollectionsKt.toBooleanArray:(Ljava/util/Collection;)[Z
     396: aastore
     397: iinc          5, 1
     400: goto          167
     403: aload         6
     405: iconst_0
     406: istore        27
     408: astore        28
     410: new           #83                 // class day20/InfiniteImage
     413: dup
     414: aload         28
     416: iload         27
     418: invokespecial #86                 // Method day20/InfiniteImage."<init>":([[ZZ)V
     421: astore        4
     423: new           #88                 // class kotlin/ranges/IntRange
     426: dup
     427: iconst_0
     428: iconst_1
     429: invokespecial #91                 // Method kotlin/ranges/IntRange."<init>":(II)V
     432: checkcast     #93                 // class java/lang/Iterable
     435: astore        6
     437: iconst_0
     438: istore        7
     440: aload         4
     442: astore        8
     444: aload         6
     446: invokeinterface #97,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     451: astore        9
     453: aload         9
     455: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     460: ifeq          491
     463: aload         9
     465: checkcast     #105                // class kotlin/collections/IntIterator
     468: invokevirtual #108                // Method kotlin/collections/IntIterator.nextInt:()I
     471: istore        10
     473: aload         8
     475: astore        12
     477: iconst_0
     478: istore        13
     480: aload         12
     482: aload_1
     483: invokestatic  #112                // Method enhanceImage:(Lday20/InfiniteImage;[Z)Lday20/InfiniteImage;
     486: astore        8
     488: goto          453
     491: aload         8
     493: astore        5
     495: aload         5
     497: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     500: checkcast     #118                // class "[Ljava/lang/Object;"
     503: astore        6
     505: iconst_0
     506: istore        7
     508: iconst_0
     509: istore        8
     511: aload         6
     513: arraylength
     514: istore        9
     516: iload         8
     518: iload         9
     520: if_icmpge     615
     523: aload         6
     525: iload         8
     527: aaload
     528: astore        10
     530: iload         7
     532: aload         10
     534: checkcast     #67                 // class "[Z"
     537: astore        11
     539: istore        22
     541: iconst_0
     542: istore        12
     544: aload         11
     546: astore        13
     548: iconst_0
     549: istore        14
     551: iconst_0
     552: istore        15
     554: iconst_0
     555: istore        16
     557: aload         13
     559: arraylength
     560: istore        17
     562: iload         16
     564: iload         17
     566: if_icmpge     597
     569: aload         13
     571: iload         16
     573: baload
     574: istore        18
     576: iload         18
     578: istore        19
     580: iconst_0
     581: istore        20
     583: iload         19
     585: ifeq          591
     588: iinc          15, 1
     591: iinc          16, 1
     594: goto          562
     597: iload         15
     599: nop
     600: istore        23
     602: iload         22
     604: iload         23
     606: iadd
     607: istore        7
     609: iinc          8, 1
     612: goto          516
     615: iload         7
     617: istore        6
     619: getstatic     #124                // Field java/lang/System.out:Ljava/io/PrintStream;
     622: iload         6
     624: invokevirtual #129                // Method java/io/PrintStream.println:(I)V
     627: new           #88                 // class kotlin/ranges/IntRange
     630: dup
     631: iconst_0
     632: bipush        49
     634: invokespecial #91                 // Method kotlin/ranges/IntRange."<init>":(II)V
     637: checkcast     #93                 // class java/lang/Iterable
     640: astore        7
     642: iconst_0
     643: istore        8
     645: aload         4
     647: astore        9
     649: aload         7
     651: invokeinterface #97,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     656: astore        10
     658: aload         10
     660: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     665: ifeq          696
     668: aload         10
     670: checkcast     #105                // class kotlin/collections/IntIterator
     673: invokevirtual #108                // Method kotlin/collections/IntIterator.nextInt:()I
     676: istore        11
     678: aload         9
     680: astore        13
     682: iconst_0
     683: istore        14
     685: aload         13
     687: aload_1
     688: invokestatic  #112                // Method enhanceImage:(Lday20/InfiniteImage;[Z)Lday20/InfiniteImage;
     691: astore        9
     693: goto          658
     696: aload         9
     698: astore        6
     700: aload         6
     702: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     705: checkcast     #118                // class "[Ljava/lang/Object;"
     708: astore        7
     710: iconst_0
     711: istore        8
     713: iconst_0
     714: istore        9
     716: aload         7
     718: arraylength
     719: istore        10
     721: iload         9
     723: iload         10
     725: if_icmpge     820
     728: aload         7
     730: iload         9
     732: aaload
     733: astore        11
     735: iload         8
     737: aload         11
     739: checkcast     #67                 // class "[Z"
     742: astore        12
     744: istore        22
     746: iconst_0
     747: istore        13
     749: aload         12
     751: astore        14
     753: iconst_0
     754: istore        15
     756: iconst_0
     757: istore        16
     759: iconst_0
     760: istore        17
     762: aload         14
     764: arraylength
     765: istore        18
     767: iload         17
     769: iload         18
     771: if_icmpge     802
     774: aload         14
     776: iload         17
     778: baload
     779: istore        19
     781: iload         19
     783: istore        20
     785: iconst_0
     786: istore        21
     788: iload         20
     790: ifeq          796
     793: iinc          16, 1
     796: iinc          17, 1
     799: goto          767
     802: iload         16
     804: nop
     805: istore        23
     807: iload         22
     809: iload         23
     811: iadd
     812: istore        8
     814: iinc          9, 1
     817: goto          721
     820: iload         8
     822: istore        7
     824: getstatic     #124                // Field java/lang/System.out:Ljava/io/PrintStream;
     827: iload         7
     829: invokevirtual #129                // Method java/io/PrintStream.println:(I)V
     832: return

  public static final day20.InfiniteImage enhanceImage(day20.InfiniteImage, boolean[]);
    Code:
       0: aload_0
       1: ldc           #173                // String image
       3: invokestatic  #179                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #180                // String imageEnhancementAlgorithm
       9: invokestatic  #179                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
      16: checkcast     #118                // class "[Ljava/lang/Object;"
      19: arraylength
      20: iconst_2
      21: iadd
      22: istore_2
      23: aload_0
      24: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
      27: iconst_0
      28: aaload
      29: arraylength
      30: iconst_2
      31: iadd
      32: istore_3
      33: aload_0
      34: invokevirtual #183                // Method day20/InfiniteImage.getOuterPixelValue:()Z
      37: ifne          44
      40: iconst_1
      41: goto          45
      44: iconst_0
      45: istore        4
      47: iconst_0
      48: istore        6
      50: iload_2
      51: anewarray     #67                 // class "[Z"
      54: astore        7
      56: iload         6
      58: iload_2
      59: if_icmpge     431
      62: iload         6
      64: istore        8
      66: aload         7
      68: iload         8
      70: iconst_0
      71: iload         8
      73: if_icmpgt     90
      76: iload         8
      78: iconst_2
      79: if_icmpge     86
      82: iconst_1
      83: goto          91
      86: iconst_0
      87: goto          91
      90: iconst_0
      91: ifne          120
      94: iload_2
      95: iconst_2
      96: isub
      97: iload         8
      99: if_icmpgt     116
     102: iload         8
     104: iload_2
     105: if_icmpge     112
     108: iconst_1
     109: goto          117
     112: iconst_0
     113: goto          117
     116: iconst_0
     117: ifeq          164
     120: iconst_0
     121: istore        9
     123: iload_3
     124: newarray       boolean
     126: astore        10
     128: istore        14
     130: astore        13
     132: iload         9
     134: iload_3
     135: if_icmpge     155
     138: iload         9
     140: istore        11
     142: aload         10
     144: iload         11
     146: iload         4
     148: bastore
     149: iinc          9, 1
     152: goto          132
     155: aload         13
     157: iload         14
     159: aload         10
     161: goto          424
     164: iconst_0
     165: istore        9
     167: iload_3
     168: newarray       boolean
     170: astore        10
     172: istore        14
     174: astore        13
     176: iload         9
     178: iload_3
     179: if_icmpge     418
     182: iload         9
     184: istore        11
     186: aload         10
     188: iload         11
     190: iconst_0
     191: iload         11
     193: if_icmpgt     210
     196: iload         11
     198: iconst_2
     199: if_icmpge     206
     202: iconst_1
     203: goto          211
     206: iconst_0
     207: goto          211
     210: iconst_0
     211: ifne          240
     214: iload_3
     215: iconst_2
     216: isub
     217: iload         11
     219: if_icmpgt     236
     222: iload         11
     224: iload_3
     225: if_icmpge     232
     228: iconst_1
     229: goto          237
     232: iconst_0
     233: goto          237
     236: iconst_0
     237: ifeq          245
     240: iload         4
     242: goto          411
     245: bipush        9
     247: newarray       boolean
     249: astore        12
     251: aload         12
     253: iconst_0
     254: aload_0
     255: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     258: iload         8
     260: iconst_2
     261: isub
     262: aaload
     263: iload         11
     265: iconst_2
     266: isub
     267: baload
     268: bastore
     269: aload         12
     271: iconst_1
     272: aload_0
     273: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     276: iload         8
     278: iconst_2
     279: isub
     280: aaload
     281: iload         11
     283: iconst_1
     284: isub
     285: baload
     286: bastore
     287: aload         12
     289: iconst_2
     290: aload_0
     291: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     294: iload         8
     296: iconst_2
     297: isub
     298: aaload
     299: iload         11
     301: baload
     302: bastore
     303: aload         12
     305: iconst_3
     306: aload_0
     307: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     310: iload         8
     312: iconst_1
     313: isub
     314: aaload
     315: iload         11
     317: iconst_2
     318: isub
     319: baload
     320: bastore
     321: aload         12
     323: iconst_4
     324: aload_0
     325: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     328: iload         8
     330: iconst_1
     331: isub
     332: aaload
     333: iload         11
     335: iconst_1
     336: isub
     337: baload
     338: bastore
     339: aload         12
     341: iconst_5
     342: aload_0
     343: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     346: iload         8
     348: iconst_1
     349: isub
     350: aaload
     351: iload         11
     353: baload
     354: bastore
     355: aload         12
     357: bipush        6
     359: aload_0
     360: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     363: iload         8
     365: aaload
     366: iload         11
     368: iconst_2
     369: isub
     370: baload
     371: bastore
     372: aload         12
     374: bipush        7
     376: aload_0
     377: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     380: iload         8
     382: aaload
     383: iload         11
     385: iconst_1
     386: isub
     387: baload
     388: bastore
     389: aload         12
     391: bipush        8
     393: aload_0
     394: invokevirtual #116                // Method day20/InfiniteImage.getInnerData:()[[Z
     397: iload         8
     399: aaload
     400: iload         11
     402: baload
     403: bastore
     404: aload_1
     405: aload         12
     407: invokestatic  #187                // Method toInt:([Z)I
     410: baload
     411: bastore
     412: iinc          9, 1
     415: goto          176
     418: aload         13
     420: iload         14
     422: aload         10
     424: aastore
     425: iinc          6, 1
     428: goto          56
     431: aload         7
     433: astore        5
     435: new           #83                 // class day20/InfiniteImage
     438: dup
     439: aload         5
     441: iload         4
     443: invokespecial #86                 // Method day20/InfiniteImage."<init>":([[ZZ)V
     446: areturn

  public static final int toInt(boolean[]);
    Code:
       0: aload_0
       1: ldc           #194                // String <this>
       3: invokestatic  #179                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #30                 // class java/util/ArrayList
      15: dup
      16: aload_1
      17: arraylength
      18: invokespecial #37                 // Method java/util/ArrayList."<init>":(I)V
      21: checkcast     #39                 // class java/util/Collection
      24: astore        4
      26: iconst_0
      27: istore        5
      29: iconst_0
      30: istore        6
      32: aload_3
      33: arraylength
      34: istore        7
      36: iload         6
      38: iload         7
      40: if_icmpge     88
      43: aload_3
      44: iload         6
      46: baload
      47: istore        8
      49: aload         4
      51: iload         8
      53: istore        9
      55: astore        11
      57: iconst_0
      58: istore        10
      60: iload         9
      62: ifeq          69
      65: iconst_1
      66: goto          70
      69: iconst_0
      70: invokestatic  #199                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      73: aload         11
      75: swap
      76: invokeinterface #53,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      81: pop
      82: iinc          6, 1
      85: goto          36
      88: aload         4
      90: checkcast     #22                 // class java/util/List
      93: nop
      94: checkcast     #93                 // class java/lang/Iterable
      97: ldc           #201                // String
      99: checkcast     #28                 // class java/lang/CharSequence
     102: aconst_null
     103: aconst_null
     104: iconst_0
     105: aconst_null
     106: aconst_null
     107: bipush        62
     109: aconst_null
     110: invokestatic  #205                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     113: astore_1
     114: iconst_2
     115: istore_2
     116: aload_1
     117: iload_2
     118: invokestatic  #211                // Method kotlin/text/CharsKt.checkRadix:(I)I
     121: invokestatic  #215                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     124: ireturn

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


package day16

import java.io.File

fun main() {
    val lines = File("src/main/kotlin/day16/input.txt").readLines()
    val bitsIterator =
        lines.first().map { hexToBinary(it) }.joinToString(separator = "").iterator()
    val packet = Packet.parse(bitsIterator)

    println(packet.versionAggregate())

    println(packet.evaluate())
}

sealed class Packet(val version: Int) {

    abstract fun versionAggregate(): Int
    abstract fun evaluate(): Long

    class Literal(version: Int, val value: Long) : Packet(version) {
        override fun versionAggregate() = version
        override fun evaluate(): Long = value

        companion object {
            fun parse(version: Int, iterator: CharIterator): Literal {
                var lastBitChunk = false
                var numberBits = ""
                while (!lastBitChunk) {
                    lastBitChunk = iterator.take(1) == "0"
                    numberBits += iterator.take(4)
                }
                return Literal(version, numberBits.toLong(2))
            }
        }
    }

    class Operator(version: Int, val type: Int, val subPackets: List<Packet>) : Packet(version) {
        override fun versionAggregate(): Int = version + subPackets.sumOf { it.versionAggregate() }
        override fun evaluate(): Long = when (type) {
            0 -> subPackets.sumOf { it.evaluate() }
            1 -> subPackets.fold(1L) { acc, packet -> acc * packet.evaluate() }
            2 -> subPackets.minOf { it.evaluate() }
            3 -> subPackets.maxOf { it.evaluate() }
            5 -> if (subPackets[0].evaluate() > subPackets[1].evaluate()) 1 else 0
            6 -> if (subPackets[0].evaluate() < subPackets[1].evaluate()) 1 else 0
            7 -> if (subPackets[0].evaluate() == subPackets[1].evaluate()) 1 else 0
            else -> 0L
        }

        companion object {
            fun parse(version: Int, type: Int, iterator: CharIterator): Operator {
                val lengthType = iterator.take(1)
                return when (lengthType) {
                    "0" -> {
                        val numberOfBits = iterator.take(15).toInt(2)
                        val subPacketsIterator = iterator.take(numberOfBits).iterator()
                        val packets = mutableListOf<Packet>()
                        while (subPacketsIterator.hasNext()) {
                            packets.add(parse(subPacketsIterator))
                        }
                        Operator(version, type, packets)
                    }
                    else -> {
                        val numberOfPackets = iterator.take(11).toInt(2)
                        val packets = (1..numberOfPackets).map { parse(iterator) }
                        Operator(version, type, packets)
                    }
                }
            }
        }
    }

    companion object {
        fun parse(iterator: CharIterator): Packet {
            val version = iterator.take(3).toInt(2)
            val type = iterator.take(3).toInt(2)
            return when (type) {
                4 -> Literal.parse(version, iterator)
                else -> Operator.parse(version, type, iterator)
            }
        }
    }
}

fun CharIterator.take(n: Int): String = this.asSequence().take(n).joinToString("")

fun hexToBinary(hex: Char): String {
    return when (hex) {
        '0' -> "0000"
        '1' -> "0001"
        '2' -> "0010"
        '3' -> "0011"
        '4' -> "0100"
        '5' -> "0101"
        '6' -> "0110"
        '7' -> "0111"
        '8' -> "1000"
        '9' -> "1001"
        'A' -> "1010"
        'B' -> "1011"
        'C' -> "1100"
        'D' -> "1101"
        'E' -> "1110"
        'F' -> "1111"
        else -> ""
    }
}

Compiled from "solution.kt"
public final class day16.SolutionKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/main/kotlin/day16/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: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      20: checkcast     #28                 // class java/lang/CharSequence
      23: astore_2
      24: iconst_0
      25: istore_3
      26: aload_2
      27: astore        4
      29: new           #30                 // class java/util/ArrayList
      32: dup
      33: aload_2
      34: invokeinterface #34,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      39: invokespecial #37                 // Method java/util/ArrayList."<init>":(I)V
      42: checkcast     #39                 // class java/util/Collection
      45: astore        5
      47: iconst_0
      48: istore        6
      50: iconst_0
      51: istore        7
      53: iload         7
      55: aload         4
      57: invokeinterface #34,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      62: if_icmpge     107
      65: aload         4
      67: iload         7
      69: invokeinterface #43,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      74: istore        8
      76: aload         5
      78: iload         8
      80: istore        9
      82: astore        11
      84: iconst_0
      85: istore        10
      87: iload         9
      89: invokestatic  #47                 // Method hexToBinary:(C)Ljava/lang/String;
      92: aload         11
      94: swap
      95: invokeinterface #51,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     100: pop
     101: iinc          7, 1
     104: goto          53
     107: aload         5
     109: checkcast     #53                 // class java/util/List
     112: nop
     113: checkcast     #55                 // class java/lang/Iterable
     116: ldc           #57                 // String
     118: checkcast     #28                 // class java/lang/CharSequence
     121: aconst_null
     122: aconst_null
     123: iconst_0
     124: aconst_null
     125: aconst_null
     126: bipush        62
     128: aconst_null
     129: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     132: checkcast     #28                 // class java/lang/CharSequence
     135: invokestatic  #67                 // Method kotlin/text/StringsKt.iterator:(Ljava/lang/CharSequence;)Lkotlin/collections/CharIterator;
     138: astore_1
     139: getstatic     #73                 // Field day16/Packet.Companion:Lday16/Packet$Companion;
     142: aload_1
     143: invokevirtual #79                 // Method day16/Packet$Companion.parse:(Lkotlin/collections/CharIterator;)Lday16/Packet;
     146: astore_2
     147: aload_2
     148: invokevirtual #82                 // Method day16/Packet.versionAggregate:()I
     151: istore_3
     152: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
     155: iload_3
     156: invokevirtual #93                 // Method java/io/PrintStream.println:(I)V
     159: aload_2
     160: invokevirtual #97                 // Method day16/Packet.evaluate:()J
     163: lstore_3
     164: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
     167: lload_3
     168: invokevirtual #100                // Method java/io/PrintStream.println:(J)V
     171: return

  public static final java.lang.String take(kotlin.collections.CharIterator, int);
    Code:
       0: aload_0
       1: ldc           #123                // String <this>
       3: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #131                // class java/util/Iterator
      10: invokestatic  #137                // Method kotlin/sequences/SequencesKt.asSequence:(Ljava/util/Iterator;)Lkotlin/sequences/Sequence;
      13: iload_1
      14: invokestatic  #140                // Method kotlin/sequences/SequencesKt.take:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
      17: ldc           #57                 // String
      19: checkcast     #28                 // class java/lang/CharSequence
      22: aconst_null
      23: aconst_null
      24: iconst_0
      25: aconst_null
      26: aconst_null
      27: bipush        62
      29: aconst_null
      30: invokestatic  #143                // Method kotlin/sequences/SequencesKt.joinToString$default:(Lkotlin/sequences/Sequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      33: areturn

  public static final java.lang.String hexToBinary(char);
    Code:
       0: iload_0
       1: tableswitch   { // 48 to 70
                    48: 108
                    49: 113
                    50: 118
                    51: 123
                    52: 128
                    53: 133
                    54: 138
                    55: 143
                    56: 148
                    57: 153
                    58: 188
                    59: 188
                    60: 188
                    61: 188
                    62: 188
                    63: 188
                    64: 188
                    65: 158
                    66: 163
                    67: 168
                    68: 173
                    69: 178
                    70: 183
               default: 188
          }
     108: ldc           #147                // String 0000
     110: goto          190
     113: ldc           #149                // String 0001
     115: goto          190
     118: ldc           #151                // String 0010
     120: goto          190
     123: ldc           #153                // String 0011
     125: goto          190
     128: ldc           #155                // String 0100
     130: goto          190
     133: ldc           #157                // String 0101
     135: goto          190
     138: ldc           #159                // String 0110
     140: goto          190
     143: ldc           #161                // String 0111
     145: goto          190
     148: ldc           #163                // String 1000
     150: goto          190
     153: ldc           #165                // String 1001
     155: goto          190
     158: ldc           #167                // String 1010
     160: goto          190
     163: ldc           #169                // String 1011
     165: goto          190
     168: ldc           #171                // String 1100
     170: goto          190
     173: ldc           #173                // String 1101
     175: goto          190
     178: ldc           #175                // String 1110
     180: goto          190
     183: ldc           #177                // String 1111
     185: goto          190
     188: ldc           #57                 // String
     190: areturn

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


package day11

import java.io.File

fun main() {
    val lines = File("src/main/kotlin/day11/input.txt").readLines()
    val mapSize = lines.size
    val energyLevelsMap: Array<IntArray> = Array(mapSize) { i -> lines[i].map { it.digitToInt() }.toIntArray() }
    val dumboOctopuses: MutableMap<Coordinate, DumboOctopus> = mutableMapOf()
    for (y in energyLevelsMap.indices) {
        for (x in energyLevelsMap[y].indices) {
            val coordinate = Coordinate(x, y)
            val dumboOctopus = DumboOctopus(coordinate, energyLevelsMap[y][x])
            dumboOctopuses[coordinate] = dumboOctopus
            if (y > 0) dumboOctopuses.getValue(Coordinate(x, y - 1)).addAdjacent(dumboOctopus)
            if (x > 0) dumboOctopuses.getValue(Coordinate(x - 1, y)).addAdjacent(dumboOctopus)
            if (x > 0 && y > 0) dumboOctopuses.getValue(Coordinate(x - 1, y - 1)).addAdjacent(dumboOctopus)
            if (x < mapSize - 1 && y > 0) dumboOctopuses.getValue(Coordinate(x + 1, y - 1)).addAdjacent(dumboOctopus)
        }
    }
    var flashCount = 0
    for (step in 1..100) {
        dumboOctopuses.values.forEach { it.increaseChargeLevel() }
        flashCount += dumboOctopuses.values.count { it.flash() }
    }
    println(flashCount)

    var stepAllFlashed = 100
    var allFlashed = false
    while(!allFlashed) {
        stepAllFlashed++
        dumboOctopuses.values.forEach { it.increaseChargeLevel() }
        allFlashed = dumboOctopuses.values.count { it.flash() } == dumboOctopuses.size
    }
    println(stepAllFlashed)
}

class DumboOctopus(val coordinate: Coordinate, var energyLevel: Int) {
    private val adjacents: MutableSet<DumboOctopus> = mutableSetOf()

    fun increaseChargeLevel() {
        energyLevel++
        if (energyLevel == FLASH_ENERGY_LEVEL) {
            adjacents.forEach { it.increaseChargeLevel() }
        }
    }

    fun addAdjacent(adjacent: DumboOctopus) {
        if (adjacent !in adjacents) {
            adjacents.add(adjacent)
            adjacent.addAdjacent(this)
        }
    }

    fun flash(): Boolean {
        val charged = energyLevel >= FLASH_ENERGY_LEVEL
        if (charged) energyLevel = 0
        return charged
    }

    companion object {
        const val FLASH_ENERGY_LEVEL = 10
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as DumboOctopus

        if (coordinate != other.coordinate) return false

        return true
    }

    override fun hashCode(): Int {
        return coordinate.hashCode()
    }

    override fun toString(): String {
        return "DumboOctopus(coordinate=$coordinate, chargeLevel=$energyLevel)"
    }

}

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

Compiled from "solution.kt"
public final class day11.SolutionKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/main/kotlin/day11/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: invokeinterface #26,  1           // InterfaceMethod java/util/List.size:()I
      22: istore_1
      23: iconst_0
      24: istore_3
      25: iload_1
      26: anewarray     #28                 // class "[I"
      29: astore        4
      31: iload_3
      32: iload_1
      33: if_icmpge     176
      36: iload_3
      37: istore        5
      39: aload         4
      41: iload         5
      43: aload_0
      44: iload         5
      46: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      51: checkcast     #34                 // class java/lang/CharSequence
      54: astore        6
      56: istore        16
      58: astore        15
      60: iconst_0
      61: istore        7
      63: aload         6
      65: astore        8
      67: new           #36                 // class java/util/ArrayList
      70: dup
      71: aload         6
      73: invokeinterface #39,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      78: invokespecial #42                 // Method java/util/ArrayList."<init>":(I)V
      81: checkcast     #44                 // class java/util/Collection
      84: astore        9
      86: iconst_0
      87: istore        10
      89: iconst_0
      90: istore        11
      92: iload         11
      94: aload         8
      96: invokeinterface #39,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     101: if_icmpge     149
     104: aload         8
     106: iload         11
     108: invokeinterface #48,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     113: istore        12
     115: aload         9
     117: iload         12
     119: istore        13
     121: astore        17
     123: iconst_0
     124: istore        14
     126: iload         13
     128: invokestatic  #54                 // Method kotlin/text/CharsKt.digitToInt:(C)I
     131: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     134: aload         17
     136: swap
     137: invokeinterface #64,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     142: pop
     143: iinc          11, 1
     146: goto          92
     149: aload         9
     151: checkcast     #22                 // class java/util/List
     154: nop
     155: astore        17
     157: aload         15
     159: iload         16
     161: aload         17
     163: checkcast     #44                 // class java/util/Collection
     166: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     169: aastore
     170: iinc          3, 1
     173: goto          31
     176: aload         4
     178: astore_2
     179: new           #72                 // class java/util/LinkedHashMap
     182: dup
     183: invokespecial #74                 // Method java/util/LinkedHashMap."<init>":()V
     186: checkcast     #76                 // class java/util/Map
     189: astore_3
     190: iconst_0
     191: istore        4
     193: aload_2
     194: checkcast     #78                 // class "[Ljava/lang/Object;"
     197: arraylength
     198: istore        5
     200: iload         4
     202: iload         5
     204: if_icmpge     415
     207: iconst_0
     208: istore        6
     210: aload_2
     211: iload         4
     213: aaload
     214: arraylength
     215: istore        7
     217: iload         6
     219: iload         7
     221: if_icmpge     409
     224: new           #80                 // class day11/Coordinate
     227: dup
     228: iload         6
     230: iload         4
     232: invokespecial #83                 // Method day11/Coordinate."<init>":(II)V
     235: astore        8
     237: new           #85                 // class day11/DumboOctopus
     240: dup
     241: aload         8
     243: aload_2
     244: iload         4
     246: aaload
     247: iload         6
     249: iaload
     250: invokespecial #88                 // Method day11/DumboOctopus."<init>":(Lday11/Coordinate;I)V
     253: astore        9
     255: aload_3
     256: aload         8
     258: aload         9
     260: invokeinterface #92,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     265: pop
     266: iload         4
     268: ifle          296
     271: aload_3
     272: new           #80                 // class day11/Coordinate
     275: dup
     276: iload         6
     278: iload         4
     280: iconst_1
     281: isub
     282: invokespecial #83                 // Method day11/Coordinate."<init>":(II)V
     285: invokestatic  #98                 // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     288: checkcast     #85                 // class day11/DumboOctopus
     291: aload         9
     293: invokevirtual #102                // Method day11/DumboOctopus.addAdjacent:(Lday11/DumboOctopus;)V
     296: iload         6
     298: ifle          326
     301: aload_3
     302: new           #80                 // class day11/Coordinate
     305: dup
     306: iload         6
     308: iconst_1
     309: isub
     310: iload         4
     312: invokespecial #83                 // Method day11/Coordinate."<init>":(II)V
     315: invokestatic  #98                 // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     318: checkcast     #85                 // class day11/DumboOctopus
     321: aload         9
     323: invokevirtual #102                // Method day11/DumboOctopus.addAdjacent:(Lday11/DumboOctopus;)V
     326: iload         6
     328: ifle          363
     331: iload         4
     333: ifle          363
     336: aload_3
     337: new           #80                 // class day11/Coordinate
     340: dup
     341: iload         6
     343: iconst_1
     344: isub
     345: iload         4
     347: iconst_1
     348: isub
     349: invokespecial #83                 // Method day11/Coordinate."<init>":(II)V
     352: invokestatic  #98                 // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     355: checkcast     #85                 // class day11/DumboOctopus
     358: aload         9
     360: invokevirtual #102                // Method day11/DumboOctopus.addAdjacent:(Lday11/DumboOctopus;)V
     363: iload         6
     365: iload_1
     366: iconst_1
     367: isub
     368: if_icmpge     403
     371: iload         4
     373: ifle          403
     376: aload_3
     377: new           #80                 // class day11/Coordinate
     380: dup
     381: iload         6
     383: iconst_1
     384: iadd
     385: iload         4
     387: iconst_1
     388: isub
     389: invokespecial #83                 // Method day11/Coordinate."<init>":(II)V
     392: invokestatic  #98                 // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     395: checkcast     #85                 // class day11/DumboOctopus
     398: aload         9
     400: invokevirtual #102                // Method day11/DumboOctopus.addAdjacent:(Lday11/DumboOctopus;)V
     403: iinc          6, 1
     406: goto          217
     409: iinc          4, 1
     412: goto          200
     415: iconst_0
     416: istore        4
     418: iconst_1
     419: istore        5
     421: iload         5
     423: bipush        101
     425: if_icmpge     613
     428: aload_3
     429: invokeinterface #106,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     434: checkcast     #108                // class java/lang/Iterable
     437: astore        6
     439: iconst_0
     440: istore        7
     442: aload         6
     444: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     449: astore        8
     451: aload         8
     453: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     458: ifeq          489
     461: aload         8
     463: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     468: astore        9
     470: aload         9
     472: checkcast     #85                 // class day11/DumboOctopus
     475: astore        10
     477: iconst_0
     478: istore        11
     480: aload         10
     482: invokevirtual #125                // Method day11/DumboOctopus.increaseChargeLevel:()V
     485: nop
     486: goto          451
     489: nop
     490: iload         4
     492: aload_3
     493: invokeinterface #106,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     498: checkcast     #108                // class java/lang/Iterable
     501: astore        6
     503: istore        15
     505: iconst_0
     506: istore        7
     508: aload         6
     510: instanceof    #44                 // class java/util/Collection
     513: ifeq          533
     516: aload         6
     518: checkcast     #44                 // class java/util/Collection
     521: invokeinterface #128,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     526: ifeq          533
     529: iconst_0
     530: goto          598
     533: iconst_0
     534: istore        8
     536: aload         6
     538: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     543: astore        9
     545: aload         9
     547: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     552: ifeq          596
     555: aload         9
     557: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     562: astore        10
     564: aload         10
     566: checkcast     #85                 // class day11/DumboOctopus
     569: astore        11
     571: iconst_0
     572: istore        12
     574: aload         11
     576: invokevirtual #131                // Method day11/DumboOctopus.flash:()Z
     579: ifeq          545
     582: iinc          8, 1
     585: iload         8
     587: ifge          545
     590: invokestatic  #134                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     593: goto          545
     596: iload         8
     598: istore        16
     600: iload         15
     602: iload         16
     604: iadd
     605: istore        4
     607: iinc          5, 1
     610: goto          421
     613: getstatic     #140                // Field java/lang/System.out:Ljava/io/PrintStream;
     616: iload         4
     618: invokevirtual #145                // Method java/io/PrintStream.println:(I)V
     621: bipush        100
     623: istore        5
     625: iconst_0
     626: istore        6
     628: iload         6
     630: ifne          821
     633: iinc          5, 1
     636: aload_3
     637: invokeinterface #106,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     642: checkcast     #108                // class java/lang/Iterable
     645: astore        7
     647: iconst_0
     648: istore        8
     650: aload         7
     652: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     657: astore        9
     659: aload         9
     661: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     666: ifeq          697
     669: aload         9
     671: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     676: astore        10
     678: aload         10
     680: checkcast     #85                 // class day11/DumboOctopus
     683: astore        11
     685: iconst_0
     686: istore        12
     688: aload         11
     690: invokevirtual #125                // Method day11/DumboOctopus.increaseChargeLevel:()V
     693: nop
     694: goto          659
     697: nop
     698: aload_3
     699: invokeinterface #106,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     704: checkcast     #108                // class java/lang/Iterable
     707: astore        7
     709: iconst_0
     710: istore        8
     712: aload         7
     714: instanceof    #44                 // class java/util/Collection
     717: ifeq          737
     720: aload         7
     722: checkcast     #44                 // class java/util/Collection
     725: invokeinterface #128,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     730: ifeq          737
     733: iconst_0
     734: goto          802
     737: iconst_0
     738: istore        9
     740: aload         7
     742: invokeinterface #112,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     747: astore        10
     749: aload         10
     751: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     756: ifeq          800
     759: aload         10
     761: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     766: astore        11
     768: aload         11
     770: checkcast     #85                 // class day11/DumboOctopus
     773: astore        12
     775: iconst_0
     776: istore        13
     778: aload         12
     780: invokevirtual #131                // Method day11/DumboOctopus.flash:()Z
     783: ifeq          749
     786: iinc          9, 1
     789: iload         9
     791: ifge          749
     794: invokestatic  #134                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     797: goto          749
     800: iload         9
     802: aload_3
     803: invokeinterface #146,  1          // InterfaceMethod java/util/Map.size:()I
     808: if_icmpne     815
     811: iconst_1
     812: goto          816
     815: iconst_0
     816: istore        6
     818: goto          628
     821: getstatic     #140                // Field java/lang/System.out:Ljava/io/PrintStream;
     824: iload         5
     826: invokevirtual #145                // Method java/io/PrintStream.println:(I)V
     829: return

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


package day10

import java.io.File

val chunkPairs = mapOf(
    '(' to ')',
    '[' to ']',
    '{' to '}',
    '<' to '>',
)
val illegalCharacterPoints = mapOf(
    ')' to 3,
    ']' to 57,
    '}' to 1197,
    '>' to 25137,
)
val autocompleteCharacterPoints = mapOf(
    ')' to 1,
    ']' to 2,
    '}' to 3,
    '>' to 4,
)

fun main() {
    val lines = File("src/main/kotlin/day10/input.txt").readLines()
    val autoCompletesByState = lines
        .map { it.toCharArray() }
        .map { autocomplete(it) }
        .partition { it.failed() }

    println(autoCompletesByState.first
            .mapNotNull { it.illegalChar }
            .mapNotNull { illegalCharacterPoints[it] }
            .sumOf { it }
        )
    println(autoCompletesByState.second
        .mapNotNull { it.missedChars }
        .map { it.fold(0L) { acc, unit -> acc * 5 + (autocompleteCharacterPoints[unit] ?: 0) } }
        .sorted().let { it[it.size / 2] })
}

fun autocomplete(line: CharArray): Autocomplete {
    val stack = ArrayDeque<Char>()
    for (char in line) {
        if (char in chunkPairs.keys) {
            stack.addLast(char)
        } else {
            stack.removeLastOrNull()?.let {
                if (chunkPairs[it] != char) {
                    return Autocomplete(illegalChar = char)
                }
            }
        }
    }
    return Autocomplete(missedChars = stack.mapNotNull { chunkPairs[it] }.reversed())
}

data class Autocomplete(val illegalChar: Char? = null, val missedChars: List<Char>? = null) {
    fun failed() = illegalChar != null
}

Compiled from "solution.kt"
public final class day10.SolutionKt {
  private static final java.util.Map<java.lang.Character, java.lang.Character> chunkPairs;

  private static final java.util.Map<java.lang.Character, java.lang.Integer> illegalCharacterPoints;

  private static final java.util.Map<java.lang.Character, java.lang.Integer> autocompleteCharacterPoints;

  public static final java.util.Map<java.lang.Character, java.lang.Character> getChunkPairs();
    Code:
       0: getstatic     #12                 // Field chunkPairs:Ljava/util/Map;
       3: areturn

  public static final java.util.Map<java.lang.Character, java.lang.Integer> getIllegalCharacterPoints();
    Code:
       0: getstatic     #17                 // Field illegalCharacterPoints:Ljava/util/Map;
       3: areturn

  public static final java.util.Map<java.lang.Character, java.lang.Integer> getAutocompleteCharacterPoints();
    Code:
       0: getstatic     #21                 // Field autocompleteCharacterPoints:Ljava/util/Map;
       3: areturn

  public static final void main();
    Code:
       0: new           #25                 // class java/io/File
       3: dup
       4: ldc           #27                 // String src/main/kotlin/day10/input.txt
       6: invokespecial #31                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #37                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: checkcast     #39                 // class java/lang/Iterable
      20: astore_2
      21: nop
      22: iconst_0
      23: istore_3
      24: aload_2
      25: astore        4
      27: new           #41                 // class java/util/ArrayList
      30: dup
      31: aload_2
      32: bipush        10
      34: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      37: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
      40: checkcast     #52                 // class java/util/Collection
      43: astore        5
      45: iconst_0
      46: istore        6
      48: aload         4
      50: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      55: astore        7
      57: aload         7
      59: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      64: ifeq          114
      67: aload         7
      69: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      74: astore        8
      76: aload         5
      78: aload         8
      80: checkcast     #68                 // class java/lang/String
      83: astore        9
      85: astore        23
      87: iconst_0
      88: istore        10
      90: aload         9
      92: invokevirtual #72                 // Method java/lang/String.toCharArray:()[C
      95: dup
      96: ldc           #74                 // String toCharArray(...)
      98: invokestatic  #80                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     101: nop
     102: aload         23
     104: swap
     105: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     110: pop
     111: goto          57
     114: aload         5
     116: checkcast     #86                 // class java/util/List
     119: nop
     120: checkcast     #39                 // class java/lang/Iterable
     123: astore_2
     124: nop
     125: iconst_0
     126: istore_3
     127: aload_2
     128: astore        4
     130: new           #41                 // class java/util/ArrayList
     133: dup
     134: aload_2
     135: bipush        10
     137: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     140: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
     143: checkcast     #52                 // class java/util/Collection
     146: astore        5
     148: iconst_0
     149: istore        6
     151: aload         4
     153: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     158: astore        7
     160: aload         7
     162: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     167: ifeq          210
     170: aload         7
     172: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     177: astore        8
     179: aload         5
     181: aload         8
     183: checkcast     #88                 // class "[C"
     186: astore        9
     188: astore        23
     190: iconst_0
     191: istore        10
     193: aload         9
     195: invokestatic  #92                 // Method autocomplete:([C)Lday10/Autocomplete;
     198: aload         23
     200: swap
     201: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     206: pop
     207: goto          160
     210: aload         5
     212: checkcast     #86                 // class java/util/List
     215: nop
     216: checkcast     #39                 // class java/lang/Iterable
     219: astore_2
     220: nop
     221: iconst_0
     222: istore_3
     223: new           #41                 // class java/util/ArrayList
     226: dup
     227: invokespecial #94                 // Method java/util/ArrayList."<init>":()V
     230: astore        4
     232: new           #41                 // class java/util/ArrayList
     235: dup
     236: invokespecial #94                 // Method java/util/ArrayList."<init>":()V
     239: astore        5
     241: aload_2
     242: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     247: astore        6
     249: aload         6
     251: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     256: ifeq          307
     259: aload         6
     261: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     266: astore        7
     268: aload         7
     270: checkcast     #96                 // class day10/Autocomplete
     273: astore        8
     275: iconst_0
     276: istore        9
     278: aload         8
     280: invokevirtual #99                 // Method day10/Autocomplete.failed:()Z
     283: ifeq          296
     286: aload         4
     288: aload         7
     290: invokevirtual #100                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     293: goto          303
     296: aload         5
     298: aload         7
     300: invokevirtual #100                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     303: pop
     304: goto          249
     307: new           #102                // class kotlin/Pair
     310: dup
     311: aload         4
     313: aload         5
     315: invokespecial #105                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     318: astore_1
     319: aload_1
     320: invokevirtual #108                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     323: checkcast     #39                 // class java/lang/Iterable
     326: astore_2
     327: nop
     328: iconst_0
     329: istore_3
     330: aload_2
     331: astore        4
     333: new           #41                 // class java/util/ArrayList
     336: dup
     337: invokespecial #94                 // Method java/util/ArrayList."<init>":()V
     340: checkcast     #52                 // class java/util/Collection
     343: astore        5
     345: iconst_0
     346: istore        6
     348: aload         4
     350: astore        7
     352: iconst_0
     353: istore        8
     355: aload         7
     357: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     362: astore        9
     364: aload         9
     366: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     371: ifeq          432
     374: aload         9
     376: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     381: astore        10
     383: aload         10
     385: astore        11
     387: iconst_0
     388: istore        12
     390: aload         11
     392: checkcast     #96                 // class day10/Autocomplete
     395: astore        14
     397: iconst_0
     398: istore        15
     400: aload         14
     402: invokevirtual #112                // Method day10/Autocomplete.getIllegalChar:()Ljava/lang/Character;
     405: dup
     406: ifnull        427
     409: astore        17
     411: iconst_0
     412: istore        18
     414: aload         5
     416: aload         17
     418: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     423: pop
     424: goto          428
     427: pop
     428: nop
     429: goto          364
     432: nop
     433: aload         5
     435: checkcast     #86                 // class java/util/List
     438: nop
     439: checkcast     #39                 // class java/lang/Iterable
     442: astore_2
     443: nop
     444: iconst_0
     445: istore_3
     446: aload_2
     447: astore        4
     449: new           #41                 // class java/util/ArrayList
     452: dup
     453: invokespecial #94                 // Method java/util/ArrayList."<init>":()V
     456: checkcast     #52                 // class java/util/Collection
     459: astore        5
     461: iconst_0
     462: istore        6
     464: aload         4
     466: astore        7
     468: iconst_0
     469: istore        8
     471: aload         7
     473: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     478: astore        9
     480: aload         9
     482: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     487: ifeq          562
     490: aload         9
     492: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     497: astore        10
     499: aload         10
     501: astore        11
     503: iconst_0
     504: istore        12
     506: aload         11
     508: checkcast     #114                // class java/lang/Character
     511: invokevirtual #118                // Method java/lang/Character.charValue:()C
     514: istore        14
     516: iconst_0
     517: istore        15
     519: getstatic     #17                 // Field illegalCharacterPoints:Ljava/util/Map;
     522: iload         14
     524: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     527: invokeinterface #128,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     532: checkcast     #130                // class java/lang/Integer
     535: dup
     536: ifnull        557
     539: astore        17
     541: iconst_0
     542: istore        18
     544: aload         5
     546: aload         17
     548: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     553: pop
     554: goto          558
     557: pop
     558: nop
     559: goto          480
     562: nop
     563: aload         5
     565: checkcast     #86                 // class java/util/List
     568: nop
     569: checkcast     #39                 // class java/lang/Iterable
     572: astore_2
     573: iconst_0
     574: istore_3
     575: aload_2
     576: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     581: astore        4
     583: aload         4
     585: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     590: ifeq          631
     593: aload         4
     595: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     600: astore        5
     602: iload_3
     603: aload         5
     605: checkcast     #132                // class java/lang/Number
     608: invokevirtual #136                // Method java/lang/Number.intValue:()I
     611: istore        6
     613: istore        23
     615: iconst_0
     616: istore        7
     618: iload         6
     620: istore        24
     622: iload         23
     624: iload         24
     626: iadd
     627: istore_3
     628: goto          583
     631: iload_3
     632: istore_2
     633: getstatic     #142                // Field java/lang/System.out:Ljava/io/PrintStream;
     636: iload_2
     637: invokevirtual #147                // Method java/io/PrintStream.println:(I)V
     640: aload_1
     641: invokevirtual #150                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     644: checkcast     #39                 // class java/lang/Iterable
     647: astore_2
     648: nop
     649: iconst_0
     650: istore_3
     651: aload_2
     652: astore        4
     654: new           #41                 // class java/util/ArrayList
     657: dup
     658: invokespecial #94                 // Method java/util/ArrayList."<init>":()V
     661: checkcast     #52                 // class java/util/Collection
     664: astore        5
     666: iconst_0
     667: istore        6
     669: aload         4
     671: astore        7
     673: iconst_0
     674: istore        8
     676: aload         7
     678: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     683: astore        9
     685: aload         9
     687: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     692: ifeq          753
     695: aload         9
     697: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     702: astore        10
     704: aload         10
     706: astore        11
     708: iconst_0
     709: istore        12
     711: aload         11
     713: checkcast     #96                 // class day10/Autocomplete
     716: astore        14
     718: iconst_0
     719: istore        15
     721: aload         14
     723: invokevirtual #154                // Method day10/Autocomplete.getMissedChars:()Ljava/util/List;
     726: dup
     727: ifnull        748
     730: astore        17
     732: iconst_0
     733: istore        18
     735: aload         5
     737: aload         17
     739: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     744: pop
     745: goto          749
     748: pop
     749: nop
     750: goto          685
     753: nop
     754: aload         5
     756: checkcast     #86                 // class java/util/List
     759: nop
     760: checkcast     #39                 // class java/lang/Iterable
     763: astore_2
     764: nop
     765: iconst_0
     766: istore_3
     767: aload_2
     768: astore        4
     770: new           #41                 // class java/util/ArrayList
     773: dup
     774: aload_2
     775: bipush        10
     777: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     780: invokespecial #50                 // Method java/util/ArrayList."<init>":(I)V
     783: checkcast     #52                 // class java/util/Collection
     786: astore        5
     788: iconst_0
     789: istore        6
     791: aload         4
     793: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     798: astore        7
     800: aload         7
     802: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     807: ifeq          953
     810: aload         7
     812: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     817: astore        8
     819: aload         5
     821: aload         8
     823: checkcast     #86                 // class java/util/List
     826: astore        9
     828: astore        23
     830: iconst_0
     831: istore        10
     833: aload         9
     835: checkcast     #39                 // class java/lang/Iterable
     838: astore        11
     840: lconst_0
     841: lstore        12
     843: iconst_0
     844: istore        14
     846: lload         12
     848: lstore        15
     850: aload         11
     852: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     857: astore        17
     859: aload         17
     861: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     866: ifeq          935
     869: aload         17
     871: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     876: astore        18
     878: lload         15
     880: aload         18
     882: checkcast     #114                // class java/lang/Character
     885: invokevirtual #118                // Method java/lang/Character.charValue:()C
     888: istore        19
     890: lstore        20
     892: iconst_0
     893: istore        22
     895: lload         20
     897: iconst_5
     898: i2l
     899: lmul
     900: getstatic     #21                 // Field autocompleteCharacterPoints:Ljava/util/Map;
     903: iload         19
     905: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     908: invokeinterface #128,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     913: checkcast     #130                // class java/lang/Integer
     916: dup
     917: ifnull        926
     920: invokevirtual #155                // Method java/lang/Integer.intValue:()I
     923: goto          928
     926: pop
     927: iconst_0
     928: i2l
     929: ladd
     930: lstore        15
     932: goto          859
     935: lload         15
     937: nop
     938: invokestatic  #160                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     941: aload         23
     943: swap
     944: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     949: pop
     950: goto          800
     953: aload         5
     955: checkcast     #86                 // class java/util/List
     958: nop
     959: checkcast     #39                 // class java/lang/Iterable
     962: invokestatic  #164                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     965: astore_3
     966: iconst_0
     967: istore        4
     969: aload_3
     970: aload_3
     971: invokeinterface #167,  1          // InterfaceMethod java/util/List.size:()I
     976: iconst_2
     977: idiv
     978: invokeinterface #170,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     983: checkcast     #132                // class java/lang/Number
     986: invokevirtual #174                // Method java/lang/Number.longValue:()J
     989: lstore_2
     990: getstatic     #142                // Field java/lang/System.out:Ljava/io/PrintStream;
     993: lload_2
     994: invokevirtual #177                // Method java/io/PrintStream.println:(J)V
     997: return

  public static final day10.Autocomplete autocomplete(char[]);
    Code:
       0: aload_0
       1: ldc           #231                // String line
       3: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #236                // class kotlin/collections/ArrayDeque
       9: dup
      10: invokespecial #237                // Method kotlin/collections/ArrayDeque."<init>":()V
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_0
      17: arraylength
      18: istore_3
      19: iload_2
      20: iload_3
      21: if_icmpge     145
      24: aload_0
      25: iload_2
      26: caload
      27: istore        4
      29: getstatic     #12                 // Field chunkPairs:Ljava/util/Map;
      32: invokeinterface #241,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
      37: iload         4
      39: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      42: invokeinterface #246,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      47: ifeq          62
      50: aload_1
      51: iload         4
      53: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      56: invokevirtual #250                // Method kotlin/collections/ArrayDeque.addLast:(Ljava/lang/Object;)V
      59: goto          139
      62: aload_1
      63: invokevirtual #253                // Method kotlin/collections/ArrayDeque.removeLastOrNull:()Ljava/lang/Object;
      66: checkcast     #114                // class java/lang/Character
      69: dup
      70: ifnull        137
      73: invokevirtual #118                // Method java/lang/Character.charValue:()C
      76: istore        7
      78: iconst_0
      79: istore        8
      81: getstatic     #12                 // Field chunkPairs:Ljava/util/Map;
      84: iload         7
      86: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      89: invokeinterface #128,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      94: checkcast     #114                // class java/lang/Character
      97: iload         4
      99: istore        9
     101: dup
     102: ifnonnull     109
     105: pop
     106: goto          117
     109: invokevirtual #118                // Method java/lang/Character.charValue:()C
     112: iload         9
     114: if_icmpeq     133
     117: new           #96                 // class day10/Autocomplete
     120: dup
     121: iload         4
     123: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     126: aconst_null
     127: iconst_2
     128: aconst_null
     129: invokespecial #256                // Method day10/Autocomplete."<init>":(Ljava/lang/Character;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     132: areturn
     133: nop
     134: goto          139
     137: pop
     138: nop
     139: iinc          2, 1
     142: goto          19
     145: aconst_null
     146: aload_1
     147: checkcast     #39                 // class java/lang/Iterable
     150: astore_2
     151: astore        17
     153: iconst_0
     154: istore_3
     155: aload_2
     156: astore        4
     158: new           #41                 // class java/util/ArrayList
     161: dup
     162: invokespecial #94                 // Method java/util/ArrayList."<init>":()V
     165: checkcast     #52                 // class java/util/Collection
     168: astore        5
     170: iconst_0
     171: istore        6
     173: aload         4
     175: astore        7
     177: iconst_0
     178: istore        8
     180: aload         7
     182: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     187: astore        9
     189: aload         9
     191: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     196: ifeq          271
     199: aload         9
     201: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     206: astore        10
     208: aload         10
     210: astore        11
     212: iconst_0
     213: istore        12
     215: aload         11
     217: checkcast     #114                // class java/lang/Character
     220: invokevirtual #118                // Method java/lang/Character.charValue:()C
     223: istore        13
     225: iconst_0
     226: istore        14
     228: getstatic     #12                 // Field chunkPairs:Ljava/util/Map;
     231: iload         13
     233: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     236: invokeinterface #128,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     241: checkcast     #114                // class java/lang/Character
     244: dup
     245: ifnull        266
     248: astore        15
     250: iconst_0
     251: istore        16
     253: aload         5
     255: aload         15
     257: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     262: pop
     263: goto          267
     266: pop
     267: nop
     268: goto          189
     271: nop
     272: aload         5
     274: checkcast     #86                 // class java/util/List
     277: nop
     278: aload         17
     280: swap
     281: checkcast     #39                 // class java/lang/Iterable
     284: invokestatic  #259                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     287: iconst_1
     288: aconst_null
     289: astore        18
     291: istore        19
     293: astore        20
     295: astore        21
     297: new           #96                 // class day10/Autocomplete
     300: dup
     301: aload         21
     303: aload         20
     305: iload         19
     307: aload         18
     309: invokespecial #256                // Method day10/Autocomplete."<init>":(Ljava/lang/Character;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     312: areturn

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

  static {};
    Code:
       0: iconst_4
       1: anewarray     #102                // class kotlin/Pair
       4: astore_0
       5: aload_0
       6: iconst_0
       7: bipush        40
       9: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      12: bipush        41
      14: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      17: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      20: aastore
      21: aload_0
      22: iconst_1
      23: bipush        91
      25: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      28: bipush        93
      30: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      33: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      36: aastore
      37: aload_0
      38: iconst_2
      39: bipush        123
      41: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      44: bipush        125
      46: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      49: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      52: aastore
      53: aload_0
      54: iconst_3
      55: bipush        60
      57: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      60: bipush        62
      62: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      65: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      68: aastore
      69: aload_0
      70: invokestatic  #282                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      73: putstatic     #12                 // Field chunkPairs:Ljava/util/Map;
      76: iconst_4
      77: anewarray     #102                // class kotlin/Pair
      80: astore_0
      81: aload_0
      82: iconst_0
      83: bipush        41
      85: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      88: iconst_3
      89: invokestatic  #285                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      92: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      95: aastore
      96: aload_0
      97: iconst_1
      98: bipush        93
     100: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     103: bipush        57
     105: invokestatic  #285                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     111: aastore
     112: aload_0
     113: iconst_2
     114: bipush        125
     116: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     119: sipush        1197
     122: invokestatic  #285                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     125: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     128: aastore
     129: aload_0
     130: iconst_3
     131: bipush        62
     133: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     136: sipush        25137
     139: invokestatic  #285                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     142: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     145: aastore
     146: aload_0
     147: invokestatic  #282                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     150: putstatic     #17                 // Field illegalCharacterPoints:Ljava/util/Map;
     153: iconst_4
     154: anewarray     #102                // class kotlin/Pair
     157: astore_0
     158: aload_0
     159: iconst_0
     160: bipush        41
     162: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     165: iconst_1
     166: invokestatic  #285                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     169: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     172: aastore
     173: aload_0
     174: iconst_1
     175: bipush        93
     177: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     180: iconst_2
     181: invokestatic  #285                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     184: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     187: aastore
     188: aload_0
     189: iconst_2
     190: bipush        125
     192: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     195: iconst_3
     196: invokestatic  #285                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     199: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     202: aastore
     203: aload_0
     204: iconst_3
     205: bipush        62
     207: invokestatic  #122                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     210: iconst_4
     211: invokestatic  #285                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     214: invokestatic  #276                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     217: aastore
     218: aload_0
     219: invokestatic  #282                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     222: putstatic     #21                 // Field autocompleteCharacterPoints:Ljava/util/Map;
     225: return
}