import java.lang.NumberFormatException
import kotlin.math.abs

val distances = listOf(1.2, 1.8, 2.5, 3.5, 5.0, 7.0)
val apertures = listOf(1.2, 1.4, 2, 2.8, 4, 5.6, 8, 11, 16, 22, 32, 45)

fun calculateAperture(iso_: String?, distance_: String?) : String {
    val iso = convertIso(iso_)
    val distance = convertDistance(distance_)
    distance?.let {
        val distanceIndex = distances.reversed().indexOf(it)
        val isoIndex = iso.index
        return "Set your aperture to ${apertures[distanceIndex + isoIndex]}"
    } ?: run {
        return "Unable to convert distance."
    }
}

fun convertDistance(distance_: String?) : Double? =
    try {
        distance_?.toDouble()?.let {
            distances.closestValue(it)
        } ?: run {
            null
        }
    } catch (exception: NumberFormatException) {
        null
    }

private fun List<Double>.closestValue(value: Double) = minByOrNull { abs(value - it) }

fun convertIso(iso: String?) : ISO =
    when(iso?.trim()) {
        "25" -> ISO.I25
        "50" -> ISO.I50
        "100" -> ISO.I100
        "200" -> ISO.I200
        "400" -> ISO.I400
        "800" -> ISO.I800
        "1000" -> ISO.I1000
        else -> ISO.I100
    }

enum class ISO(val index: Int) {
    I25(0),
    I50(1),
    I100(2),
    I200(3),
    I400(4),
    I800(5),
    I1000(6)
}

Compiled from "CalculateAperture.kt"
public final class CalculateApertureKt {
  private static final java.util.List<java.lang.Double> distances;

  private static final java.util.List<java.lang.Object> apertures;

  public static final java.util.List<java.lang.Double> getDistances();
    Code:
       0: getstatic     #12                 // Field distances:Ljava/util/List;
       3: areturn

  public static final java.util.List<java.lang.Object> getApertures();
    Code:
       0: getstatic     #17                 // Field apertures:Ljava/util/List;
       3: areturn

