Lank891__Advent-of-Code-2021__4164b70/Day 05 - Kotlin/source.kt

import java.io.File
import kotlin.math.sign

const val boardSize: Int = 1000;

typealias XY = Pair<Int, Int>;
typealias VentPath = Pair<XY, XY>;
typealias Board = Array<Array<Int>>

fun ventPathToString(path: VentPath): String {
    return "Path (${path.first.first}, ${path.first.second}) -> (${path.second.first}, ${path.second.second})"
}

fun printBoard(board: Board) {
    for(y in 0 until boardSize){
        for(x in 0 until boardSize) {
            print("${if (board[x][y] == 0) '.' else board[x][y]} ");
        }
        println();
    }
}

fun isVentPathOblique(path: VentPath): Boolean {
    return path.first.first != path.second.first && path.first.second != path.second.second;
}

fun commaSeparatedNumbersToXY(numbers: String): XY {
    val split: List<Int> = numbers.split(",").map{ str: String -> str.toInt()}
    return Pair(split[0], split[1]);
}

fun inputLineToVentPath(line: String): VentPath {
    val splits: List<String>     = line.split("->").map{ str: String -> str.trim()};
    return Pair(commaSeparatedNumbersToXY(splits[0]), commaSeparatedNumbersToXY(splits[1]));
}

fun addNotObliqueVent(board: Board, path: VentPath) {
    fun getXRange(path: VentPath): IntProgression {
        return if(path.first.first < path.second.first){
            (path.second.first downTo path.first.first)
        } else {
            (path.first.first downTo path.second.first)
        }
    }

    fun getYRange(path: VentPath): IntProgression {
        return if(path.first.second < path.second.second){
            (path.second.second downTo path.first.second)
        } else {
            (path.first.second downTo path.second.second)
        }
    }

    for(x in getXRange(path)) {
        for(y in getYRange(path)) {
            board[x][y]++;
        }
    }
}

fun addObliqueVent(board: Board, path: VentPath) {
    val (left: XY, right: XY) = if (path.first.first < path.second.first) Pair(path.first, path.second) else Pair(path.second, path.first);

    var yVal: Int = left.second;
    val yDiff: Int = -sign((left.second - right.second).toDouble()).toInt();

    for(x in left.first..right.first) {
        board[x][yVal] += 1;
        yVal += yDiff;
    }
}

fun getOverlappedCells(board: Board): Int {
    var sum: Int = 0;
    for(column in board) {
        for(cell in column) {
            if(cell > 1) {
                sum++;
            }
        }
    }
    return sum;
}

fun main(args: Array<String>) {
    val vents: List<VentPath> = File("./input.txt").readLines().map{ str: String -> inputLineToVentPath(str)};
    val (obliqueVents: List<VentPath>, notObliqueVents: List<VentPath>) = vents.partition { vent: VentPath -> isVentPathOblique(vent) };

    /*
    println("---   OBLIQUE VENTS   ---")
    obliqueVents.forEach { vent: VentPath -> println(ventPathToString(vent))};

    println("--- NOT OBLIQUE VENTS ---")
    notObliqueVents.forEach { vent: VentPath -> println(ventPathToString(vent))};
    */

    val board: Board = Array(boardSize) { _ -> Array(boardSize) { _ -> 0 } };

    // Part 1
    notObliqueVents.forEach { vent: VentPath -> addNotObliqueVent(board, vent) };
    println("Part 1 overlapped cells: ${getOverlappedCells(board)}");

    //printBoard(board);

    // Part 2
    obliqueVents.forEach { vent: VentPath -> addObliqueVent(board, vent) };
    println("Part 2 overlapped cells: ${getOverlappedCells(board)}");

    //printBoard(board);
}

Compiled from "source.kt"
public final class SourceKt {
  public static final int boardSize;

  public static final java.lang.String ventPathToString(kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #10                 // String path
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #22                 // Method java/lang/StringBuilder."<init>":()V
      13: ldc           #24                 // String Path (
      15: invokevirtual #28                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      18: aload_0
      19: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      22: checkcast     #30                 // class kotlin/Pair
      25: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      28: checkcast     #36                 // class java/lang/Number
      31: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      34: invokevirtual #43                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      37: ldc           #45                 // String ,
      39: invokevirtual #28                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: aload_0
      43: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      46: checkcast     #30                 // class kotlin/Pair
      49: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      52: checkcast     #36                 // class java/lang/Number
      55: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      58: invokevirtual #43                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      61: ldc           #50                 // String ) -> (
      63: invokevirtual #28                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      66: aload_0
      67: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      70: checkcast     #30                 // class kotlin/Pair
      73: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      76: checkcast     #36                 // class java/lang/Number
      79: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      82: invokevirtual #43                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      85: ldc           #45                 // String ,
      87: invokevirtual #28                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      90: aload_0
      91: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      94: checkcast     #30                 // class kotlin/Pair
      97: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     100: checkcast     #36                 // class java/lang/Number
     103: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     106: invokevirtual #43                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     109: bipush        41
     111: invokevirtual #53                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     114: invokevirtual #57                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     117: areturn

  public static final void printBoard(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc           #62                 // String board
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: iload_1
       9: sipush        1000
      12: if_icmpge     91
      15: iconst_0
      16: istore_2
      17: iload_2
      18: sipush        1000
      21: if_icmpge     79
      24: new           #18                 // class java/lang/StringBuilder
      27: dup
      28: invokespecial #22                 // Method java/lang/StringBuilder."<init>":()V
      31: aload_0
      32: iload_2
      33: aaload
      34: iload_1
      35: aaload
      36: invokevirtual #65                 // Method java/lang/Integer.intValue:()I
      39: ifne          50
      42: bipush        46
      44: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      47: goto          55
      50: aload_0
      51: iload_2
      52: aaload
      53: iload_1
      54: aaload
      55: invokevirtual #74                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      58: bipush        32
      60: invokevirtual #53                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      63: invokevirtual #57                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      66: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: swap
      70: invokevirtual #86                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      73: iinc          2, 1
      76: goto          17
      79: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
      82: invokevirtual #89                 // Method java/io/PrintStream.println:()V
      85: iinc          1, 1
      88: goto          8
      91: return

  public static final boolean isVentPathOblique(kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #10                 // String path
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      10: checkcast     #30                 // class kotlin/Pair
      13: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      16: checkcast     #36                 // class java/lang/Number
      19: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      22: aload_0
      23: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      26: checkcast     #30                 // class kotlin/Pair
      29: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      32: checkcast     #36                 // class java/lang/Number
      35: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      38: if_icmpeq     80
      41: aload_0
      42: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      45: checkcast     #30                 // class kotlin/Pair
      48: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      51: checkcast     #36                 // class java/lang/Number
      54: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      57: aload_0
      58: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      61: checkcast     #30                 // class kotlin/Pair
      64: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      67: checkcast     #36                 // class java/lang/Number
      70: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      73: if_icmpeq     80
      76: iconst_1
      77: goto          81
      80: iconst_0
      81: ireturn

  public static final kotlin.Pair<java.lang.Integer, java.lang.Integer> commaSeparatedNumbersToXY(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #102                // String numbers
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #104                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #106                // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #108                // String ,
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #114                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #116                // class java/lang/Iterable
      32: astore_2
      33: iconst_0
      34: istore_3
      35: aload_2
      36: astore        4
      38: new           #118                // class java/util/ArrayList
      41: dup
      42: aload_2
      43: bipush        10
      45: invokestatic  #124                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      48: invokespecial #127                // Method java/util/ArrayList."<init>":(I)V
      51: checkcast     #129                // class java/util/Collection
      54: astore        5
      56: iconst_0
      57: istore        6
      59: aload         4
      61: invokeinterface #133,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      66: astore        7
      68: aload         7
      70: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      75: ifeq          122
      78: aload         7
      80: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      85: astore        8
      87: aload         5
      89: aload         8
      91: checkcast     #106                // class java/lang/String
      94: astore        9
      96: astore        11
      98: iconst_0
      99: istore        10
     101: aload         9
     103: invokestatic  #146                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     106: nop
     107: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     110: aload         11
     112: swap
     113: invokeinterface #153,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     118: pop
     119: goto          68
     122: aload         5
     124: checkcast     #155                // class java/util/List
     127: nop
     128: astore_1
     129: new           #30                 // class kotlin/Pair
     132: dup
     133: aload_1
     134: iconst_0
     135: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     140: aload_1
     141: iconst_1
     142: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     147: invokespecial #162                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     150: areturn

  public static final kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>> inputLineToVentPath(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #180                // String line
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #104                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #106                // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #182                // String ->
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #114                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #116                // class java/lang/Iterable
      32: astore_2
      33: iconst_0
      34: istore_3
      35: aload_2
      36: astore        4
      38: new           #118                // class java/util/ArrayList
      41: dup
      42: aload_2
      43: bipush        10
      45: invokestatic  #124                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      48: invokespecial #127                // Method java/util/ArrayList."<init>":(I)V
      51: checkcast     #129                // class java/util/Collection
      54: astore        5
      56: iconst_0
      57: istore        6
      59: aload         4
      61: invokeinterface #133,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      66: astore        7
      68: aload         7
      70: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      75: ifeq          125
      78: aload         7
      80: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      85: astore        8
      87: aload         5
      89: aload         8
      91: checkcast     #106                // class java/lang/String
      94: astore        9
      96: astore        11
      98: iconst_0
      99: istore        10
     101: aload         9
     103: checkcast     #104                // class java/lang/CharSequence
     106: invokestatic  #186                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     109: invokevirtual #187                // Method java/lang/Object.toString:()Ljava/lang/String;
     112: nop
     113: aload         11
     115: swap
     116: invokeinterface #153,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          68
     125: aload         5
     127: checkcast     #155                // class java/util/List
     130: nop
     131: astore_1
     132: new           #30                 // class kotlin/Pair
     135: dup
     136: aload_1
     137: iconst_0
     138: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     143: checkcast     #106                // class java/lang/String
     146: invokestatic  #189                // Method commaSeparatedNumbersToXY:(Ljava/lang/String;)Lkotlin/Pair;
     149: aload_1
     150: iconst_1
     151: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     156: checkcast     #106                // class java/lang/String
     159: invokestatic  #189                // Method commaSeparatedNumbersToXY:(Ljava/lang/String;)Lkotlin/Pair;
     162: invokespecial #162                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     165: areturn

  public static final void addNotObliqueVent(java.lang.Integer[][], kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #62                 // String board
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #10                 // String path
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokestatic  #198                // Method addNotObliqueVent$getXRange:(Lkotlin/Pair;)Lkotlin/ranges/IntProgression;
      16: astore_2
      17: aload_2
      18: invokevirtual #202                // Method kotlin/ranges/IntProgression.getFirst:()I
      21: istore_3
      22: aload_2
      23: invokevirtual #205                // Method kotlin/ranges/IntProgression.getLast:()I
      26: istore        4
      28: aload_2
      29: invokevirtual #208                // Method kotlin/ranges/IntProgression.getStep:()I
      32: istore        5
      34: iload         5
      36: ifle          45
      39: iload_3
      40: iload         4
      42: if_icmple     56
      45: iload         5
      47: ifge          169
      50: iload         4
      52: iload_3
      53: if_icmpgt     169
      56: aload_1
      57: invokestatic  #211                // Method addNotObliqueVent$getYRange:(Lkotlin/Pair;)Lkotlin/ranges/IntProgression;
      60: astore        6
      62: aload         6
      64: invokevirtual #202                // Method kotlin/ranges/IntProgression.getFirst:()I
      67: istore        7
      69: aload         6
      71: invokevirtual #205                // Method kotlin/ranges/IntProgression.getLast:()I
      74: istore        8
      76: aload         6
      78: invokevirtual #208                // Method kotlin/ranges/IntProgression.getStep:()I
      81: istore        9
      83: iload         9
      85: ifle          95
      88: iload         7
      90: iload         8
      92: if_icmple     107
      95: iload         9
      97: ifge          155
     100: iload         8
     102: iload         7
     104: if_icmpgt     155
     107: aload_0
     108: iload_3
     109: aaload
     110: astore        10
     112: iload         7
     114: istore        11
     116: aload         10
     118: iload         11
     120: aaload
     121: invokevirtual #65                 // Method java/lang/Integer.intValue:()I
     124: istore        12
     126: aload         10
     128: iload         11
     130: iload         12
     132: iconst_1
     133: iadd
     134: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     137: aastore
     138: iload         7
     140: iload         8
     142: if_icmpeq     155
     145: iload         7
     147: iload         9
     149: iadd
     150: istore        7
     152: goto          107
     155: iload_3
     156: iload         4
     158: if_icmpeq     169
     161: iload_3
     162: iload         5
     164: iadd
     165: istore_3
     166: goto          56
     169: return

  public static final void addObliqueVent(java.lang.Integer[][], kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #62                 // String board
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #10                 // String path
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      16: checkcast     #30                 // class kotlin/Pair
      19: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      22: checkcast     #36                 // class java/lang/Number
      25: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      28: aload_1
      29: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      32: checkcast     #30                 // class kotlin/Pair
      35: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      38: checkcast     #36                 // class java/lang/Number
      41: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      44: if_icmpge     65
      47: new           #30                 // class kotlin/Pair
      50: dup
      51: aload_1
      52: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      55: aload_1
      56: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      59: invokespecial #162                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      62: goto          80
      65: new           #30                 // class kotlin/Pair
      68: dup
      69: aload_1
      70: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      73: aload_1
      74: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      77: invokespecial #162                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      80: astore_2
      81: aload_2
      82: invokevirtual #215                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      85: checkcast     #30                 // class kotlin/Pair
      88: astore_3
      89: aload_2
      90: invokevirtual #218                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      93: checkcast     #30                 // class kotlin/Pair
      96: astore        4
      98: aload_3
      99: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     102: checkcast     #36                 // class java/lang/Number
     105: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     108: istore        5
     110: aload_3
     111: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     114: checkcast     #36                 // class java/lang/Number
     117: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     120: aload         4
     122: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     125: checkcast     #36                 // class java/lang/Number
     128: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     131: isub
     132: i2d
     133: invokestatic  #224                // Method java/lang/Math.signum:(D)D
     136: d2i
     137: ineg
     138: istore        6
     140: aload_3
     141: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     144: checkcast     #36                 // class java/lang/Number
     147: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     150: istore        7
     152: aload         4
     154: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     157: checkcast     #36                 // class java/lang/Number
     160: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     163: istore        8
     165: iload         7
     167: iload         8
     169: if_icmpgt     220
     172: aload_0
     173: iload         7
     175: aaload
     176: astore        9
     178: iload         5
     180: istore        10
     182: aload         9
     184: iload         10
     186: aload         9
     188: iload         10
     190: aaload
     191: invokevirtual #65                 // Method java/lang/Integer.intValue:()I
     194: iconst_1
     195: iadd
     196: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     199: aastore
     200: iload         5
     202: iload         6
     204: iadd
     205: istore        5
     207: iload         7
     209: iload         8
     211: if_icmpeq     220
     214: iinc          7, 1
     217: goto          172
     220: return

  public static final int getOverlappedCells(java.lang.Integer[][]);
    Code:
       0: aload_0
       1: ldc           #62                 // String board
       3: invokestatic  #16                 // 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     #232                // 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 #65                 // Method java/lang/Integer.intValue:()I
      49: istore        7
      51: iload         7
      53: iconst_1
      54: if_icmple     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 final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #241                // String args
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #243                // class java/io/File
       9: dup
      10: ldc           #245                // String ./input.txt
      12: invokespecial #248                // Method java/io/File."<init>":(Ljava/lang/String;)V
      15: aconst_null
      16: iconst_1
      17: aconst_null
      18: invokestatic  #254                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      21: checkcast     #116                // class java/lang/Iterable
      24: astore_2
      25: iconst_0
      26: istore_3
      27: aload_2
      28: astore        4
      30: new           #118                // class java/util/ArrayList
      33: dup
      34: aload_2
      35: bipush        10
      37: invokestatic  #124                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      40: invokespecial #127                // Method java/util/ArrayList."<init>":(I)V
      43: checkcast     #129                // class java/util/Collection
      46: astore        5
      48: iconst_0
      49: istore        6
      51: aload         4
      53: invokeinterface #133,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        7
      60: aload         7
      62: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          110
      70: aload         7
      72: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        8
      79: aload         5
      81: aload         8
      83: checkcast     #106                // class java/lang/String
      86: astore        9
      88: astore        12
      90: iconst_0
      91: istore        10
      93: aload         9
      95: invokestatic  #256                // Method inputLineToVentPath:(Ljava/lang/String;)Lkotlin/Pair;
      98: aload         12
     100: swap
     101: invokeinterface #153,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     106: pop
     107: goto          60
     110: aload         5
     112: checkcast     #155                // class java/util/List
     115: nop
     116: astore_1
     117: aload_1
     118: checkcast     #116                // class java/lang/Iterable
     121: astore_3
     122: iconst_0
     123: istore        4
     125: new           #118                // class java/util/ArrayList
     128: dup
     129: invokespecial #257                // Method java/util/ArrayList."<init>":()V
     132: astore        5
     134: new           #118                // class java/util/ArrayList
     137: dup
     138: invokespecial #257                // Method java/util/ArrayList."<init>":()V
     141: astore        6
     143: aload_3
     144: invokeinterface #133,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     149: astore        7
     151: aload         7
     153: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     158: ifeq          209
     161: aload         7
     163: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     168: astore        8
     170: aload         8
     172: checkcast     #30                 // class kotlin/Pair
     175: astore        9
     177: iconst_0
     178: istore        10
     180: aload         9
     182: invokestatic  #259                // Method isVentPathOblique:(Lkotlin/Pair;)Z
     185: ifeq          198
     188: aload         5
     190: aload         8
     192: invokevirtual #260                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     195: goto          205
     198: aload         6
     200: aload         8
     202: invokevirtual #260                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     205: pop
     206: goto          151
     209: new           #30                 // class kotlin/Pair
     212: dup
     213: aload         5
     215: aload         6
     217: invokespecial #162                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     220: astore_2
     221: aload_2
     222: invokevirtual #215                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     225: checkcast     #155                // class java/util/List
     228: astore_3
     229: aload_2
     230: invokevirtual #218                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     233: checkcast     #155                // class java/util/List
     236: astore        4
     238: iconst_0
     239: istore        6
     241: sipush        1000
     244: anewarray     #237                // class "[Ljava/lang/Integer;"
     247: astore        7
     249: iload         6
     251: sipush        1000
     254: if_icmpge     320
     257: iload         6
     259: istore        8
     261: aload         7
     263: iload         8
     265: iconst_0
     266: istore        9
     268: sipush        1000
     271: anewarray     #64                 // class java/lang/Integer
     274: astore        10
     276: istore        13
     278: astore        12
     280: iload         9
     282: sipush        1000
     285: if_icmpge     307
     288: iload         9
     290: istore        11
     292: aload         10
     294: iload         11
     296: iconst_0
     297: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     300: aastore
     301: iinc          9, 1
     304: goto          280
     307: aload         12
     309: iload         13
     311: aload         10
     313: aastore
     314: iinc          6, 1
     317: goto          249
     320: aload         7
     322: astore        5
     324: aload         4
     326: checkcast     #116                // class java/lang/Iterable
     329: astore        6
     331: iconst_0
     332: istore        7
     334: aload         6
     336: invokeinterface #133,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     341: astore        8
     343: aload         8
     345: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     350: ifeq          383
     353: aload         8
     355: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     360: astore        9
     362: aload         9
     364: checkcast     #30                 // class kotlin/Pair
     367: astore        10
     369: iconst_0
     370: istore        11
     372: aload         5
     374: aload         10
     376: invokestatic  #262                // Method addNotObliqueVent:([[Ljava/lang/Integer;Lkotlin/Pair;)V
     379: nop
     380: goto          343
     383: nop
     384: new           #18                 // class java/lang/StringBuilder
     387: dup
     388: invokespecial #22                 // Method java/lang/StringBuilder."<init>":()V
     391: ldc_w         #264                // String Part 1 overlapped cells:
     394: invokevirtual #28                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     397: aload         5
     399: invokestatic  #266                // Method getOverlappedCells:([[Ljava/lang/Integer;)I
     402: invokevirtual #43                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     405: invokevirtual #57                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     408: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     411: swap
     412: invokevirtual #268                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     415: aload_3
     416: checkcast     #116                // class java/lang/Iterable
     419: astore        6
     421: iconst_0
     422: istore        7
     424: aload         6
     426: invokeinterface #133,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     431: astore        8
     433: aload         8
     435: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     440: ifeq          473
     443: aload         8
     445: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     450: astore        9
     452: aload         9
     454: checkcast     #30                 // class kotlin/Pair
     457: astore        10
     459: iconst_0
     460: istore        11
     462: aload         5
     464: aload         10
     466: invokestatic  #270                // Method addObliqueVent:([[Ljava/lang/Integer;Lkotlin/Pair;)V
     469: nop
     470: goto          433
     473: nop
     474: new           #18                 // class java/lang/StringBuilder
     477: dup
     478: invokespecial #22                 // Method java/lang/StringBuilder."<init>":()V
     481: ldc_w         #272                // String Part 2 overlapped cells:
     484: invokevirtual #28                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     487: aload         5
     489: invokestatic  #266                // Method getOverlappedCells:([[Ljava/lang/Integer;)I
     492: invokevirtual #43                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     495: invokevirtual #57                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     498: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     501: swap
     502: invokevirtual #268                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     505: return

  private static final kotlin.ranges.IntProgression addNotObliqueVent$getXRange(kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       4: checkcast     #30                 // class kotlin/Pair
       7: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      10: checkcast     #36                 // class java/lang/Number
      13: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      16: aload_0
      17: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      20: checkcast     #30                 // class kotlin/Pair
      23: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      26: checkcast     #36                 // class java/lang/Number
      29: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      32: if_icmpge     73
      35: aload_0
      36: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      39: checkcast     #30                 // class kotlin/Pair
      42: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      45: checkcast     #36                 // class java/lang/Number
      48: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      51: aload_0
      52: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      55: checkcast     #30                 // class kotlin/Pair
      58: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      61: checkcast     #36                 // class java/lang/Number
      64: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      67: invokestatic  #297                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      70: goto          108
      73: aload_0
      74: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      77: checkcast     #30                 // class kotlin/Pair
      80: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      83: checkcast     #36                 // class java/lang/Number
      86: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      89: aload_0
      90: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      93: checkcast     #30                 // class kotlin/Pair
      96: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      99: checkcast     #36                 // class java/lang/Number
     102: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     105: invokestatic  #297                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
     108: areturn

  private static final kotlin.ranges.IntProgression addNotObliqueVent$getYRange(kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       4: checkcast     #30                 // class kotlin/Pair
       7: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      10: checkcast     #36                 // class java/lang/Number
      13: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      16: aload_0
      17: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      20: checkcast     #30                 // class kotlin/Pair
      23: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      26: checkcast     #36                 // class java/lang/Number
      29: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      32: if_icmpge     73
      35: aload_0
      36: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      39: checkcast     #30                 // class kotlin/Pair
      42: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      45: checkcast     #36                 // class java/lang/Number
      48: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      51: aload_0
      52: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      55: checkcast     #30                 // class kotlin/Pair
      58: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      61: checkcast     #36                 // class java/lang/Number
      64: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      67: invokestatic  #297                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      70: goto          108
      73: aload_0
      74: invokevirtual #34                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      77: checkcast     #30                 // class kotlin/Pair
      80: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      83: checkcast     #36                 // class java/lang/Number
      86: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      89: aload_0
      90: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      93: checkcast     #30                 // class kotlin/Pair
      96: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      99: checkcast     #36                 // class java/lang/Number
     102: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     105: invokestatic  #297                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
     108: areturn
}


fun main() {
    val numbers = mutableListOf<Int>()

    println("Digite uma série de números separados por espaços (ou '0' para sair):")

    while (true) {
        val input = readLine()
        if (input == "0") {
            break
        }

        val number = input?.toIntOrNull()
        if (number != null) {
            numbers.add(number)
        } else {
            println("Entrada inválida. Por favor, digite um número válido ou 'q' para sair.")
        }
    }

    if (numbers.isEmpty()) {
        println("Nenhum número foi inserido.")
    } else {
        println("Média: ${calculateAverage(numbers)}")
        val (max, min) = findMaxAndMin(numbers)
        println("Maior número: $max")
        println("Menor número: $min")
        val (evenCount, oddCount) = countEvenAndOdd(numbers)
        println("Quantidade de números pares: $evenCount")
        println("Quantidade de números ímpares: $oddCount")
    }
}

fun calculateAverage(numbers: List<Int>): Double {
    val sum = numbers.sum()
    return sum.toDouble() / numbers.size
}

fun findMaxAndMin(numbers: List<Int>): Pair<Int, Int> {
    val max = numbers.maxOrNull() ?: Int.MIN_VALUE
    val min = numbers.minOrNull() ?: Int.MAX_VALUE
    return Pair(max, min)
}

fun countEvenAndOdd(numbers: List<Int>): Pair<Int, Int> {
    val evenCount = numbers.count { it % 2 == 0 }
    val oddCount = numbers.size - evenCount
    return Pair(evenCount, oddCount)
}

Compiled from "Atv3.kt"
public final class Atv3Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/util/ArrayList
       3: dup
       4: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #13                 // class java/util/List
      10: astore_0
      11: ldc           #15                 // String Digite uma série de números separados por espaços (ou \'0\' para sair):
      13: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
      16: swap
      17: invokevirtual #27                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      20: nop
      21: invokestatic  #33                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      24: astore_1
      25: aload_1
      26: ldc           #35                 // String 0
      28: invokestatic  #41                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      31: ifeq          37
      34: goto          78
      37: aload_1
      38: dup
      39: ifnull        48
      42: invokestatic  #47                 // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
      45: goto          50
      48: pop
      49: aconst_null
      50: astore_2
      51: aload_2
      52: ifnull        66
      55: aload_0
      56: aload_2
      57: invokeinterface #51,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      62: pop
      63: goto          20
      66: ldc           #53                 // String Entrada inválida. Por favor, digite um número válido ou \'q\' para sair.
      68: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
      71: swap
      72: invokevirtual #27                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      75: goto          20
      78: aload_0
      79: invokeinterface #57,  1           // InterfaceMethod java/util/List.isEmpty:()Z
      84: ifeq          99
      87: ldc           #59                 // String Nenhum número foi inserido.
      89: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
      92: swap
      93: invokevirtual #27                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      96: goto          293
      99: new           #61                 // class java/lang/StringBuilder
     102: dup
     103: invokespecial #62                 // Method java/lang/StringBuilder."<init>":()V
     106: ldc           #64                 // String Média:
     108: invokevirtual #68                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     111: aload_0
     112: invokestatic  #72                 // Method calculateAverage:(Ljava/util/List;)D
     115: invokevirtual #75                 // Method java/lang/StringBuilder.append:(D)Ljava/lang/StringBuilder;
     118: invokevirtual #78                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     121: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
     124: swap
     125: invokevirtual #27                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     128: aload_0
     129: invokestatic  #82                 // Method findMaxAndMin:(Ljava/util/List;)Lkotlin/Pair;
     132: astore_1
     133: aload_1
     134: invokevirtual #88                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     137: checkcast     #90                 // class java/lang/Number
     140: invokevirtual #94                 // Method java/lang/Number.intValue:()I
     143: istore_2
     144: aload_1
     145: invokevirtual #97                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     148: checkcast     #90                 // class java/lang/Number
     151: invokevirtual #94                 // Method java/lang/Number.intValue:()I
     154: istore_3
     155: new           #61                 // class java/lang/StringBuilder
     158: dup
     159: invokespecial #62                 // Method java/lang/StringBuilder."<init>":()V
     162: ldc           #99                 // String Maior número:
     164: invokevirtual #68                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     167: iload_2
     168: invokevirtual #102                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     171: invokevirtual #78                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     174: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
     177: swap
     178: invokevirtual #27                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     181: new           #61                 // class java/lang/StringBuilder
     184: dup
     185: invokespecial #62                 // Method java/lang/StringBuilder."<init>":()V
     188: ldc           #104                // String Menor número:
     190: invokevirtual #68                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     193: iload_3
     194: invokevirtual #102                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     197: invokevirtual #78                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     200: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
     203: swap
     204: invokevirtual #27                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     207: aload_0
     208: invokestatic  #107                // Method countEvenAndOdd:(Ljava/util/List;)Lkotlin/Pair;
     211: astore        4
     213: aload         4
     215: invokevirtual #88                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     218: checkcast     #90                 // class java/lang/Number
     221: invokevirtual #94                 // Method java/lang/Number.intValue:()I
     224: istore        5
     226: aload         4
     228: invokevirtual #97                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     231: checkcast     #90                 // class java/lang/Number
     234: invokevirtual #94                 // Method java/lang/Number.intValue:()I
     237: istore        6
     239: new           #61                 // class java/lang/StringBuilder
     242: dup
     243: invokespecial #62                 // Method java/lang/StringBuilder."<init>":()V
     246: ldc           #109                // String Quantidade de números pares:
     248: invokevirtual #68                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     251: iload         5
     253: invokevirtual #102                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     256: invokevirtual #78                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     259: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
     262: swap
     263: invokevirtual #27                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     266: new           #61                 // class java/lang/StringBuilder
     269: dup
     270: invokespecial #62                 // Method java/lang/StringBuilder."<init>":()V
     273: ldc           #111                // String Quantidade de números ímpares:
     275: invokevirtual #68                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     278: iload         6
     280: invokevirtual #102                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     283: invokevirtual #78                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     286: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
     289: swap
     290: invokevirtual #27                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     293: return

  public static final double calculateAverage(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #129                // String numbers
       3: invokestatic  #133                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #135                // class java/lang/Iterable
      10: invokestatic  #141                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      13: istore_1
      14: iload_1
      15: i2d
      16: aload_0
      17: invokeinterface #144,  1          // InterfaceMethod java/util/List.size:()I
      22: i2d
      23: ddiv
      24: dreturn

  public static final kotlin.Pair<java.lang.Integer, java.lang.Integer> findMaxAndMin(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #129                // String numbers
       3: invokestatic  #133                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #135                // class java/lang/Iterable
      10: invokestatic  #150                // Method kotlin/collections/CollectionsKt.maxOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
      13: checkcast     #126                // class java/lang/Integer
      16: dup
      17: ifnull        26
      20: invokevirtual #151                // Method java/lang/Integer.intValue:()I
      23: goto          29
      26: pop
      27: ldc           #152                // int -2147483648
      29: istore_1
      30: aload_0
      31: checkcast     #135                // class java/lang/Iterable
      34: invokestatic  #155                // Method kotlin/collections/CollectionsKt.minOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
      37: checkcast     #126                // class java/lang/Integer
      40: dup
      41: ifnull        50
      44: invokevirtual #151                // Method java/lang/Integer.intValue:()I
      47: goto          53
      50: pop
      51: ldc           #156                // int 2147483647
      53: istore_2
      54: new           #84                 // class kotlin/Pair
      57: dup
      58: iload_1
      59: invokestatic  #160                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      62: iload_2
      63: invokestatic  #160                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokespecial #163                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      69: areturn

  public static final kotlin.Pair<java.lang.Integer, java.lang.Integer> countEvenAndOdd(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #129                // String numbers
       3: invokestatic  #133                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #135                // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: instanceof    #165                // class java/util/Collection
      17: ifeq          36
      20: aload_2
      21: checkcast     #165                // class java/util/Collection
      24: invokeinterface #166,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      29: ifeq          36
      32: iconst_0
      33: goto          110
      36: iconst_0
      37: istore        4
      39: aload_2
      40: invokeinterface #170,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        5
      47: aload         5
      49: invokeinterface #175,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          108
      57: aload         5
      59: invokeinterface #178,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        6
      66: aload         6
      68: checkcast     #90                 // class java/lang/Number
      71: invokevirtual #94                 // Method java/lang/Number.intValue:()I
      74: istore        7
      76: iconst_0
      77: istore        8
      79: iload         7
      81: iconst_2
      82: irem
      83: ifne          90
      86: iconst_1
      87: goto          91
      90: iconst_0
      91: ifeq          47
      94: iinc          4, 1
      97: iload         4
      99: ifge          47
     102: invokestatic  #181                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     105: goto          47
     108: iload         4
     110: istore_1
     111: aload_0
     112: invokeinterface #144,  1          // InterfaceMethod java/util/List.size:()I
     117: iload_1
     118: isub
     119: istore_2
     120: new           #84                 // class kotlin/Pair
     123: dup
     124: iload_1
     125: invokestatic  #160                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     128: iload_2
     129: invokestatic  #160                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     132: invokespecial #163                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     135: areturn

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


/**
 * @created October 2, 2019
 * Kotlin Program that solves Rat in a maze problem using backtracking.
 */
class RatMaze {

    // Size of the maze.
    private var n: Int = 0 // Just in case. Primitive types cannot be lateinit.
    private lateinit var solution: Array<IntArray>
    private lateinit var maze: Array<IntArray>

    /**
     * This function solves the Maze problem using
     * Backtracking. It mainly uses solveMazeUtil()
     * to solve the problem. It returns false if no
     * path is possible, otherwise return true and
     * prints the path in the form of 1s. Please note
     * that there may be more than one solutions, this
     * function prints one of the feasible solutions.
     */
    fun solve(maze: Array<IntArray>): Boolean {
        n = maze.size
        this.maze = maze
        solution = Array(n) { IntArray(n) }
        if (!solveMazeUtil(0, 0)) {
            println("Solution does not exist.")
            return false
        }
        printSolution()
        return true
    }

    /**
     * A recursive utility function to solve Maze problem.
     */
    private fun solveMazeUtil(row: Int, column: Int): Boolean {
        // if (row ; column) is the goal then return true
        if (row == n - 1 && column == n - 1) {
            solution[row][column] = 1
            return true
        }
        // Check if maze[row][column] is valid.
        if (isSafe(row, column)) {
            solution[row][column] = 1
            // Move horizontally
            if (solveMazeUtil(row, column + 1)) {
                return true
            }
            // Move vertically
            if (solveMazeUtil(row + 1, column)) {
                return true
            }
            // If none of the above movements works then
            // BACKTRACK: remove mark on row, column as part of solution path
            solution[row][column] = 0
            return false
        }
        return false
    }

    /**
     * Checks that the coordinates "row" and "column" are valid.
     */
    private fun isSafe(row: Int, column: Int): Boolean {
        return row in 0..(n - 1) &&
                column in 0..(n - 1) &&
                maze[row][column] == 1
    }

    /**
     * A utility function to print solution matrix.
     * solution[n][n]
     */
    private fun printSolution() {
        (0..(n - 1)).forEach { row ->
            (0..(n - 1)).forEach { column ->
                print(" ${solution[row][column]}")
            }
            println()
        }
    }

}

fun main() {
    // Valid Maze
    val maze01 = arrayOf(
        intArrayOf(1, 0, 0, 0),
        intArrayOf(1, 1, 0, 1),
        intArrayOf(0, 1, 0, 0),
        intArrayOf(1, 1, 1, 1)
    )

    // Valid Maze
    val maze02 = arrayOf(
        intArrayOf(1, 0, 0),
        intArrayOf(1, 1, 0),
        intArrayOf(0, 1, 1)
    )

    // Invalid Maze
    val maze03 = arrayOf(
        intArrayOf(1, 0, 0),
        intArrayOf(0, 0, 0),
        intArrayOf(0, 0, 1)
    )

    val mazes = arrayListOf<Array<IntArray>>()
    mazes.add(maze01)
    mazes.add(maze02)
    mazes.add(maze03)

    val ratMaze = RatMaze()
    for (i in 0 until mazes.size) {
        println("Solving Maze ${i + 1}")
        println()
        ratMaze.solve(mazes[i])
        println()
    }
}

Compiled from "RatMaze.kt"
public final class RatMaze {
  private int n;

  private int[][] solution;

  private int[][] maze;

  public RatMaze();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final boolean solve(int[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String maze
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: checkcast     #23                 // class "[Ljava/lang/Object;"
      11: arraylength
      12: putfield      #27                 // Field n:I
      15: aload_0
      16: aload_1
      17: putfield      #30                 // Field maze:[[I
      20: aload_0
      21: iconst_0
      22: istore_2
      23: aload_0
      24: getfield      #27                 // Field n:I
      27: istore_3
      28: iload_3
      29: anewarray     #32                 // class "[I"
      32: astore        4
      34: astore        6
      36: iload_2
      37: iload_3
      38: if_icmpge     61
      41: iload_2
      42: istore        5
      44: aload         4
      46: iload         5
      48: aload_0
      49: getfield      #27                 // Field n:I
      52: newarray       int
      54: aastore
      55: iinc          2, 1
      58: goto          36
      61: aload         6
      63: aload         4
      65: putfield      #35                 // Field solution:[[I
      68: aload_0
      69: iconst_0
      70: iconst_0
      71: invokespecial #39                 // Method solveMazeUtil:(II)Z
      74: ifne          88
      77: ldc           #41                 // String Solution does not exist.
      79: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
      82: swap
      83: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      86: iconst_0
      87: ireturn
      88: aload_0
      89: invokespecial #56                 // Method printSolution:()V
      92: iconst_1
      93: ireturn

  private final boolean solveMazeUtil(int, int);
    Code:
       0: iload_1
       1: aload_0
       2: getfield      #27                 // Field n:I
       5: iconst_1
       6: isub
       7: if_icmpne     42
      10: iload_2
      11: aload_0
      12: getfield      #27                 // Field n:I
      15: iconst_1
      16: isub
      17: if_icmpne     42
      20: aload_0
      21: getfield      #35                 // Field solution:[[I
      24: dup
      25: ifnonnull     35
      28: pop
      29: ldc           #58                 // String solution
      31: invokestatic  #62                 // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
      34: aconst_null
      35: iload_1
      36: aaload
      37: iload_2
      38: iconst_1
      39: iastore
      40: iconst_1
      41: ireturn
      42: aload_0
      43: iload_1
      44: iload_2
      45: invokespecial #65                 // Method isSafe:(II)Z
      48: ifeq          119
      51: aload_0
      52: getfield      #35                 // Field solution:[[I
      55: dup
      56: ifnonnull     66
      59: pop
      60: ldc           #58                 // String solution
      62: invokestatic  #62                 // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
      65: aconst_null
      66: iload_1
      67: aaload
      68: iload_2
      69: iconst_1
      70: iastore
      71: aload_0
      72: iload_1
      73: iload_2
      74: iconst_1
      75: iadd
      76: invokespecial #39                 // Method solveMazeUtil:(II)Z
      79: ifeq          84
      82: iconst_1
      83: ireturn
      84: aload_0
      85: iload_1
      86: iconst_1
      87: iadd
      88: iload_2
      89: invokespecial #39                 // Method solveMazeUtil:(II)Z
      92: ifeq          97
      95: iconst_1
      96: ireturn
      97: aload_0
      98: getfield      #35                 // Field solution:[[I
     101: dup
     102: ifnonnull     112
     105: pop
     106: ldc           #58                 // String solution
     108: invokestatic  #62                 // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
     111: aconst_null
     112: iload_1
     113: aaload
     114: iload_2
     115: iconst_0
     116: iastore
     117: iconst_0
     118: ireturn
     119: iconst_0
     120: ireturn

  private final boolean isSafe(int, int);
    Code:
       0: iconst_0
       1: iload_1
       2: if_icmpgt     23
       5: iload_1
       6: aload_0
       7: getfield      #27                 // Field n:I
      10: iconst_1
      11: isub
      12: if_icmpgt     19
      15: iconst_1
      16: goto          24
      19: iconst_0
      20: goto          24
      23: iconst_0
      24: ifeq          81
      27: iconst_0
      28: iload_2
      29: if_icmpgt     50
      32: iload_2
      33: aload_0
      34: getfield      #27                 // Field n:I
      37: iconst_1
      38: isub
      39: if_icmpgt     46
      42: iconst_1
      43: goto          51
      46: iconst_0
      47: goto          51
      50: iconst_0
      51: ifeq          81
      54: aload_0
      55: getfield      #30                 // Field maze:[[I
      58: dup
      59: ifnonnull     69
      62: pop
      63: ldc           #15                 // String maze
      65: invokestatic  #62                 // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
      68: aconst_null
      69: iload_1
      70: aaload
      71: iload_2
      72: iaload
      73: iconst_1
      74: if_icmpne     81
      77: iconst_1
      78: goto          82
      81: iconst_0
      82: ireturn

  private final void printSolution();
    Code:
       0: new           #69                 // class kotlin/ranges/IntRange
       3: dup
       4: iconst_0
       5: aload_0
       6: getfield      #27                 // Field n:I
       9: iconst_1
      10: isub
      11: invokespecial #72                 // Method kotlin/ranges/IntRange."<init>":(II)V
      14: checkcast     #74                 // class java/lang/Iterable
      17: astore_1
      18: iconst_0
      19: istore_2
      20: aload_1
      21: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      26: astore_3
      27: aload_3
      28: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      33: ifeq          173
      36: aload_3
      37: checkcast     #86                 // class kotlin/collections/IntIterator
      40: invokevirtual #90                 // Method kotlin/collections/IntIterator.nextInt:()I
      43: istore        4
      45: iload         4
      47: istore        5
      49: iconst_0
      50: istore        6
      52: new           #69                 // class kotlin/ranges/IntRange
      55: dup
      56: iconst_0
      57: aload_0
      58: getfield      #27                 // Field n:I
      61: iconst_1
      62: isub
      63: invokespecial #72                 // Method kotlin/ranges/IntRange."<init>":(II)V
      66: checkcast     #74                 // class java/lang/Iterable
      69: astore        7
      71: iconst_0
      72: istore        8
      74: aload         7
      76: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      81: astore        9
      83: aload         9
      85: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      90: ifeq          161
      93: aload         9
      95: checkcast     #86                 // class kotlin/collections/IntIterator
      98: invokevirtual #90                 // Method kotlin/collections/IntIterator.nextInt:()I
     101: istore        10
     103: iload         10
     105: istore        11
     107: iconst_0
     108: istore        12
     110: new           #92                 // class java/lang/StringBuilder
     113: dup
     114: invokespecial #93                 // Method java/lang/StringBuilder."<init>":()V
     117: bipush        32
     119: invokevirtual #97                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     122: aload_0
     123: getfield      #35                 // Field solution:[[I
     126: dup
     127: ifnonnull     137
     130: pop
     131: ldc           #58                 // String solution
     133: invokestatic  #62                 // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
     136: aconst_null
     137: iload         5
     139: aaload
     140: iload         11
     142: iaload
     143: invokevirtual #100                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     146: invokevirtual #104                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     149: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     152: swap
     153: invokevirtual #107                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     156: nop
     157: nop
     158: goto          83
     161: nop
     162: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     165: invokevirtual #109                // Method java/io/PrintStream.println:()V
     168: nop
     169: nop
     170: goto          27
     173: nop
     174: return
}

Compiled from "RatMaze.kt"
public final class RatMazeKt {
  public static final void main();
    Code:
       0: iconst_4
       1: anewarray     #8                  // class "[I"
       4: astore_1
       5: aload_1
       6: iconst_0
       7: iconst_4
       8: newarray       int
      10: astore_2
      11: aload_2
      12: iconst_0
      13: iconst_1
      14: iastore
      15: aload_2
      16: iconst_1
      17: iconst_0
      18: iastore
      19: aload_2
      20: iconst_2
      21: iconst_0
      22: iastore
      23: aload_2
      24: iconst_3
      25: iconst_0
      26: iastore
      27: aload_2
      28: aastore
      29: aload_1
      30: iconst_1
      31: iconst_4
      32: newarray       int
      34: astore_2
      35: aload_2
      36: iconst_0
      37: iconst_1
      38: iastore
      39: aload_2
      40: iconst_1
      41: iconst_1
      42: iastore
      43: aload_2
      44: iconst_2
      45: iconst_0
      46: iastore
      47: aload_2
      48: iconst_3
      49: iconst_1
      50: iastore
      51: aload_2
      52: aastore
      53: aload_1
      54: iconst_2
      55: iconst_4
      56: newarray       int
      58: astore_2
      59: aload_2
      60: iconst_0
      61: iconst_0
      62: iastore
      63: aload_2
      64: iconst_1
      65: iconst_1
      66: iastore
      67: aload_2
      68: iconst_2
      69: iconst_0
      70: iastore
      71: aload_2
      72: iconst_3
      73: iconst_0
      74: iastore
      75: aload_2
      76: aastore
      77: aload_1
      78: iconst_3
      79: iconst_4
      80: newarray       int
      82: astore_2
      83: aload_2
      84: iconst_0
      85: iconst_1
      86: iastore
      87: aload_2
      88: iconst_1
      89: iconst_1
      90: iastore
      91: aload_2
      92: iconst_2
      93: iconst_1
      94: iastore
      95: aload_2
      96: iconst_3
      97: iconst_1
      98: iastore
      99: aload_2
     100: aastore
     101: aload_1
     102: astore_0
     103: iconst_3
     104: anewarray     #8                  // class "[I"
     107: astore_2
     108: aload_2
     109: iconst_0
     110: iconst_3
     111: newarray       int
     113: astore_3
     114: aload_3
     115: iconst_0
     116: iconst_1
     117: iastore
     118: aload_3
     119: iconst_1
     120: iconst_0
     121: iastore
     122: aload_3
     123: iconst_2
     124: iconst_0
     125: iastore
     126: aload_3
     127: aastore
     128: aload_2
     129: iconst_1
     130: iconst_3
     131: newarray       int
     133: astore_3
     134: aload_3
     135: iconst_0
     136: iconst_1
     137: iastore
     138: aload_3
     139: iconst_1
     140: iconst_1
     141: iastore
     142: aload_3
     143: iconst_2
     144: iconst_0
     145: iastore
     146: aload_3
     147: aastore
     148: aload_2
     149: iconst_2
     150: iconst_3
     151: newarray       int
     153: astore_3
     154: aload_3
     155: iconst_0
     156: iconst_0
     157: iastore
     158: aload_3
     159: iconst_1
     160: iconst_1
     161: iastore
     162: aload_3
     163: iconst_2
     164: iconst_1
     165: iastore
     166: aload_3
     167: aastore
     168: aload_2
     169: astore_1
     170: iconst_3
     171: anewarray     #8                  // class "[I"
     174: astore_3
     175: aload_3
     176: iconst_0
     177: iconst_3
     178: newarray       int
     180: astore        4
     182: aload         4
     184: iconst_0
     185: iconst_1
     186: iastore
     187: aload         4
     189: iconst_1
     190: iconst_0
     191: iastore
     192: aload         4
     194: iconst_2
     195: iconst_0
     196: iastore
     197: aload         4
     199: aastore
     200: aload_3
     201: iconst_1
     202: iconst_3
     203: newarray       int
     205: astore        4
     207: aload         4
     209: iconst_0
     210: iconst_0
     211: iastore
     212: aload         4
     214: iconst_1
     215: iconst_0
     216: iastore
     217: aload         4
     219: iconst_2
     220: iconst_0
     221: iastore
     222: aload         4
     224: aastore
     225: aload_3
     226: iconst_2
     227: iconst_3
     228: newarray       int
     230: astore        4
     232: aload         4
     234: iconst_0
     235: iconst_0
     236: iastore
     237: aload         4
     239: iconst_1
     240: iconst_0
     241: iastore
     242: aload         4
     244: iconst_2
     245: iconst_1
     246: iastore
     247: aload         4
     249: aastore
     250: aload_3
     251: astore_2
     252: new           #10                 // class java/util/ArrayList
     255: dup
     256: invokespecial #13                 // Method java/util/ArrayList."<init>":()V
     259: astore_3
     260: aload_3
     261: aload_0
     262: invokevirtual #17                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     265: pop
     266: aload_3
     267: aload_1
     268: invokevirtual #17                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     271: pop
     272: aload_3
     273: aload_2
     274: invokevirtual #17                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     277: pop
     278: new           #19                 // class RatMaze
     281: dup
     282: invokespecial #20                 // Method RatMaze."<init>":()V
     285: astore        4
     287: iconst_0
     288: istore        5
     290: aload_3
     291: invokevirtual #24                 // Method java/util/ArrayList.size:()I
     294: istore        6
     296: iload         5
     298: iload         6
     300: if_icmpge     371
     303: new           #26                 // class java/lang/StringBuilder
     306: dup
     307: invokespecial #27                 // Method java/lang/StringBuilder."<init>":()V
     310: ldc           #29                 // String Solving Maze
     312: invokevirtual #33                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     315: iload         5
     317: iconst_1
     318: iadd
     319: invokevirtual #36                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     322: invokevirtual #40                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     325: getstatic     #46                 // Field java/lang/System.out:Ljava/io/PrintStream;
     328: swap
     329: invokevirtual #52                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     332: getstatic     #46                 // Field java/lang/System.out:Ljava/io/PrintStream;
     335: invokevirtual #54                 // Method java/io/PrintStream.println:()V
     338: aload         4
     340: aload_3
     341: iload         5
     343: invokevirtual #58                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     346: dup
     347: ldc           #60                 // String get(...)
     349: invokestatic  #66                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     352: checkcast     #68                 // class "[[I"
     355: invokevirtual #72                 // Method RatMaze.solve:([[I)Z
     358: pop
     359: getstatic     #46                 // Field java/lang/System.out:Ljava/io/PrintStream;
     362: invokevirtual #54                 // Method java/io/PrintStream.println:()V
     365: iinc          5, 1
     368: goto          296
     371: return

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


class Edge(val source: Int, val destination: Int, val weight: Int)

class Graph(val vertices: Int, val edges: List<Edge>) {
    fun bellmanFord(startVertex: Int) {
        val distance = IntArray(vertices) { Int.MAX_VALUE }
        distance[startVertex] = 0

        for (i in 1 until vertices) {
            for (edge in edges) {
                if (distance[edge.source] != Int.MAX_VALUE && distance[edge.source] + edge.weight < distance[edge.destination]) {
                    distance[edge.destination] = distance[edge.source] + edge.weight
                }
            }
        }

        for (edge in edges) {
            if (distance[edge.source] != Int.MAX_VALUE && distance[edge.source] + edge.weight < distance[edge.destination]) {
                println("Graph contains a negative-weight cycle.")
                return
            }
        }

        for (i in 0 until vertices) {
            println("Shortest distance from vertex $startVertex to vertex $i is ${distance[i]}")
        }
    }
}

fun main() {
    val vertices = 5
    val edges = listOf(
        Edge(0, 1, -1),
        Edge(0, 2, 4),
        Edge(1, 2, 3),
        Edge(1, 3, 2),
        Edge(1, 4, 2),
        Edge(3, 2, 5),
        Edge(3, 1, 1),
        Edge(4, 3, -3)
    )

    val graph = Graph(vertices, edges)

    val startVertex = 0
    graph.bellmanFord(startVertex)
}

Compiled from "bellmanford.kt"
public final class BellmanfordKt {
  public static final void main();
    Code:
       0: iconst_5
       1: istore_0
       2: bipush        8
       4: anewarray     #8                  // class Edge
       7: astore_2
       8: aload_2
       9: iconst_0
      10: new           #8                  // class Edge
      13: dup
      14: iconst_0
      15: iconst_1
      16: iconst_m1
      17: invokespecial #12                 // Method Edge."<init>":(III)V
      20: aastore
      21: aload_2
      22: iconst_1
      23: new           #8                  // class Edge
      26: dup
      27: iconst_0
      28: iconst_2
      29: iconst_4
      30: invokespecial #12                 // Method Edge."<init>":(III)V
      33: aastore
      34: aload_2
      35: iconst_2
      36: new           #8                  // class Edge
      39: dup
      40: iconst_1
      41: iconst_2
      42: iconst_3
      43: invokespecial #12                 // Method Edge."<init>":(III)V
      46: aastore
      47: aload_2
      48: iconst_3
      49: new           #8                  // class Edge
      52: dup
      53: iconst_1
      54: iconst_3
      55: iconst_2
      56: invokespecial #12                 // Method Edge."<init>":(III)V
      59: aastore
      60: aload_2
      61: iconst_4
      62: new           #8                  // class Edge
      65: dup
      66: iconst_1
      67: iconst_4
      68: iconst_2
      69: invokespecial #12                 // Method Edge."<init>":(III)V
      72: aastore
      73: aload_2
      74: iconst_5
      75: new           #8                  // class Edge
      78: dup
      79: iconst_3
      80: iconst_2
      81: iconst_5
      82: invokespecial #12                 // Method Edge."<init>":(III)V
      85: aastore
      86: aload_2
      87: bipush        6
      89: new           #8                  // class Edge
      92: dup
      93: iconst_3
      94: iconst_1
      95: iconst_1
      96: invokespecial #12                 // Method Edge."<init>":(III)V
      99: aastore
     100: aload_2
     101: bipush        7
     103: new           #8                  // class Edge
     106: dup
     107: iconst_4
     108: iconst_3
     109: bipush        -3
     111: invokespecial #12                 // Method Edge."<init>":(III)V
     114: aastore
     115: aload_2
     116: invokestatic  #18                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     119: astore_1
     120: new           #20                 // class Graph
     123: dup
     124: iload_0
     125: aload_1
     126: invokespecial #23                 // Method Graph."<init>":(ILjava/util/List;)V
     129: astore_2
     130: iconst_0
     131: istore_3
     132: aload_2
     133: iload_3
     134: invokevirtual #27                 // Method Graph.bellmanFord:(I)V
     137: return

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


// Problem 21 - Project Euler
// http://projecteuler.net/index.php?section=problems&id=21
import kotlin.math.*

fun divisors(x: Int): List<Int> {
    val lim = ceil(sqrt(x.toDouble())).toInt()
    return (1..lim)
            .map { n ->
                if (x % n == 0) listOf(n, x/n) else null
            }
            .filterNotNull()
            .flatten()
            .distinct()
            .toList()
}

fun d(x: Int) = divisors(x).sum() - x

fun amicable_pair(x: Int): Int? {
    val dx = d(x)
    return if (d(dx) == x && dx != x) dx else null
}

fun main(args: Array<String>) {
    val ans = (1..10000-1).map { amicable_pair(it) }
            .filterNotNull()
            .filter { it < 10000 }
            .sum()
    println(ans)
}

Compiled from "problem021.kt"
public final class Problem021Kt {
  public static final java.util.List<java.lang.Integer> divisors(int);
    Code:
       0: iload_0
       1: i2d
       2: invokestatic  #14                 // Method java/lang/Math.sqrt:(D)D
       5: invokestatic  #17                 // Method java/lang/Math.ceil:(D)D
       8: d2i
       9: istore_1
      10: new           #19                 // class kotlin/ranges/IntRange
      13: dup
      14: iconst_1
      15: iload_1
      16: invokespecial #23                 // Method kotlin/ranges/IntRange."<init>":(II)V
      19: checkcast     #25                 // class java/lang/Iterable
      22: astore_2
      23: nop
      24: iconst_0
      25: istore_3
      26: aload_2
      27: astore        4
      29: new           #27                 // class java/util/ArrayList
      32: dup
      33: aload_2
      34: bipush        10
      36: invokestatic  #33                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      39: invokespecial #36                 // Method java/util/ArrayList."<init>":(I)V
      42: checkcast     #38                 // class java/util/Collection
      45: astore        5
      47: iconst_0
      48: istore        6
      50: aload         4
      52: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      57: astore        7
      59: aload         7
      61: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      66: ifeq          144
      69: aload         7
      71: checkcast     #50                 // class kotlin/collections/IntIterator
      74: invokevirtual #54                 // Method kotlin/collections/IntIterator.nextInt:()I
      77: istore        8
      79: aload         5
      81: iload         8
      83: istore        9
      85: astore        12
      87: iconst_0
      88: istore        10
      90: iload_0
      91: iload         9
      93: irem
      94: ifne          131
      97: iconst_2
      98: anewarray     #56                 // class java/lang/Integer
     101: astore        11
     103: aload         11
     105: iconst_0
     106: iload         9
     108: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     111: aastore
     112: aload         11
     114: iconst_1
     115: iload_0
     116: iload         9
     118: idiv
     119: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     122: aastore
     123: aload         11
     125: invokestatic  #64                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     128: goto          132
     131: aconst_null
     132: aload         12
     134: swap
     135: invokeinterface #68,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     140: pop
     141: goto          59
     144: aload         5
     146: checkcast     #70                 // class java/util/List
     149: nop
     150: checkcast     #25                 // class java/lang/Iterable
     153: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.filterNotNull:(Ljava/lang/Iterable;)Ljava/util/List;
     156: checkcast     #25                 // class java/lang/Iterable
     159: invokestatic  #77                 // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     162: checkcast     #25                 // class java/lang/Iterable
     165: invokestatic  #80                 // Method kotlin/collections/CollectionsKt.distinct:(Ljava/lang/Iterable;)Ljava/util/List;
     168: checkcast     #25                 // class java/lang/Iterable
     171: invokestatic  #83                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     174: areturn

  public static final int d(int);
    Code:
       0: iload_0
       1: invokestatic  #100                // Method divisors:(I)Ljava/util/List;
       4: checkcast     #25                 // class java/lang/Iterable
       7: invokestatic  #104                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      10: iload_0
      11: isub
      12: ireturn

  public static final java.lang.Integer amicable_pair(int);
    Code:
       0: iload_0
       1: invokestatic  #108                // Method d:(I)I
       4: istore_1
       5: iload_1
       6: invokestatic  #108                // Method d:(I)I
       9: iload_0
      10: if_icmpne     25
      13: iload_1
      14: iload_0
      15: if_icmpeq     25
      18: iload_1
      19: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      22: goto          26
      25: aconst_null
      26: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #113                // String args
       3: invokestatic  #119                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #19                 // class kotlin/ranges/IntRange
       9: dup
      10: iconst_1
      11: sipush        9999
      14: invokespecial #23                 // Method kotlin/ranges/IntRange."<init>":(II)V
      17: checkcast     #25                 // class java/lang/Iterable
      20: astore_2
      21: iconst_0
      22: istore_3
      23: aload_2
      24: astore        4
      26: new           #27                 // class java/util/ArrayList
      29: dup
      30: aload_2
      31: bipush        10
      33: invokestatic  #33                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      36: invokespecial #36                 // Method java/util/ArrayList."<init>":(I)V
      39: checkcast     #38                 // class java/util/Collection
      42: astore        5
      44: iconst_0
      45: istore        6
      47: aload         4
      49: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      54: astore        7
      56: aload         7
      58: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      63: ifeq          104
      66: aload         7
      68: checkcast     #50                 // class kotlin/collections/IntIterator
      71: invokevirtual #54                 // Method kotlin/collections/IntIterator.nextInt:()I
      74: istore        8
      76: aload         5
      78: iload         8
      80: istore        9
      82: astore        11
      84: iconst_0
      85: istore        10
      87: iload         9
      89: invokestatic  #121                // Method amicable_pair:(I)Ljava/lang/Integer;
      92: aload         11
      94: swap
      95: invokeinterface #68,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     100: pop
     101: goto          56
     104: aload         5
     106: checkcast     #70                 // class java/util/List
     109: nop
     110: checkcast     #25                 // class java/lang/Iterable
     113: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.filterNotNull:(Ljava/lang/Iterable;)Ljava/util/List;
     116: checkcast     #25                 // class java/lang/Iterable
     119: astore_2
     120: nop
     121: iconst_0
     122: istore_3
     123: aload_2
     124: astore        4
     126: new           #27                 // class java/util/ArrayList
     129: dup
     130: invokespecial #124                // Method java/util/ArrayList."<init>":()V
     133: checkcast     #38                 // class java/util/Collection
     136: astore        5
     138: iconst_0
     139: istore        6
     141: aload         4
     143: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     148: astore        7
     150: aload         7
     152: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     157: ifeq          211
     160: aload         7
     162: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     167: astore        8
     169: aload         8
     171: checkcast     #130                // class java/lang/Number
     174: invokevirtual #133                // Method java/lang/Number.intValue:()I
     177: istore        9
     179: iconst_0
     180: istore        10
     182: iload         9
     184: sipush        10000
     187: if_icmpge     194
     190: iconst_1
     191: goto          195
     194: iconst_0
     195: ifeq          150
     198: aload         5
     200: aload         8
     202: invokeinterface #68,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     207: pop
     208: goto          150
     211: aload         5
     213: checkcast     #70                 // class java/util/List
     216: nop
     217: checkcast     #25                 // class java/lang/Iterable
     220: invokestatic  #104                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     223: istore_1
     224: getstatic     #139                // Field java/lang/System.out:Ljava/io/PrintStream;
     227: iload_1
     228: invokevirtual #144                // Method java/io/PrintStream.println:(I)V
     231: return
}