  public static final java.lang.String calculateAperture(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #24                 // Method convertIso:(Ljava/lang/String;)LISO;
       4: astore_2
       5: aload_1
       6: invokestatic  #28                 // Method convertDistance:(Ljava/lang/String;)Ljava/lang/Double;
       9: astore_3
      10: aload_3
      11: dup
      12: ifnull        85
      15: checkcast     #30                 // class java/lang/Number
      18: invokevirtual #34                 // Method java/lang/Number.doubleValue:()D
      21: dstore        5
      23: iconst_0
      24: istore        7
      26: getstatic     #12                 // Field distances:Ljava/util/List;
      29: checkcast     #36                 // class java/lang/Iterable
      32: invokestatic  #42                 // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
      35: dload         5
      37: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      40: invokeinterface #54,  2           // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
      45: istore        8
      47: aload_2
      48: invokevirtual #60                 // Method ISO.getIndex:()I
      51: istore        9
      53: new           #62                 // class java/lang/StringBuilder
      56: dup
      57: invokespecial #66                 // Method java/lang/StringBuilder."<init>":()V
      60: ldc           #68                 // String Set your aperture to
      62: invokevirtual #72                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      65: getstatic     #17                 // Field apertures:Ljava/util/List;
      68: iload         8
      70: iload         9
      72: iadd
      73: invokeinterface #76,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      78: invokevirtual #79                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      81: invokevirtual #83                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      84: areturn
      85: pop
      86: iconst_0
      87: istore        4
      89: ldc           #85                 // String Unable to convert distance.
      91: areturn

  public static final java.lang.Double convertDistance(java.lang.String);
    Code:
       0: nop
       1: aload_0
       2: dup
       3: ifnull        27
       6: invokestatic  #107                // Method java/lang/Double.parseDouble:(Ljava/lang/String;)D
       9: dstore        4
      11: iconst_0
      12: istore        6
      14: getstatic     #12                 // Field distances:Ljava/util/List;
      17: dload         4
      19: invokestatic  #111                // Method closestValue:(Ljava/util/List;D)Ljava/lang/Double;
      22: nop
      23: dup
      24: ifnonnull     31
      27: pop
      28: iconst_0
      29: istore_3
      30: aconst_null
      31: astore_1
      32: goto          38
      35: astore_2
      36: aconst_null
      37: astore_1
      38: aload_1
      39: areturn
    Exception table:
       from    to  target type
           0    32    35   Class java/lang/NumberFormatException

  private static final java.lang.Double closestValue(java.util.List<java.lang.Double>, double);
    Code:
       0: aload_0
       1: checkcast     #36                 // class java/lang/Iterable
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokeinterface #120,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      14: astore        5
      16: aload         5
      18: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifne          30
      26: aconst_null
      27: goto          139
      30: aload         5
      32: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      37: astore        6
      39: aload         5
      41: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifne          54
      49: aload         6
      51: goto          139
      54: aload         6
      56: checkcast     #30                 // class java/lang/Number
      59: invokevirtual #34                 // Method java/lang/Number.doubleValue:()D
      62: dstore        7
      64: iconst_0
      65: istore        9
      67: dload_1
      68: dload         7
      70: dsub
      71: invokestatic  #136                // Method java/lang/Math.abs:(D)D
      74: nop
      75: dstore        11
      77: aload         5
      79: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      84: astore        13
      86: aload         13
      88: checkcast     #30                 // class java/lang/Number
      91: invokevirtual #34                 // Method java/lang/Number.doubleValue:()D
      94: dstore        14
      96: iconst_0
      97: istore        16
      99: dload_1
     100: dload         14
     102: dsub
     103: invokestatic  #136                // Method java/lang/Math.abs:(D)D
     106: nop
     107: dstore        9
     109: dload         11
     111: dload         9
     113: invokestatic  #140                // Method java/lang/Double.compare:(DD)I
     116: ifle          127
     119: aload         13
     121: astore        6
     123: dload         9
     125: dstore        11
     127: aload         5
     129: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     134: ifne          77
     137: aload         6
     139: checkcast     #44                 // class java/lang/Double
     142: areturn

  public static final ISO convertIso(java.lang.String);
    Code:
       0: aload_0
       1: dup
       2: ifnull        17
       5: checkcast     #155                // class java/lang/CharSequence
       8: invokestatic  #161                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      11: invokevirtual #162                // Method java/lang/Object.toString:()Ljava/lang/String;
      14: goto          19
      17: pop
      18: aconst_null
      19: astore_1
      20: aload_1
      21: ifnull        222
      24: aload_1
      25: invokevirtual #165                // Method java/lang/String.hashCode:()I
      28: lookupswitch  { // 7
                  1603: 120
                  1691: 168
                 48625: 96
                 49586: 108
                 51508: 132
                 55352: 144
               1507423: 156
               default: 222
          }
      96: aload_1
      97: ldc           #167                // String 100
      99: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     102: ifne          192
     105: goto          222
     108: aload_1
     109: ldc           #173                // String 200
     111: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     114: ifne          198
     117: goto          222
     120: aload_1
     121: ldc           #175                // String 25
     123: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     126: ifne          180
     129: goto          222
     132: aload_1
     133: ldc           #177                // String 400
     135: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     138: ifne          204
     141: goto          222
     144: aload_1
     145: ldc           #179                // String 800
     147: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     150: ifne          210
     153: goto          222
     156: aload_1
     157: ldc           #181                // String 1000
     159: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     162: ifne          216
     165: goto          222
     168: aload_1
     169: ldc           #183                // String 50
     171: invokevirtual #171                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     174: ifne          186
     177: goto          222
     180: getstatic     #186                // Field ISO.I25:LISO;
     183: goto          225
     186: getstatic     #189                // Field ISO.I50:LISO;
     189: goto          225
     192: getstatic     #192                // Field ISO.I100:LISO;
     195: goto          225
     198: getstatic     #195                // Field ISO.I200:LISO;
     201: goto          225
     204: getstatic     #198                // Field ISO.I400:LISO;
     207: goto          225
     210: getstatic     #201                // Field ISO.I800:LISO;
     213: goto          225
     216: getstatic     #204                // Field ISO.I1000:LISO;
     219: goto          225
     222: getstatic     #192                // Field ISO.I100:LISO;
     225: areturn

  static {};
    Code:
       0: bipush        6
       2: anewarray     #44                 // class java/lang/Double
       5: astore_0
       6: aload_0
       7: iconst_0
       8: ldc2_w        #206                // double 1.2d
      11: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      14: aastore
      15: aload_0
      16: iconst_1
      17: ldc2_w        #208                // double 1.8d
      20: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      23: aastore
      24: aload_0
      25: iconst_2
      26: ldc2_w        #210                // double 2.5d
      29: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      32: aastore
      33: aload_0
      34: iconst_3
      35: ldc2_w        #212                // double 3.5d
      38: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      41: aastore
      42: aload_0
      43: iconst_4
      44: ldc2_w        #214                // double 5.0d
      47: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      50: aastore
      51: aload_0
      52: iconst_5
      53: ldc2_w        #216                // double 7.0d
      56: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      59: aastore
      60: aload_0
      61: invokestatic  #221                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      64: putstatic     #12                 // Field distances:Ljava/util/List;
      67: bipush        12
      69: anewarray     #4                  // class java/lang/Object
      72: astore_0
      73: aload_0
      74: iconst_0
      75: ldc2_w        #206                // double 1.2d
      78: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      81: aastore
      82: aload_0
      83: iconst_1
      84: ldc2_w        #222                // double 1.4d
      87: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      90: aastore
      91: aload_0
      92: iconst_2
      93: iconst_2
      94: invokestatic  #228                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      97: aastore
      98: aload_0
      99: iconst_3
     100: ldc2_w        #229                // double 2.8d
     103: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     106: aastore
     107: aload_0
     108: iconst_4
     109: iconst_4
     110: invokestatic  #228                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     113: aastore
     114: aload_0
     115: iconst_5
     116: ldc2_w        #231                // double 5.6d
     119: invokestatic  #48                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     122: aastore
     123: aload_0
     124: bipush        6
     126: bipush        8
     128: invokestatic  #228                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     131: aastore
     132: aload_0
     133: bipush        7
     135: bipush        11
     137: invokestatic  #228                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     140: aastore
     141: aload_0
     142: bipush        8
     144: bipush        16
     146: invokestatic  #228                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     149: aastore
     150: aload_0
     151: bipush        9
     153: bipush        22
     155: invokestatic  #228                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     158: aastore
     159: aload_0
     160: bipush        10
     162: bipush        32
     164: invokestatic  #228                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     167: aastore
     168: aload_0
     169: bipush        11
     171: bipush        45
     173: invokestatic  #228                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     176: aastore
     177: aload_0
     178: invokestatic  #221                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     181: putstatic     #17                 // Field apertures:Ljava/util/List;
     184: return
}


import java.io.File
import kotlin.math.abs

fun main() {
    val input = File("five.txt").readText()
    val coord = input.trim().split("\n").map{ it.split(" -> ")}
    val mat = Array(1000) {Array(1000) {0} }
    //val mat = Array(10) {Array(10) {0} }
    for (c in coord) {
        val start = c.first().split(","); val stop = c.last().split(",")
        val x1 = start.first().toInt(); val y1 = start.last().toInt()
        val x2 = stop.first().toInt(); val y2 = stop.last().toInt()

        if (x1 == x2) {
            val mnY = minOf(y1,y2); val mxY = maxOf(y1,y2)
            for (y in mnY..mxY) {
                    mat[y][x1] += 1
            }
        } else if (y1 == y2) {
            val mnX = minOf(x1,x2); val mxX = maxOf(x1,x2)
            for (x in mnX..mxX) {
                mat[y1][x] += 1
            }
        // Part B
        } else {
            for (i in 0..abs(x1-x2)) {
                if (y1 < y2) {
                    if (x1 < x2) {
                        mat[y1 + i][x1 + i] += 1
                    } else {
                        mat[y1 + i][x1 - i] += 1
                    }
                } else {
                    if (x1 < x2) {
                        mat[y1 - i][x1 + i] += 1
                    } else {
                        mat[y1 - i][x1 - i] += 1
                    }
                }
            }
        }
    }
    //mPrint(mat)
    print(mCount(mat))
}

fun mPrint(mat: Array<Array<Int>>) {
    for (array in mat) {
        for (value in array) {
            print(value)
        }
        println()
    }
}

fun mCount(mat: Array<Array<Int>>) : Int {
    var count = 0
    for (array in mat) {
        for (value in array) {
            if (value >= 2){
              count += 1
            }
        }
    }
    return(count)
}

Compiled from "five.kt"
public final class FiveKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String five.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.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: astore_0
      16: aload_0
      17: checkcast     #22                 // class java/lang/CharSequence
      20: invokestatic  #28                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      23: invokevirtual #32                 // Method java/lang/Object.toString:()Ljava/lang/String;
      26: checkcast     #22                 // class java/lang/CharSequence
      29: iconst_1
      30: anewarray     #34                 // class java/lang/String
      33: astore_2
      34: aload_2
      35: iconst_0
      36: ldc           #36                 // String \n
      38: aastore
      39: aload_2
      40: iconst_0
      41: iconst_0
      42: bipush        6
      44: aconst_null
      45: invokestatic  #40                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      48: checkcast     #42                 // class java/lang/Iterable
      51: astore_2
      52: iconst_0
      53: istore_3
      54: aload_2
      55: astore        4
      57: new           #44                 // class java/util/ArrayList
      60: dup
      61: aload_2
      62: bipush        10
      64: invokestatic  #50                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      67: invokespecial #53                 // Method java/util/ArrayList."<init>":(I)V
      70: checkcast     #55                 // class java/util/Collection
      73: astore        5
      75: iconst_0
      76: istore        6
      78: aload         4
      80: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      85: astore        7
      87: aload         7
      89: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      94: ifeq          159
      97: aload         7
      99: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     104: astore        8
     106: aload         5
     108: aload         8
     110: checkcast     #34                 // class java/lang/String
     113: astore        9
     115: astore        16
     117: iconst_0
     118: istore        10
     120: aload         9
     122: checkcast     #22                 // class java/lang/CharSequence
     125: iconst_1
     126: anewarray     #34                 // class java/lang/String
     129: astore        11
     131: aload         11
     133: iconst_0
     134: ldc           #71                 // String  ->
     136: aastore
     137: aload         11
     139: iconst_0
     140: iconst_0
     141: bipush        6
     143: aconst_null
     144: invokestatic  #40                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     147: aload         16
     149: swap
     150: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     155: pop
     156: goto          87
     159: aload         5
     161: checkcast     #77                 // class java/util/List
     164: nop
     165: astore_1
     166: iconst_0
     167: istore_3
     168: sipush        1000
     171: anewarray     #79                 // class "[Ljava/lang/Integer;"
     174: astore        4
     176: iload_3
     177: sipush        1000
     180: if_icmpge     245
     183: iload_3
     184: istore        5
     186: aload         4
     188: iload         5
     190: iconst_0
     191: istore        6
     193: sipush        1000
     196: anewarray     #81                 // class java/lang/Integer
     199: astore        7
     201: istore        17
     203: astore        16
     205: iload         6
     207: sipush        1000
     210: if_icmpge     232
     213: iload         6
     215: istore        8
     217: aload         7
     219: iload         8
     221: iconst_0
     222: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     225: aastore
     226: iinc          6, 1
     229: goto          205
     232: aload         16
     234: iload         17
     236: aload         7
     238: aastore
     239: iinc          3, 1
     242: goto          176
     245: aload         4
     247: astore_2
     248: aload_1
     249: invokeinterface #86,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     254: astore_3
     255: aload_3
     256: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     261: ifeq          740
     264: aload_3
     265: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     270: checkcast     #77                 // class java/util/List
     273: astore        4
     275: aload         4
     277: invokestatic  #90                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     280: checkcast     #22                 // class java/lang/CharSequence
     283: iconst_1
     284: anewarray     #34                 // class java/lang/String
     287: astore        6
     289: aload         6
     291: iconst_0
     292: ldc           #92                 // String ,
     294: aastore
     295: aload         6
     297: iconst_0
     298: iconst_0
     299: bipush        6
     301: aconst_null
     302: invokestatic  #40                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     305: astore        5
     307: aload         4
     309: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     312: checkcast     #22                 // class java/lang/CharSequence
     315: iconst_1
     316: anewarray     #34                 // class java/lang/String
     319: astore        7
     321: aload         7
     323: iconst_0
     324: ldc           #92                 // String ,
     326: aastore
     327: aload         7
     329: iconst_0
     330: iconst_0
     331: bipush        6
     333: aconst_null
     334: invokestatic  #40                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     337: astore        6
     339: aload         5
     341: invokestatic  #90                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     344: checkcast     #34                 // class java/lang/String
     347: invokestatic  #99                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     350: istore        7
     352: aload         5
     354: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     357: checkcast     #34                 // class java/lang/String
     360: invokestatic  #99                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     363: istore        8
     365: aload         6
     367: invokestatic  #90                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     370: checkcast     #34                 // class java/lang/String
     373: invokestatic  #99                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     376: istore        9
     378: aload         6
     380: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     383: checkcast     #34                 // class java/lang/String
     386: invokestatic  #99                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     389: istore        10
     391: iload         7
     393: iload         9
     395: if_icmpne     464
     398: iload         8
     400: iload         10
     402: invokestatic  #105                // Method java/lang/Math.min:(II)I
     405: istore        11
     407: iload         8
     409: iload         10
     411: invokestatic  #108                // Method java/lang/Math.max:(II)I
     414: istore        12
     416: iload         11
     418: istore        13
     420: iload         13
     422: iload         12
     424: if_icmpgt     255
     427: aload_2
     428: iload         13
     430: aaload
     431: astore        14
     433: aload         14
     435: iload         7
     437: aload         14
     439: iload         7
     441: aaload
     442: invokevirtual #112                // Method java/lang/Integer.intValue:()I
     445: iconst_1
     446: iadd
     447: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     450: aastore
     451: iload         13
     453: iload         12
     455: if_icmpeq     255
     458: iinc          13, 1
     461: goto          427
     464: iload         8
     466: iload         10
     468: if_icmpne     541
     471: iload         7
     473: iload         9
     475: invokestatic  #105                // Method java/lang/Math.min:(II)I
     478: istore        11
     480: iload         7
     482: iload         9
     484: invokestatic  #108                // Method java/lang/Math.max:(II)I
     487: istore        12
     489: iload         11
     491: istore        13
     493: iload         13
     495: iload         12
     497: if_icmpgt     255
     500: aload_2
     501: iload         8
     503: aaload
     504: astore        14
     506: iload         13
     508: istore        15
     510: aload         14
     512: iload         15
     514: aload         14
     516: iload         15
     518: aaload
     519: invokevirtual #112                // Method java/lang/Integer.intValue:()I
     522: iconst_1
     523: iadd
     524: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     527: aastore
     528: iload         13
     530: iload         12
     532: if_icmpeq     255
     535: iinc          13, 1
     538: goto          500
     541: iconst_0
     542: istore        11
     544: iload         7
     546: iload         9
     548: isub
     549: invokestatic  #116                // Method java/lang/Math.abs:(I)I
     552: istore        12
     554: iload         11
     556: iload         12
     558: if_icmpgt     255
     561: iload         8
     563: iload         10
     565: if_icmpge     649
     568: iload         7
     570: iload         9
     572: if_icmpge     612
     575: aload_2
     576: iload         8
     578: iload         11
     580: iadd
     581: aaload
     582: astore        13
     584: iload         7
     586: iload         11
     588: iadd
     589: istore        14
     591: aload         13
     593: iload         14
     595: aload         13
     597: iload         14
     599: aaload
     600: invokevirtual #112                // Method java/lang/Integer.intValue:()I
     603: iconst_1
     604: iadd
     605: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     608: aastore
     609: goto          727
     612: aload_2
     613: iload         8
     615: iload         11
     617: iadd
     618: aaload
     619: astore        13
     621: iload         7
     623: iload         11
     625: isub
     626: istore        14
     628: aload         13
     630: iload         14
     632: aload         13
     634: iload         14
     636: aaload
     637: invokevirtual #112                // Method java/lang/Integer.intValue:()I
     640: iconst_1
     641: iadd
     642: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     645: aastore
     646: goto          727
     649: iload         7
     651: iload         9
     653: if_icmpge     693
     656: aload_2
     657: iload         8
     659: iload         11
     661: isub
     662: aaload
     663: astore        13
     665: iload         7
     667: iload         11
     669: iadd
     670: istore        14
     672: aload         13
     674: iload         14
     676: aload         13
     678: iload         14
     680: aaload
     681: invokevirtual #112                // Method java/lang/Integer.intValue:()I
     684: iconst_1
     685: iadd
     686: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     689: aastore
     690: goto          727
     693: aload_2
     694: iload         8
     696: iload         11
     698: isub
     699: aaload
     700: astore        13
     702: iload         7
     704: iload         11
     706: isub
     707: istore        14
     709: aload         13
     711: iload         14
     713: aload         13
     715: iload         14
     717: aaload
     718: invokevirtual #112                // Method java/lang/Integer.intValue:()I
     721: iconst_1
     722: iadd
     723: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     726: aastore
     727: iload         11
     729: iload         12
     731: if_icmpeq     255
     734: iinc          11, 1
     737: goto          561
     740: aload_2
     741: invokestatic  #120                // Method mCount:([[Ljava/lang/Integer;)I
     744: istore_3
     745: getstatic     #126                // Field java/lang/System.out:Ljava/io/PrintStream;
     748: iload_3
     749: invokevirtual #131                // Method java/io/PrintStream.print:(I)V
     752: return

  public static final void mPrint(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc           #168                // String mat
       3: invokestatic  #174                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: checkcast     #176                // class "[Ljava/lang/Object;"
      12: arraylength
      13: istore_2
      14: iload_1
      15: iload_2
      16: if_icmpge     72
      19: aload_0
      20: iload_1
      21: aaload
      22: astore_3
      23: iconst_0
      24: istore        4
      26: aload_3
      27: arraylength
      28: istore        5
      30: iload         4
      32: iload         5
      34: if_icmpge     60
      37: aload_3
      38: iload         4
      40: aaload
      41: invokevirtual #112                // Method java/lang/Integer.intValue:()I
      44: istore        6
      46: getstatic     #126                // Field java/lang/System.out:Ljava/io/PrintStream;
      49: iload         6
      51: invokevirtual #131                // Method java/io/PrintStream.print:(I)V
      54: iinc          4, 1
      57: goto          30
      60: getstatic     #126                // Field java/lang/System.out:Ljava/io/PrintStream;
      63: invokevirtual #179                // Method java/io/PrintStream.println:()V
      66: iinc          1, 1
      69: goto          14
      72: return

  public static final int mCount(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc           #168                // String mat
       3: invokestatic  #174                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: iconst_0
       9: istore_2
      10: aload_0
      11: checkcast     #176                // class "[Ljava/lang/Object;"
      14: arraylength
      15: istore_3
      16: iload_2
      17: iload_3
      18: if_icmpge     72
      21: aload_0
      22: iload_2
      23: aaload
      24: astore        4
      26: iconst_0
      27: istore        5
      29: aload         4
      31: arraylength
      32: istore        6
      34: iload         5
      36: iload         6
      38: if_icmpge     66
      41: aload         4
      43: iload         5
      45: aaload
      46: invokevirtual #112                // Method java/lang/Integer.intValue:()I
      49: istore        7
      51: iload         7
      53: iconst_2
      54: if_icmplt     60
      57: iinc          1, 1
      60: iinc          5, 1
      63: goto          34
      66: iinc          2, 1
      69: goto          16
      72: iload_1
      73: ireturn

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


import java.io.File
import java.math.BigInteger
import java.util.Collections

fun main() {
    val input = File("input.txt").readText()
    println(cosmicExpansion(input,2))
    println(cosmicExpansion(input,1000000))
}

fun cosmicExpansion(input: String, times: Int):BigInteger{
    var lines = input.split("\n").dropLast(1)
    var n = lines.size
    var map = Array(n) {Array(n) {""} }
    var galaxies = arrayOf<Pair<Int,Int>>()
    for (y in 0..n-1) {
        val line = lines[y].split("").drop(1).dropLast(1)
        for (x in 0..n-1) {
            var v = line[x]
            map[y][x] = v
            if (v == "#") {
                galaxies += Pair(x,y)
            }
        }
    }
    //pprint(map)

    var distSum = 0.toBigInteger()
    var (xs,ys) = getExpandLines(map,n)
    for (gi in 0..galaxies.size) {
        for (gj in gi+1..galaxies.size-1) {
            var p1 = galaxies[gi]
            var p2 = galaxies[gj]
            distSum += getDist(p1,p2,xs,ys,times)
         }
    }
    return distSum
}

fun getDist(p1:Pair<Int,Int>, p2:Pair<Int,Int>, xs:Array<Int>, ys: Array<Int>, times:Int):BigInteger {
    var (x1,y1) = p1
    var (x2,y2) = p2
    var dist = Math.abs(x2-x1) + Math.abs(y2-y1)
    if (x1 < x2) {
        x2 = x1.apply{x1 = x2}
    }
    if (y1 < y2) {
        y2 = y1.apply{y1 = y2}
    }

    var cnt = 0
    for (xx in x2..x1) {
        if (xs.any({x -> x==xx})) {
            cnt += 1
        }
    }
    for (yy in y2..y1) {
        if (ys.any({y -> y==yy})) {
            cnt += 1
        }
    }
    return dist.toBigInteger() + (cnt.toBigInteger() * (times-1).toBigInteger())
}

fun getExpandLines(map:Array<Array<String>>, n:Int):Pair<Array<Int>,Array<Int>> {
    var ys = arrayOf<Int>()
    for (x in 0..n-1) {
        var col = arrayOf<String>()
        for (y in 0..n-1) {
            col += map[y][x]
        }
        if (col.all({y -> y=="."})) {
            ys += x
        }
    }
    var xs = arrayOf<Int>()
    for (x in 0..n-1) {
        if (map[x].all({x -> x!="#"})) {
            xs += x
        }
    }
    return Pair(ys,xs)
}

fun pprint(map: Array<Array<String>>) {
    for (line in map) {
        for (l in line) {
            print(l)
        }
        print("\n")
    }
}

Compiled from "eleven.kt"
public final class ElevenKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String 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.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: astore_0
      16: aload_0
      17: iconst_2
      18: invokestatic  #24                 // Method cosmicExpansion:(Ljava/lang/String;I)Ljava/math/BigInteger;
      21: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      24: swap
      25: invokevirtual #36                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      28: aload_0
      29: ldc           #37                 // int 1000000
      31: invokestatic  #24                 // Method cosmicExpansion:(Ljava/lang/String;I)Ljava/math/BigInteger;
      34: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      37: swap
      38: invokevirtual #36                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      41: return

  public static final java.math.BigInteger cosmicExpansion(java.lang.String, int);
    Code:
       0: aload_0
       1: ldc           #41                 // String input
       3: invokestatic  #47                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #49                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #51                 // class java/lang/String
      14: astore_3
      15: aload_3
      16: iconst_0
      17: ldc           #53                 // String \n
      19: aastore
      20: aload_3
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #59                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: iconst_1
      30: invokestatic  #65                 // Method kotlin/collections/CollectionsKt.dropLast:(Ljava/util/List;I)Ljava/util/List;
      33: astore_2
      34: aload_2
      35: invokeinterface #71,  1           // InterfaceMethod java/util/List.size:()I
      40: istore_3
      41: iconst_0
      42: istore        5
      44: iload_3
      45: istore        6
      47: iload         6
      49: anewarray     #73                 // class "[Ljava/lang/String;"
      52: astore        7
      54: iload         5
      56: iload         6
      58: if_icmpge     123
      61: iload         5
      63: istore        8
      65: aload         7
      67: iload         8
      69: iconst_0
      70: istore        9
      72: iload_3
      73: istore        10
      75: iload         10
      77: anewarray     #51                 // class java/lang/String
      80: astore        11
      82: istore        17
      84: astore        16
      86: iload         9
      88: iload         10
      90: if_icmpge     110
      93: iload         9
      95: istore        12
      97: aload         11
      99: iload         12
     101: ldc           #75                 // String
     103: aastore
     104: iinc          9, 1
     107: goto          86
     110: aload         16
     112: iload         17
     114: aload         11
     116: aastore
     117: iinc          5, 1
     120: goto          54
     123: aload         7
     125: astore        4
     127: iconst_0
     128: anewarray     #77                 // class kotlin/Pair
     131: astore        5
     133: iconst_0
     134: istore        6
     136: iload_3
     137: iconst_1
     138: isub
     139: istore        7
     141: iload         6
     143: iload         7
     145: if_icmpgt     296
     148: aload_2
     149: iload         6
     151: invokeinterface #81,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     156: checkcast     #49                 // class java/lang/CharSequence
     159: iconst_1
     160: anewarray     #51                 // class java/lang/String
     163: astore        9
     165: aload         9
     167: iconst_0
     168: ldc           #75                 // String
     170: aastore
     171: aload         9
     173: iconst_0
     174: iconst_0
     175: bipush        6
     177: aconst_null
     178: invokestatic  #59                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     181: checkcast     #83                 // class java/lang/Iterable
     184: iconst_1
     185: invokestatic  #87                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     188: iconst_1
     189: invokestatic  #65                 // Method kotlin/collections/CollectionsKt.dropLast:(Ljava/util/List;I)Ljava/util/List;
     192: astore        8
     194: iconst_0
     195: istore        9
     197: iload_3
     198: iconst_1
     199: isub
     200: istore        10
     202: iload         9
     204: iload         10
     206: if_icmpgt     283
     209: aload         8
     211: iload         9
     213: invokeinterface #81,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     218: checkcast     #51                 // class java/lang/String
     221: astore        11
     223: aload         4
     225: iload         6
     227: aaload
     228: iload         9
     230: aload         11
     232: aastore
     233: aload         11
     235: ldc           #89                 // String #
     237: invokestatic  #93                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     240: ifeq          270
     243: aload         5
     245: new           #77                 // class kotlin/Pair
     248: dup
     249: iload         9
     251: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     254: iload         6
     256: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     259: invokespecial #102                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     262: invokestatic  #108                // Method kotlin/collections/ArraysKt.plus:([Ljava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;
     265: checkcast     #110                // class "[Lkotlin/Pair;"
     268: astore        5
     270: iload         9
     272: iload         10
     274: if_icmpeq     283
     277: iinc          9, 1
     280: goto          209
     283: iload         6
     285: iload         7
     287: if_icmpeq     296
     290: iinc          6, 1
     293: goto          148
     296: lconst_0
     297: invokestatic  #115                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     300: dup
     301: ldc           #117                // String valueOf(...)
     303: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     306: astore        6
     308: aload         4
     310: iload_3
     311: invokestatic  #124                // Method getExpandLines:([[Ljava/lang/String;I)Lkotlin/Pair;
     314: astore        7
     316: aload         7
     318: invokevirtual #128                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     321: checkcast     #130                // class "[Ljava/lang/Integer;"
     324: astore        8
     326: aload         7
     328: invokevirtual #133                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     331: checkcast     #130                // class "[Ljava/lang/Integer;"
     334: astore        9
     336: iconst_0
     337: istore        10
     339: aload         5
     341: arraylength
     342: istore        11
     344: iload         10
     346: iload         11
     348: if_icmpgt     436
     351: iload         10
     353: iconst_1
     354: iadd
     355: istore        12
     357: aload         5
     359: arraylength
     360: iconst_1
     361: isub
     362: istore        13
     364: iload         12
     366: iload         13
     368: if_icmpgt     423
     371: aload         5
     373: iload         10
     375: aaload
     376: astore        14
     378: aload         5
     380: iload         12
     382: aaload
     383: astore        15
     385: aload         6
     387: aload         14
     389: aload         15
     391: aload         8
     393: aload         9
     395: iload_1
     396: invokestatic  #137                // Method getDist:(Lkotlin/Pair;Lkotlin/Pair;[Ljava/lang/Integer;[Ljava/lang/Integer;I)Ljava/math/BigInteger;
     399: invokevirtual #141                // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     402: dup
     403: ldc           #143                // String add(...)
     405: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     408: astore        6
     410: iload         12
     412: iload         13
     414: if_icmpeq     423
     417: iinc          12, 1
     420: goto          371
     423: iload         10
     425: iload         11
     427: if_icmpeq     436
     430: iinc          10, 1
     433: goto          351
     436: aload         6
     438: areturn

  public static final java.math.BigInteger getDist(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.lang.Integer[], java.lang.Integer[], int);
    Code:
       0: aload_0
       1: ldc           #167                // String p1
       3: invokestatic  #47                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #168                // String p2
       9: invokestatic  #47                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_2
      13: ldc           #169                // String xs
      15: invokestatic  #47                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload_3
      19: ldc           #170                // String ys
      21: invokestatic  #47                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      24: iconst_0
      25: istore        5
      27: aload_0
      28: invokevirtual #128                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      31: checkcast     #172                // class java/lang/Number
      34: invokevirtual #175                // Method java/lang/Number.intValue:()I
      37: istore        5
      39: iconst_0
      40: istore        6
      42: aload_0
      43: invokevirtual #133                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      46: checkcast     #172                // class java/lang/Number
      49: invokevirtual #175                // Method java/lang/Number.intValue:()I
      52: istore        6
      54: iconst_0
      55: istore        7
      57: aload_1
      58: invokevirtual #128                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      61: checkcast     #172                // class java/lang/Number
      64: invokevirtual #175                // Method java/lang/Number.intValue:()I
      67: istore        7
      69: iconst_0
      70: istore        8
      72: aload_1
      73: invokevirtual #133                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      76: checkcast     #172                // class java/lang/Number
      79: invokevirtual #175                // Method java/lang/Number.intValue:()I
      82: istore        8
      84: iload         7
      86: iload         5
      88: isub
      89: invokestatic  #181                // Method java/lang/Math.abs:(I)I
      92: iload         8
      94: iload         6
      96: isub
      97: invokestatic  #181                // Method java/lang/Math.abs:(I)I
     100: iadd
     101: istore        9
     103: iload         5
     105: iload         7
     107: if_icmpge     129
     110: iload         5
     112: istore        10
     114: iload         10
     116: istore        11
     118: iconst_0
     119: istore        12
     121: iload         7
     123: istore        5
     125: iload         10
     127: istore        7
     129: iload         6
     131: iload         8
     133: if_icmpge     155
     136: iload         6
     138: istore        10
     140: iload         10
     142: istore        11
     144: iconst_0
     145: istore        12
     147: iload         8
     149: istore        6
     151: iload         10
     153: istore        8
     155: iconst_0
     156: istore        10
     158: iload         7
     160: istore        11
     162: iload         5
     164: istore        12
     166: iload         11
     168: iload         12
     170: if_icmpgt     259
     173: aload_2
     174: astore        13
     176: iconst_0
     177: istore        14
     179: iconst_0
     180: istore        15
     182: aload         13
     184: arraylength
     185: istore        16
     187: iload         15
     189: iload         16
     191: if_icmpge     239
     194: aload         13
     196: iload         15
     198: aaload
     199: astore        17
     201: aload         17
     203: checkcast     #172                // class java/lang/Number
     206: invokevirtual #175                // Method java/lang/Number.intValue:()I
     209: istore        18
     211: iconst_0
     212: istore        19
     214: iload         18
     216: iload         11
     218: if_icmpne     225
     221: iconst_1
     222: goto          226
     225: iconst_0
     226: ifeq          233
     229: iconst_1
     230: goto          240
     233: iinc          15, 1
     236: goto          187
     239: iconst_0
     240: ifeq          246
     243: iinc          10, 1
     246: iload         11
     248: iload         12
     250: if_icmpeq     259
     253: iinc          11, 1
     256: goto          173
     259: iload         8
     261: istore        11
     263: iload         6
     265: istore        12
     267: iload         11
     269: iload         12
     271: if_icmpgt     360
     274: aload_3
     275: astore        13
     277: iconst_0
     278: istore        14
     280: iconst_0
     281: istore        15
     283: aload         13
     285: arraylength
     286: istore        16
     288: iload         15
     290: iload         16
     292: if_icmpge     340
     295: aload         13
     297: iload         15
     299: aaload
     300: astore        17
     302: aload         17
     304: checkcast     #172                // class java/lang/Number
     307: invokevirtual #175                // Method java/lang/Number.intValue:()I
     310: istore        18
     312: iconst_0
     313: istore        19
     315: iload         18
     317: iload         11
     319: if_icmpne     326
     322: iconst_1
     323: goto          327
     326: iconst_0
     327: ifeq          334
     330: iconst_1
     331: goto          341
     334: iinc          15, 1
     337: goto          288
     340: iconst_0
     341: ifeq          347
     344: iinc          10, 1
     347: iload         11
     349: iload         12
     351: if_icmpeq     360
     354: iinc          11, 1
     357: goto          274
     360: nop
     361: iload         9
     363: i2l
     364: invokestatic  #115                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     367: dup
     368: ldc           #117                // String valueOf(...)
     370: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     373: nop
     374: iload         10
     376: i2l
     377: invokestatic  #115                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     380: dup
     381: ldc           #117                // String valueOf(...)
     383: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     386: iload         4
     388: iconst_1
     389: isub
     390: i2l
     391: invokestatic  #115                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     394: dup
     395: ldc           #117                // String valueOf(...)
     397: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     400: invokevirtual #184                // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     403: dup
     404: ldc           #186                // String multiply(...)
     406: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     409: invokevirtual #141                // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     412: dup
     413: ldc           #143                // String add(...)
     415: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     418: areturn

  public static final kotlin.Pair<java.lang.Integer[], java.lang.Integer[]> getExpandLines(java.lang.String[][], int);
    Code:
       0: aload_0
       1: ldc           #207                // String map
       3: invokestatic  #47                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: anewarray     #95                 // class java/lang/Integer
      10: astore_2
      11: iconst_0
      12: istore_3
      13: iload_1
      14: iconst_1
      15: isub
      16: istore        4
      18: iload_3
      19: iload         4
      21: if_icmpgt     158
      24: iconst_0
      25: anewarray     #51                 // class java/lang/String
      28: astore        5
      30: iconst_0
      31: istore        6
      33: iload_1
      34: iconst_1
      35: isub
      36: istore        7
      38: iload         6
      40: iload         7
      42: if_icmpgt     74
      45: aload         5
      47: aload_0
      48: iload         6
      50: aaload
      51: iload_3
      52: aaload
      53: invokestatic  #108                // Method kotlin/collections/ArraysKt.plus:([Ljava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;
      56: checkcast     #73                 // class "[Ljava/lang/String;"
      59: astore        5
      61: iload         6
      63: iload         7
      65: if_icmpeq     74
      68: iinc          6, 1
      71: goto          45
      74: aload         5
      76: astore        6
      78: iconst_0
      79: istore        7
      81: iconst_0
      82: istore        8
      84: aload         6
      86: arraylength
      87: istore        9
      89: iload         8
      91: iload         9
      93: if_icmpge     130
      96: aload         6
      98: iload         8
     100: aaload
     101: astore        10
     103: aload         10
     105: astore        11
     107: iconst_0
     108: istore        12
     110: aload         11
     112: ldc           #209                // String .
     114: invokestatic  #93                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     117: ifne          124
     120: iconst_0
     121: goto          131
     124: iinc          8, 1
     127: goto          89
     130: iconst_1
     131: ifeq          146
     134: aload_2
     135: iload_3
     136: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     139: invokestatic  #108                // Method kotlin/collections/ArraysKt.plus:([Ljava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;
     142: checkcast     #130                // class "[Ljava/lang/Integer;"
     145: astore_2
     146: iload_3
     147: iload         4
     149: if_icmpeq     158
     152: iinc          3, 1
     155: goto          24
     158: iconst_0
     159: anewarray     #95                 // class java/lang/Integer
     162: astore_3
     163: iconst_0
     164: istore        4
     166: iload_1
     167: iconst_1
     168: isub
     169: istore        5
     171: iload         4
     173: iload         5
     175: if_icmpgt     274
     178: aload_0
     179: iload         4
     181: aaload
     182: astore        6
     184: iconst_0
     185: istore        7
     187: iconst_0
     188: istore        8
     190: aload         6
     192: arraylength
     193: istore        9
     195: iload         8
     197: iload         9
     199: if_icmpge     244
     202: aload         6
     204: iload         8
     206: aaload
     207: astore        10
     209: aload         10
     211: astore        11
     213: iconst_0
     214: istore        12
     216: aload         11
     218: ldc           #89                 // String #
     220: invokestatic  #93                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     223: ifne          230
     226: iconst_1
     227: goto          231
     230: iconst_0
     231: ifne          238
     234: iconst_0
     235: goto          245
     238: iinc          8, 1
     241: goto          195
     244: iconst_1
     245: ifeq          261
     248: aload_3
     249: iload         4
     251: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     254: invokestatic  #108                // Method kotlin/collections/ArraysKt.plus:([Ljava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;
     257: checkcast     #130                // class "[Ljava/lang/Integer;"
     260: astore_3
     261: iload         4
     263: iload         5
     265: if_icmpeq     274
     268: iinc          4, 1
     271: goto          178
     274: new           #77                 // class kotlin/Pair
     277: dup
     278: aload_2
     279: aload_3
     280: invokespecial #102                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     283: areturn

  public static final void pprint(java.lang.String[][]);
    Code:
       0: aload_0
       1: ldc           #207                // String map
       3: invokestatic  #47                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: checkcast     #217                // class "[Ljava/lang/Object;"
      12: arraylength
      13: istore_2
      14: iload_1
      15: iload_2
      16: if_icmpge     72
      19: aload_0
      20: iload_1
      21: aaload
      22: astore_3
      23: iconst_0
      24: istore        4
      26: aload_3
      27: arraylength
      28: istore        5
      30: iload         4
      32: iload         5
      34: if_icmpge     57
      37: aload_3
      38: iload         4
      40: aaload
      41: astore        6
      43: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      46: aload         6
      48: invokevirtual #220                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      51: iinc          4, 1
      54: goto          30
      57: ldc           #53                 // String \n
      59: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #220                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      66: iinc          1, 1
      69: goto          14
      72: return

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


data class Coordinate(val x: Int, val y: Int, val z: Int) {
    fun add(other: Coordinate) : Coordinate = Coordinate(x + other.x, y + other.y, z + other.z)

    fun subtract(other: Coordinate) : Coordinate = Coordinate(x - other.x, y - other.y, z - other.z)

    fun manhattanDistance(other: Coordinate) : Int = Math.abs(x - other.x) + Math.abs(y - other.y) + Math.abs(z - other.z)

    private fun getHeading(heading: Int) : Coordinate {
        when (heading) { // heading
            0 -> return Coordinate(x, y, z)
            1 -> return Coordinate(-y, x, z)
            2 -> return Coordinate(-x, -y, z)
            3 -> return Coordinate(y, -x, z)
            4 -> return Coordinate(-z, y, x)
            5 -> return Coordinate(z, y, -x)
            else -> throw Exception("Wut")
        }
    }

    private fun getRotation(rotation: Int) : Coordinate {
        when (rotation) { // rotation
            0 -> return Coordinate(x, y, z);
            1 -> return Coordinate(x, -z, y);
            2 -> return Coordinate(x, -y, -z);
            3 -> return Coordinate(x, z, -y);
            else -> throw Exception("Wut")
        }
    }

    fun transform(direction: Int) : Coordinate = getHeading(direction / 4).getRotation(direction % 4)
}

class Scanner() {
    var coordinates: MutableList<Coordinate> = mutableListOf<Coordinate>()
    var position: Coordinate = Coordinate(0, 0, 0)

    fun getRotatedCoordinates(rotation: Int, delta: Coordinate) : MutableList<Coordinate> =
        coordinates.map({ it.transform(rotation).subtract(delta) }).toMutableList()

    fun normalize(rotation: Int, delta: Coordinate) {
        coordinates = getRotatedCoordinates(rotation, delta)
        position = Coordinate(0, 0, 0).subtract(delta)
    }
}

class Program {
    var pendingLocation : MutableList<Scanner> = mutableListOf<Scanner>()
    var pendingCompare : MutableList<Scanner> = mutableListOf<Scanner>()
    var completed : MutableList<Scanner> = mutableListOf<Scanner>()

    fun load() {
        var first = true
        var current : Scanner = Scanner()
        pendingCompare.add(current)

        java.io.File("input.txt").forEachLine {
            if (it.startsWith("---")) {
                if (!first) {
                    current = Scanner()
                    pendingLocation.add(current)
                }
                first = false
            } else if (!it.isNullOrEmpty()) {
                val tokens = it.split(",")
                current.coordinates.add(Coordinate(tokens[0].toInt(), tokens[1].toInt(), tokens[2].toInt()))
            }
        }
    }

    fun iterate() {
        val first = pendingCompare[0]
        var i = 0
        while (i < pendingLocation.count()) {
            val second = pendingLocation[i]
            var found = false
            var fi = 0
            while (!found && fi < first.coordinates.count()) {
                val c1 = first.coordinates[fi++]

                var si = 0
                while (!found && si < second.coordinates.count()) {
                    val c2 = second.coordinates[si++]

                    for (rotation in 0..23) {
                        val tc2 = c2.transform(rotation)
                        val delta = tc2.subtract(c1)
                        var matchAttempt = second.getRotatedCoordinates(rotation, delta)

                        var result = first.coordinates.intersect(matchAttempt)
                        if (result.count() == 12) {
                            second.normalize(rotation, delta)
                            found = true
                        }
                    }
                }
            }
            if (found) {
                pendingLocation.removeAt(i)
                pendingCompare.add(second)
            } else {
                i++
            }
        }
        pendingCompare.removeAt(0)
        completed.add(first)
    }

    fun coordinateCount() : Int = completed.flatMap { it.coordinates }.distinct().count()

    fun maxDistance() : Int {
        var result = 0
        completed.forEach { first ->
            completed.forEach { second ->
                result = Math.max(result, first.position.manhattanDistance(second.position))
            }
        }
        return result
    }

    fun run() {
        load()
        while (pendingLocation.count() + pendingCompare.count() > 0) iterate()
        println("Part 1: ${coordinateCount()}")
        println("Part 2: ${maxDistance()}")
    }
}

fun main() = Program().run()

Compiled from "program.kt"
public final class ProgramKt {
  public static final void main();
    Code:
       0: new           #8                  // class Program
       3: dup
       4: invokespecial #11                 // Method Program."<init>":()V
       7: invokevirtual #14                 // Method Program.run:()V
      10: return

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

Compiled from "program.kt"
public final class Program {
  private java.util.List<Scanner> pendingLocation;

  private java.util.List<Scanner> pendingCompare;

  private java.util.List<Scanner> completed;

  public Program();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: new           #10                 // class java/util/ArrayList
       8: dup
       9: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      12: checkcast     #13                 // class java/util/List
      15: putfield      #17                 // Field pendingLocation:Ljava/util/List;
      18: aload_0
      19: new           #10                 // class java/util/ArrayList
      22: dup
      23: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      26: checkcast     #13                 // class java/util/List
      29: putfield      #20                 // Field pendingCompare:Ljava/util/List;
      32: aload_0
      33: new           #10                 // class java/util/ArrayList
      36: dup
      37: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      40: checkcast     #13                 // class java/util/List
      43: putfield      #23                 // Field completed:Ljava/util/List;
      46: return

  public final java.util.List<Scanner> getPendingLocation();
    Code:
       0: aload_0
       1: getfield      #17                 // Field pendingLocation:Ljava/util/List;
       4: areturn

  public final void setPendingLocation(java.util.List<Scanner>);
    Code:
       0: aload_1
       1: ldc           #34                 // String <set-?>
       3: invokestatic  #40                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: putfield      #17                 // Field pendingLocation:Ljava/util/List;
      11: return

  public final java.util.List<Scanner> getPendingCompare();
    Code:
       0: aload_0
       1: getfield      #20                 // Field pendingCompare:Ljava/util/List;
       4: areturn

  public final void setPendingCompare(java.util.List<Scanner>);
    Code:
       0: aload_1
       1: ldc           #34                 // String <set-?>
       3: invokestatic  #40                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: putfield      #20                 // Field pendingCompare:Ljava/util/List;
      11: return

  public final java.util.List<Scanner> getCompleted();
    Code:
       0: aload_0
       1: getfield      #23                 // Field completed:Ljava/util/List;
       4: areturn

  public final void setCompleted(java.util.List<Scanner>);
    Code:
       0: aload_1
       1: ldc           #34                 // String <set-?>
       3: invokestatic  #40                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: putfield      #23                 // Field completed:Ljava/util/List;
      11: return

  public final void load();
    Code:
       0: new           #47                 // class kotlin/jvm/internal/Ref$BooleanRef
       3: dup
       4: invokespecial #48                 // Method kotlin/jvm/internal/Ref$BooleanRef."<init>":()V
       7: astore_1
       8: aload_1
       9: iconst_1
      10: putfield      #52                 // Field kotlin/jvm/internal/Ref$BooleanRef.element:Z
      13: new           #54                 // class kotlin/jvm/internal/Ref$ObjectRef
      16: dup
      17: invokespecial #55                 // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
      20: astore_2
      21: aload_2
      22: new           #57                 // class Scanner
      25: dup
      26: invokespecial #58                 // Method Scanner."<init>":()V
      29: putfield      #61                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      32: aload_0
      33: getfield      #20                 // Field pendingCompare:Ljava/util/List;
      36: aload_2
      37: getfield      #61                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      40: invokeinterface #65,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      45: pop
      46: new           #67                 // class java/io/File
      49: dup
      50: ldc           #69                 // String input.txt
      52: invokespecial #72                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      55: aconst_null
      56: aload_1
      57: aload_2
      58: aload_0
      59: invokedynamic #92,  0             // InvokeDynamic #0:invoke:(Lkotlin/jvm/internal/Ref$BooleanRef;Lkotlin/jvm/internal/Ref$ObjectRef;LProgram;)Lkotlin/jvm/functions/Function1;
      64: iconst_1
      65: aconst_null
      66: invokestatic  #98                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      69: return

  public final void iterate();
    Code:
       0: aload_0
       1: getfield      #20                 // Field pendingCompare:Ljava/util/List;
       4: iconst_0
       5: invokeinterface #107,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      10: checkcast     #57                 // class Scanner
      13: astore_1
      14: iconst_0
      15: istore_2
      16: iload_2
      17: aload_0
      18: getfield      #17                 // Field pendingLocation:Ljava/util/List;
      21: checkcast     #109                // class java/util/Collection
      24: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
      29: if_icmpge     262
      32: aload_0
      33: getfield      #17                 // Field pendingLocation:Ljava/util/List;
      36: iload_2
      37: invokeinterface #107,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      42: checkcast     #57                 // class Scanner
      45: astore_3
      46: iconst_0
      47: istore        4
      49: iconst_0
      50: istore        5
      52: iload         4
      54: ifne          224
      57: iload         5
      59: aload_1
      60: invokevirtual #116                // Method Scanner.getCoordinates:()Ljava/util/List;
      63: checkcast     #109                // class java/util/Collection
      66: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
      71: if_icmpge     224
      74: aload_1
      75: invokevirtual #116                // Method Scanner.getCoordinates:()Ljava/util/List;
      78: iload         5
      80: iinc          5, 1
      83: invokeinterface #107,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      88: checkcast     #118                // class Coordinate
      91: astore        6
      93: iconst_0
      94: istore        7
      96: iload         4
      98: ifne          52
     101: iload         7
     103: aload_3
     104: invokevirtual #116                // Method Scanner.getCoordinates:()Ljava/util/List;
     107: checkcast     #109                // class java/util/Collection
     110: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
     115: if_icmpge     52
     118: aload_3
     119: invokevirtual #116                // Method Scanner.getCoordinates:()Ljava/util/List;
     122: iload         7
     124: iinc          7, 1
     127: invokeinterface #107,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     132: checkcast     #118                // class Coordinate
     135: astore        8
     137: iconst_0
     138: istore        9
     140: iload         9
     142: bipush        24
     144: if_icmpge     96
     147: aload         8
     149: iload         9
     151: invokevirtual #122                // Method Coordinate.transform:(I)LCoordinate;
     154: astore        10
     156: aload         10
     158: aload         6
     160: invokevirtual #126                // Method Coordinate.subtract:(LCoordinate;)LCoordinate;
     163: astore        11
     165: aload_3
     166: iload         9
     168: aload         11
     170: invokevirtual #130                // Method Scanner.getRotatedCoordinates:(ILCoordinate;)Ljava/util/List;
     173: astore        12
     175: aload_1
     176: invokevirtual #116                // Method Scanner.getCoordinates:()Ljava/util/List;
     179: checkcast     #132                // class java/lang/Iterable
     182: aload         12
     184: checkcast     #132                // class java/lang/Iterable
     187: invokestatic  #138                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     190: astore        13
     192: aload         13
     194: checkcast     #109                // class java/util/Collection
     197: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
     202: bipush        12
     204: if_icmpne     218
     207: aload_3
     208: iload         9
     210: aload         11
     212: invokevirtual #142                // Method Scanner.normalize:(ILCoordinate;)V
     215: iconst_1
     216: istore        4
     218: iinc          9, 1
     221: goto          140
     224: iload         4
     226: ifeq          254
     229: aload_0
     230: getfield      #17                 // Field pendingLocation:Ljava/util/List;
     233: iload_2
     234: invokeinterface #145,  2          // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
     239: pop
     240: aload_0
     241: getfield      #20                 // Field pendingCompare:Ljava/util/List;
     244: aload_3
     245: invokeinterface #65,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     250: pop
     251: goto          16
     254: iload_2
     255: iinc          2, 1
     258: pop
     259: goto          16
     262: aload_0
     263: getfield      #20                 // Field pendingCompare:Ljava/util/List;
     266: iconst_0
     267: invokeinterface #145,  2          // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
     272: pop
     273: aload_0
     274: getfield      #23                 // Field completed:Ljava/util/List;
     277: aload_1
     278: invokeinterface #65,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     283: pop
     284: return

  public final int coordinateCount();
    Code:
       0: aload_0
       1: getfield      #23                 // Field completed:Ljava/util/List;
       4: checkcast     #132                // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #10                 // class java/util/ArrayList
      15: dup
      16: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      19: checkcast     #109                // class java/util/Collection
      22: astore        4
      24: iconst_0
      25: istore        5
      27: aload_3
      28: invokeinterface #168,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        6
      35: aload         6
      37: invokeinterface #174,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          85
      45: aload         6
      47: invokeinterface #178,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        7
      54: aload         7
      56: checkcast     #57                 // class Scanner
      59: astore        8
      61: iconst_0
      62: istore        9
      64: aload         8
      66: invokevirtual #116                // Method Scanner.getCoordinates:()Ljava/util/List;
      69: checkcast     #132                // class java/lang/Iterable
      72: astore        8
      74: aload         4
      76: aload         8
      78: invokestatic  #182                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
      81: pop
      82: goto          35
      85: aload         4
      87: checkcast     #13                 // class java/util/List
      90: nop
      91: checkcast     #132                // class java/lang/Iterable
      94: invokestatic  #186                // Method kotlin/collections/CollectionsKt.distinct:(Ljava/lang/Iterable;)Ljava/util/List;
      97: checkcast     #109                // class java/util/Collection
     100: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
     105: ireturn

  public final int maxDistance();
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: getfield      #23                 // Field completed:Ljava/util/List;
       6: checkcast     #132                // class java/lang/Iterable
       9: astore_2
      10: iconst_0
      11: istore_3
      12: aload_2
      13: invokeinterface #168,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      18: astore        4
      20: aload         4
      22: invokeinterface #174,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      27: ifeq          128
      30: aload         4
      32: invokeinterface #178,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      37: astore        5
      39: aload         5
      41: checkcast     #57                 // class Scanner
      44: astore        6
      46: iconst_0
      47: istore        7
      49: aload_0
      50: getfield      #23                 // Field completed:Ljava/util/List;
      53: checkcast     #132                // class java/lang/Iterable
      56: astore        8
      58: iconst_0
      59: istore        9
      61: aload         8
      63: invokeinterface #168,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      68: astore        10
      70: aload         10
      72: invokeinterface #174,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      77: ifeq          122
      80: aload         10
      82: invokeinterface #178,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      87: astore        11
      89: aload         11
      91: checkcast     #57                 // class Scanner
      94: astore        12
      96: iconst_0
      97: istore        13
      99: iload_1
     100: aload         6
     102: invokevirtual #202                // Method Scanner.getPosition:()LCoordinate;
     105: aload         12
     107: invokevirtual #202                // Method Scanner.getPosition:()LCoordinate;
     110: invokevirtual #206                // Method Coordinate.manhattanDistance:(LCoordinate;)I
     113: invokestatic  #212                // Method java/lang/Math.max:(II)I
     116: istore_1
     117: nop
     118: nop
     119: goto          70
     122: nop
     123: nop
     124: nop
     125: goto          20
     128: nop
     129: iload_1
     130: ireturn

  public final void run();
    Code:
       0: aload_0
       1: invokevirtual #220                // Method load:()V
       4: aload_0
       5: getfield      #17                 // Field pendingLocation:Ljava/util/List;
       8: checkcast     #109                // class java/util/Collection
      11: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
      16: aload_0
      17: getfield      #20                 // Field pendingCompare:Ljava/util/List;
      20: checkcast     #109                // class java/util/Collection
      23: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
      28: iadd
      29: ifle          39
      32: aload_0
      33: invokevirtual #222                // Method iterate:()V
      36: goto          4
      39: new           #224                // class java/lang/StringBuilder
      42: dup
      43: invokespecial #225                // Method java/lang/StringBuilder."<init>":()V
      46: ldc           #227                // String Part 1:
      48: invokevirtual #231                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      51: aload_0
      52: invokevirtual #233                // Method coordinateCount:()I
      55: invokevirtual #236                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      58: invokevirtual #240                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      61: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
      64: swap
      65: invokevirtual #252                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      68: new           #224                // class java/lang/StringBuilder
      71: dup
      72: invokespecial #225                // Method java/lang/StringBuilder."<init>":()V
      75: ldc           #254                // String Part 2:
      77: invokevirtual #231                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      80: aload_0
      81: invokevirtual #256                // Method maxDistance:()I
      84: invokevirtual #236                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      87: invokevirtual #240                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      90: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
      93: swap
      94: invokevirtual #252                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      97: return

  private static final kotlin.Unit load$lambda$0(kotlin.jvm.internal.Ref$BooleanRef, kotlin.jvm.internal.Ref$ObjectRef, Program, java.lang.String);
    Code:
       0: aload_3
       1: ldc_w         #257                // String it
       4: invokestatic  #40                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_3
       8: ldc_w         #259                // String ---
      11: iconst_0
      12: iconst_2
      13: aconst_null
      14: invokestatic  #265                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      17: ifeq          60
      20: aload_0
      21: getfield      #52                 // Field kotlin/jvm/internal/Ref$BooleanRef.element:Z
      24: ifne          52
      27: aload_1
      28: new           #57                 // class Scanner
      31: dup
      32: invokespecial #58                 // Method Scanner."<init>":()V
      35: putfield      #61                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      38: aload_2
      39: getfield      #17                 // Field pendingLocation:Ljava/util/List;
      42: aload_1
      43: getfield      #61                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      46: invokeinterface #65,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      51: pop
      52: aload_0
      53: iconst_0
      54: putfield      #52                 // Field kotlin/jvm/internal/Ref$BooleanRef.element:Z
      57: goto          174
      60: aload_3
      61: checkcast     #267                // class java/lang/CharSequence
      64: invokeinterface #270,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      69: ifne          76
      72: iconst_1
      73: goto          77
      76: iconst_0
      77: ifne          174
      80: aload_3
      81: checkcast     #267                // class java/lang/CharSequence
      84: iconst_1
      85: anewarray     #272                // class java/lang/String
      88: astore        5
      90: aload         5
      92: iconst_0
      93: ldc_w         #274                // String ,
      96: aastore
      97: aload         5
      99: iconst_0
     100: iconst_0
     101: bipush        6
     103: aconst_null
     104: invokestatic  #278                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     107: astore        4
     109: aload_1
     110: getfield      #61                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     113: checkcast     #57                 // class Scanner
     116: invokevirtual #116                // Method Scanner.getCoordinates:()Ljava/util/List;
     119: new           #118                // class Coordinate
     122: dup
     123: aload         4
     125: iconst_0
     126: invokeinterface #107,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     131: checkcast     #272                // class java/lang/String
     134: invokestatic  #284                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     137: aload         4
     139: iconst_1
     140: invokeinterface #107,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     145: checkcast     #272                // class java/lang/String
     148: invokestatic  #284                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     151: aload         4
     153: iconst_2
     154: invokeinterface #107,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     159: checkcast     #272                // class java/lang/String
     162: invokestatic  #284                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     165: invokespecial #287                // Method Coordinate."<init>":(III)V
     168: invokeinterface #65,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     173: pop
     174: getstatic     #293                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     177: areturn
}


import kotlin.math.pow
import kotlin.math.round

fun fib(n: Int): Int {
  return if (n < 2) n else fib(n - 1) + fib(n - 2)
}

fun fibLinear(n: Int): Int {
  var prevFib = 0
  var fib = 1

  repeat(n) {
    val temp = prevFib + fib
    prevFib = fib
    fib = temp
  }
  return prevFib
}

fun fibFormula(n: Int): Int {
  return round((((5.0.pow(0.5) + 1) / 2.0).pow(n)) / 5.0.pow(0.5)).toInt();
}

fun fibTailRecursive(n: Int, prevFib: Int = 0, fib: Int = 1): Int {
  return if (n == 0) prevFib else fibTailRecursive(n - 1, fib, prevFib + fib)
}

fun fibonacciGenerate(n: Int): List<Int> {
  var a = 0
  var b = 1

  fun next(): Int {
      val result = a + b
      a = b
      b = result
      return a
  }
  return generateSequence(::next).take(n).toList()
}

fun main(args: Array<String>) {
  var input = if (args.size > 0) args[0].toInt() else 29
  println(fibLinear(input))
}

Compiled from "fib.kt"
public final class FibKt {
  public static final int fib(int);
    Code:
       0: iload_0
       1: iconst_2
       2: if_icmpge     9
       5: iload_0
       6: goto          22
       9: iload_0
      10: iconst_1
      11: isub
      12: invokestatic  #8                  // Method fib:(I)I
      15: iload_0
      16: iconst_2
      17: isub
      18: invokestatic  #8                  // Method fib:(I)I
      21: iadd
      22: ireturn

  public static final int fibLinear(int);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_0
       3: istore_2
       4: iconst_1
       5: istore_2
       6: iconst_0
       7: istore_3
       8: iload_3
       9: iload_0
      10: if_icmpge     36
      13: iload_3
      14: istore        4
      16: iconst_0
      17: istore        5
      19: iload_1
      20: iload_2
      21: iadd
      22: istore        6
      24: iload_2
      25: istore_1
      26: iload         6
      28: istore_2
      29: nop
      30: iinc          3, 1
      33: goto          8
      36: iload_1
      37: ireturn

  public static final int fibFormula(int);
    Code:
       0: ldc2_w        #17                 // double 5.0d
       3: ldc2_w        #19                 // double 0.5d
       6: invokestatic  #26                 // Method java/lang/Math.pow:(DD)D
       9: iconst_1
      10: i2d
      11: dadd
      12: ldc2_w        #27                 // double 2.0d
      15: ddiv
      16: iload_0
      17: i2d
      18: invokestatic  #26                 // Method java/lang/Math.pow:(DD)D
      21: ldc2_w        #17                 // double 5.0d
      24: ldc2_w        #19                 // double 0.5d
      27: invokestatic  #26                 // Method java/lang/Math.pow:(DD)D
      30: ddiv
      31: invokestatic  #32                 // Method java/lang/Math.rint:(D)D
      34: d2i
      35: ireturn

  public static final int fibTailRecursive(int, int, int);
    Code:
       0: iload_0
       1: ifne          8
       4: iload_1
       5: goto          18
       8: iload_0
       9: iconst_1
      10: isub
      11: iload_2
      12: iload_1
      13: iload_2
      14: iadd
      15: invokestatic  #36                 // Method fibTailRecursive:(III)I
      18: ireturn

  public static int fibTailRecursive$default(int, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_1
       8: iload_3
       9: iconst_4
      10: iand
      11: ifeq          16
      14: iconst_1
      15: istore_2
      16: iload_0
      17: iload_1
      18: iload_2
      19: invokestatic  #36                 // Method fibTailRecursive:(III)I
      22: ireturn

  public static final java.util.List<java.lang.Integer> fibonacciGenerate(int);
    Code:
       0: new           #44                 // class kotlin/jvm/internal/Ref$IntRef
       3: dup
       4: invokespecial #48                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
       7: astore_1
       8: new           #44                 // class kotlin/jvm/internal/Ref$IntRef
      11: dup
      12: invokespecial #48                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      15: astore_2
      16: aload_2
      17: iconst_1
      18: putfield      #51                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      21: new           #53                 // class FibKt$fibonacciGenerate$1
      24: dup
      25: aload_1
      26: aload_2
      27: invokespecial #56                 // Method FibKt$fibonacciGenerate$1."<init>":(Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;)V
      30: checkcast     #58                 // class kotlin/jvm/functions/Function0
      33: invokestatic  #64                 // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
      36: iload_0
      37: invokestatic  #68                 // Method kotlin/sequences/SequencesKt.take:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
      40: invokestatic  #72                 // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      43: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #79                 // String args
       3: invokestatic  #85                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: arraylength
       8: ifle          20
      11: aload_0
      12: iconst_0
      13: aaload
      14: invokestatic  #91                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      17: goto          22
      20: bipush        29
      22: istore_1
      23: iload_1
      24: invokestatic  #93                 // Method fibLinear:(I)I
      27: istore_2
      28: getstatic     #99                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: iload_2
      32: invokevirtual #105                // Method java/io/PrintStream.println:(I)V
      35: return

  private static final int fibonacciGenerate$next(kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef);
    Code:
       0: aload_0
       1: getfield      #51                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
       4: aload_1
       5: getfield      #51                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
       8: iadd
       9: istore_2
      10: aload_0
      11: aload_1
      12: getfield      #51                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      15: putfield      #51                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      18: aload_1
      19: iload_2
      20: putfield      #51                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      23: aload_0
      24: getfield      #51                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      27: ireturn

  public static final int access$fibonacciGenerate$next(kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #113                // Method fibonacciGenerate$next:(Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;)I
       5: ireturn
}

Compiled from "fib.kt"
final class FibKt$fibonacciGenerate$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function0<java.lang.Integer> {
  final kotlin.jvm.internal.Ref$IntRef $a;

  final kotlin.jvm.internal.Ref$IntRef $b;

  FibKt$fibonacciGenerate$1(kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #13                 // Field $a:Lkotlin/jvm/internal/Ref$IntRef;
       5: aload_0
       6: aload_2
       7: putfield      #16                 // Field $b:Lkotlin/jvm/internal/Ref$IntRef;
      10: aload_0
      11: iconst_0
      12: ldc           #18                 // class kotlin/jvm/internal/Intrinsics$Kotlin
      14: ldc           #20                 // String next
      16: ldc           #22                 // String fibonacciGenerate$next(Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;)I
      18: iconst_0
      19: invokespecial #25                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      22: return

  public final java.lang.Integer invoke();
    Code:
       0: aload_0
       1: getfield      #13                 // Field $a:Lkotlin/jvm/internal/Ref$IntRef;
       4: aload_0
       5: getfield      #16                 // Field $b:Lkotlin/jvm/internal/Ref$IntRef;
       8: invokestatic  #35                 // Method FibKt.access$fibonacciGenerate$next:(Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;)I
      11: invokestatic  #41                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      14: areturn

  public java.lang.Object invoke();
    Code:
       0: aload_0
       1: invokevirtual #44                 // Method invoke:()Ljava/lang/Integer;
       4: areturn
}