package adventofcode

import java.io.File

class PuzzleDay04 {

    fun determineWinningBoardOrder(file: File): List<BingoBoard> {
        val pulls = readPulls(file)
        val boards = readBoards(file)
        return pulls.flatMap { pulledNumber ->
                boards.filter { !it.won }
                    .onEach { it.drawNumber(pulledNumber) }
                    .filter { it.won }
            }
    }

    private fun readPulls(file: File): List<Int> = file.useLines { seq ->
        seq.first().split(",").map { it.toInt() }
    }

    private fun readBoards(file: File): List<BingoBoard> = file.useLines { seq ->
        seq.drop(2)
            .flatMap { it.split(" ") }
            .filter { it.isNotEmpty() }
            .map { it.toInt() }
            .windowed(25, 25)
            .mapIndexed { index, boardNumbers -> BingoBoard(index + 1, boardNumbers.toIntArray()) }
            .toList()
    }

    class BingoBoard(val id: Int, numbers: IntArray) {

        companion object {
            const val X_SIZE = 5
            const val Y_SIZE = 5
            const val WINNING_COUNT = 5
        }

        private val fields: Array<BingoBoardField> = numbers.map { BingoBoardField(it) }.toTypedArray()
        var won: Boolean = false
        var drawsToWin: Int = 0
        var lastNumber: Int = -1

        fun score(): Int = if (!won) 0 else fields.filter { !it.pulled }.sumOf { it.number } * lastNumber

        fun drawNumber(number: Int) {
            if (won) return
            fields.filter { it.number == number }.onEach { it.pulled = true }
            drawsToWin++
            won = checkWon()
            lastNumber = number
        }

        private fun checkWon(): Boolean =
            ((0 until X_SIZE).map { columnFields(it) } + (0 until Y_SIZE).map { rowFields(it) }).any { it.checkWon() }

        private fun List<BingoBoardField>.checkWon(): Boolean = count { it.pulled } >= WINNING_COUNT

        private fun rowFields(rowIndex: Int): List<BingoBoardField> =
            fields.slice(rowIndex * X_SIZE until rowIndex * X_SIZE + X_SIZE)

        private fun columnFields(columnIndex: Int): List<BingoBoardField> =
            fields.slice(columnIndex until X_SIZE * Y_SIZE step X_SIZE)

    }

    class BingoBoardField(val number: Int) {
        var pulled: Boolean = false
    }
}

Compiled from "PuzzleDay04.kt"
public final class adventofcode.PuzzleDay04$BingoBoard$Companion {
  private adventofcode.PuzzleDay04$BingoBoard$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public adventofcode.PuzzleDay04$BingoBoard$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #12                 // Method "<init>":()V
       4: return
}

Compiled from "PuzzleDay04.kt"
public final class adventofcode.PuzzleDay04$BingoBoardField {
  private final int number;

  private boolean pulled;

  public adventofcode.PuzzleDay04$BingoBoardField(int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field number:I
       9: return

  public final int getNumber();
    Code:
       0: aload_0
       1: getfield      #13                 // Field number:I
       4: ireturn

  public final boolean getPulled();
    Code:
       0: aload_0
       1: getfield      #23                 // Field pulled:Z
       4: ireturn

  public final void setPulled(boolean);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #23                 // Field pulled:Z
       5: return
}

Compiled from "PuzzleDay04.kt"
public final class adventofcode.PuzzleDay04$BingoBoard {
  public static final adventofcode.PuzzleDay04$BingoBoard$Companion Companion;

  private final int id;

  private final adventofcode.PuzzleDay04$BingoBoardField[] fields;

  private boolean won;

  private int drawsToWin;

  private int lastNumber;

  public static final int X_SIZE;

  public static final int Y_SIZE;

  public static final int WINNING_COUNT;

  public adventofcode.PuzzleDay04$BingoBoard(int, int[]);
    Code:
       0: aload_2
       1: ldc           #9                  // String numbers
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: iload_1
      12: putfield      #22                 // Field id:I
      15: aload_0
      16: aload_2
      17: astore_3
      18: astore        13
      20: iconst_0
      21: istore        4
      23: aload_3
      24: astore        5
      26: new           #24                 // class java/util/ArrayList
      29: dup
      30: aload_3
      31: arraylength
      32: invokespecial #27                 // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #29                 // class java/util/Collection
      38: astore        6
      40: iconst_0
      41: istore        7
      43: iconst_0
      44: istore        8
      46: aload         5
      48: arraylength
      49: istore        9
      51: iload         8
      53: iload         9
      55: if_icmpge     100
      58: aload         5
      60: iload         8
      62: iaload
      63: istore        10
      65: aload         6
      67: iload         10
      69: istore        11
      71: astore        14
      73: iconst_0
      74: istore        12
      76: new           #31                 // class adventofcode/PuzzleDay04$BingoBoardField
      79: dup
      80: iload         11
      82: invokespecial #32                 // Method adventofcode/PuzzleDay04$BingoBoardField."<init>":(I)V
      85: aload         14
      87: swap
      88: invokeinterface #36,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      93: pop
      94: iinc          8, 1
      97: goto          51
     100: aload         6
     102: checkcast     #38                 // class java/util/List
     105: nop
     106: aload         13
     108: swap
     109: checkcast     #29                 // class java/util/Collection
     112: astore_3
     113: nop
     114: iconst_0
     115: istore        4
     117: aload_3
     118: astore        5
     120: aload         5
     122: iconst_0
     123: anewarray     #31                 // class adventofcode/PuzzleDay04$BingoBoardField
     126: invokeinterface #42,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     131: checkcast     #44                 // class "[Ladventofcode/PuzzleDay04$BingoBoardField;"
     134: putfield      #47                 // Field fields:[Ladventofcode/PuzzleDay04$BingoBoardField;
     137: aload_0
     138: iconst_m1
     139: putfield      #50                 // Field lastNumber:I
     142: return

  public final int getId();
    Code:
       0: aload_0
       1: getfield      #22                 // Field id:I
       4: ireturn

  public final boolean getWon();
    Code:
       0: aload_0
       1: getfield      #74                 // Field won:Z
       4: ireturn

  public final void setWon(boolean);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #74                 // Field won:Z
       5: return

  public final int getDrawsToWin();
    Code:
       0: aload_0
       1: getfield      #81                 // Field drawsToWin:I
       4: ireturn

  public final void setDrawsToWin(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #81                 // Field drawsToWin:I
       5: return

  public final int getLastNumber();
    Code:
       0: aload_0
       1: getfield      #50                 // Field lastNumber:I
       4: ireturn

  public final void setLastNumber(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #50                 // Field lastNumber:I
       5: return

  public final int score();
    Code:
       0: aload_0
       1: getfield      #74                 // Field won:Z
       4: ifne          11
       7: iconst_0
       8: goto          165
      11: aload_0
      12: getfield      #47                 // Field fields:[Ladventofcode/PuzzleDay04$BingoBoardField;
      15: astore_1
      16: iconst_0
      17: istore_2
      18: aload_1
      19: astore_3
      20: new           #24                 // class java/util/ArrayList
      23: dup
      24: invokespecial #86                 // Method java/util/ArrayList."<init>":()V
      27: checkcast     #29                 // class java/util/Collection
      30: astore        4
      32: iconst_0
      33: istore        5
      35: iconst_0
      36: istore        6
      38: aload_3
      39: arraylength
      40: istore        7
      42: iload         6
      44: iload         7
      46: if_icmpge     94
      49: aload_3
      50: iload         6
      52: aaload
      53: astore        8
      55: aload         8
      57: astore        9
      59: iconst_0
      60: istore        10
      62: aload         9
      64: invokevirtual #89                 // Method adventofcode/PuzzleDay04$BingoBoardField.getPulled:()Z
      67: ifne          74
      70: iconst_1
      71: goto          75
      74: iconst_0
      75: ifeq          88
      78: aload         4
      80: aload         8
      82: invokeinterface #36,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      87: pop
      88: iinc          6, 1
      91: goto          42
      94: aload         4
      96: checkcast     #38                 // class java/util/List
      99: nop
     100: checkcast     #91                 // class java/lang/Iterable
     103: astore_1
     104: iconst_0
     105: istore_2
     106: aload_1
     107: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     112: astore_3
     113: aload_3
     114: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     119: ifeq          159
     122: aload_3
     123: invokeinterface #104,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     128: astore        4
     130: iload_2
     131: aload         4
     133: checkcast     #31                 // class adventofcode/PuzzleDay04$BingoBoardField
     136: astore        5
     138: istore        11
     140: iconst_0
     141: istore        6
     143: aload         5
     145: invokevirtual #107                // Method adventofcode/PuzzleDay04$BingoBoardField.getNumber:()I
     148: istore        12
     150: iload         11
     152: iload         12
     154: iadd
     155: istore_2
     156: goto          113
     159: iload_2
     160: aload_0
     161: getfield      #50                 // Field lastNumber:I
     164: imul
     165: ireturn

  public final void drawNumber(int);
    Code:
       0: aload_0
       1: getfield      #74                 // Field won:Z
       4: ifeq          8
       7: return
       8: aload_0
       9: getfield      #47                 // Field fields:[Ladventofcode/PuzzleDay04$BingoBoardField;
      12: astore_2
      13: iconst_0
      14: istore_3
      15: aload_2
      16: astore        4
      18: new           #24                 // class java/util/ArrayList
      21: dup
      22: invokespecial #86                 // Method java/util/ArrayList."<init>":()V
      25: checkcast     #29                 // class java/util/Collection
      28: astore        5
      30: iconst_0
      31: istore        6
      33: iconst_0
      34: istore        7
      36: aload         4
      38: arraylength
      39: istore        8
      41: iload         7
      43: iload         8
      45: if_icmpge     95
      48: aload         4
      50: iload         7
      52: aaload
      53: astore        9
      55: aload         9
      57: astore        10
      59: iconst_0
      60: istore        11
      62: aload         10
      64: invokevirtual #107                // Method adventofcode/PuzzleDay04$BingoBoardField.getNumber:()I
      67: iload_1
      68: if_icmpne     75
      71: iconst_1
      72: goto          76
      75: iconst_0
      76: ifeq          89
      79: aload         5
      81: aload         9
      83: invokeinterface #36,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: iinc          7, 1
      92: goto          41
      95: aload         5
      97: checkcast     #38                 // class java/util/List
     100: nop
     101: checkcast     #91                 // class java/lang/Iterable
     104: astore_2
     105: nop
     106: iconst_0
     107: istore_3
     108: aload_2
     109: astore        4
     111: aload         4
     113: astore        5
     115: iconst_0
     116: istore        6
     118: aload         5
     120: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     125: astore        7
     127: aload         7
     129: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     134: ifeq          166
     137: aload         7
     139: invokeinterface #104,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     144: astore        8
     146: aload         8
     148: checkcast     #31                 // class adventofcode/PuzzleDay04$BingoBoardField
     151: astore        9
     153: iconst_0
     154: istore        10
     156: aload         9
     158: iconst_1
     159: invokevirtual #121                // Method adventofcode/PuzzleDay04$BingoBoardField.setPulled:(Z)V
     162: nop
     163: goto          127
     166: nop
     167: nop
     168: aload_0
     169: getfield      #81                 // Field drawsToWin:I
     172: istore_2
     173: aload_0
     174: iload_2
     175: iconst_1
     176: iadd
     177: putfield      #81                 // Field drawsToWin:I
     180: aload_0
     181: aload_0
     182: invokespecial #124                // Method checkWon:()Z
     185: putfield      #74                 // Field won:Z
     188: aload_0
     189: iload_1
     190: putfield      #50                 // Field lastNumber:I
     193: return

  private final boolean checkWon();
    Code:
       0: iconst_0
       1: iconst_5
       2: invokestatic  #139                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       5: checkcast     #91                 // class java/lang/Iterable
       8: astore_1
       9: iconst_0
      10: istore_2
      11: aload_1
      12: astore_3
      13: new           #24                 // class java/util/ArrayList
      16: dup
      17: aload_1
      18: bipush        10
      20: invokestatic  #145                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      23: invokespecial #27                 // Method java/util/ArrayList."<init>":(I)V
      26: checkcast     #29                 // class java/util/Collection
      29: astore        4
      31: iconst_0
      32: istore        5
      34: aload_3
      35: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        6
      42: aload         6
      44: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          91
      52: aload         6
      54: checkcast     #147                // class kotlin/collections/IntIterator
      57: invokevirtual #150                // Method kotlin/collections/IntIterator.nextInt:()I
      60: istore        7
      62: aload         4
      64: iload         7
      66: istore        8
      68: astore        10
      70: iconst_0
      71: istore        9
      73: aload_0
      74: iload         8
      76: invokespecial #154                // Method columnFields:(I)Ljava/util/List;
      79: aload         10
      81: swap
      82: invokeinterface #36,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      87: pop
      88: goto          42
      91: aload         4
      93: checkcast     #38                 // class java/util/List
      96: nop
      97: checkcast     #29                 // class java/util/Collection
     100: iconst_0
     101: iconst_5
     102: invokestatic  #139                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     105: checkcast     #91                 // class java/lang/Iterable
     108: astore_1
     109: astore        10
     111: iconst_0
     112: istore_2
     113: aload_1
     114: astore_3
     115: new           #24                 // class java/util/ArrayList
     118: dup
     119: aload_1
     120: bipush        10
     122: invokestatic  #145                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     125: invokespecial #27                 // Method java/util/ArrayList."<init>":(I)V
     128: checkcast     #29                 // class java/util/Collection
     131: astore        4
     133: iconst_0
     134: istore        5
     136: aload_3
     137: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     142: astore        6
     144: aload         6
     146: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     151: ifeq          193
     154: aload         6
     156: checkcast     #147                // class kotlin/collections/IntIterator
     159: invokevirtual #150                // Method kotlin/collections/IntIterator.nextInt:()I
     162: istore        7
     164: aload         4
     166: iload         7
     168: istore        8
     170: astore        11
     172: iconst_0
     173: istore        9
     175: aload_0
     176: iload         8
     178: invokespecial #157                // Method rowFields:(I)Ljava/util/List;
     181: aload         11
     183: swap
     184: invokeinterface #36,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     189: pop
     190: goto          144
     193: aload         4
     195: checkcast     #38                 // class java/util/List
     198: nop
     199: aload         10
     201: swap
     202: checkcast     #91                 // class java/lang/Iterable
     205: invokestatic  #161                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     208: checkcast     #91                 // class java/lang/Iterable
     211: astore_1
     212: iconst_0
     213: istore_2
     214: aload_1
     215: instanceof    #29                 // class java/util/Collection
     218: ifeq          237
     221: aload_1
     222: checkcast     #29                 // class java/util/Collection
     225: invokeinterface #164,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     230: ifeq          237
     233: iconst_0
     234: goto          285
     237: aload_1
     238: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     243: astore_3
     244: aload_3
     245: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     250: ifeq          284
     253: aload_3
     254: invokeinterface #104,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     259: astore        4
     261: aload         4
     263: checkcast     #38                 // class java/util/List
     266: astore        5
     268: iconst_0
     269: istore        6
     271: aload_0
     272: aload         5
     274: invokespecial #167                // Method checkWon:(Ljava/util/List;)Z
     277: ifeq          244
     280: iconst_1
     281: goto          285
     284: iconst_0
     285: ireturn

  private final boolean checkWon(java.util.List<adventofcode.PuzzleDay04$BingoBoardField>);
    Code:
       0: aload_1
       1: checkcast     #91                 // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: instanceof    #29                 // class java/util/Collection
      11: ifeq          30
      14: aload_2
      15: checkcast     #29                 // class java/util/Collection
      18: invokeinterface #164,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      23: ifeq          30
      26: iconst_0
      27: goto          94
      30: iconst_0
      31: istore        4
      33: aload_2
      34: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        5
      41: aload         5
      43: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          92
      51: aload         5
      53: invokeinterface #104,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        6
      60: aload         6
      62: checkcast     #31                 // class adventofcode/PuzzleDay04$BingoBoardField
      65: astore        7
      67: iconst_0
      68: istore        8
      70: aload         7
      72: invokevirtual #89                 // Method adventofcode/PuzzleDay04$BingoBoardField.getPulled:()Z
      75: ifeq          41
      78: iinc          4, 1
      81: iload         4
      83: ifge          41
      86: invokestatic  #177                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
      89: goto          41
      92: iload         4
      94: iconst_5
      95: if_icmplt     102
      98: iconst_1
      99: goto          103
     102: iconst_0
     103: ireturn

  private final java.util.List<adventofcode.PuzzleDay04$BingoBoardField> rowFields(int);
    Code:
       0: aload_0
       1: getfield      #47                 // Field fields:[Ladventofcode/PuzzleDay04$BingoBoardField;
       4: iload_1
       5: iconst_5
       6: imul
       7: iload_1
       8: iconst_5
       9: imul
      10: iconst_5
      11: iadd
      12: invokestatic  #139                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      15: invokestatic  #189                // Method kotlin/collections/ArraysKt.slice:([Ljava/lang/Object;Lkotlin/ranges/IntRange;)Ljava/util/List;
      18: areturn

  private final java.util.List<adventofcode.PuzzleDay04$BingoBoardField> columnFields(int);
    Code:
       0: aload_0
       1: getfield      #47                 // Field fields:[Ladventofcode/PuzzleDay04$BingoBoardField;
       4: iload_1
       5: bipush        25
       7: invokestatic  #139                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      10: checkcast     #192                // class kotlin/ranges/IntProgression
      13: iconst_5
      14: invokestatic  #196                // Method kotlin/ranges/RangesKt.step:(Lkotlin/ranges/IntProgression;I)Lkotlin/ranges/IntProgression;
      17: checkcast     #91                 // class java/lang/Iterable
      20: invokestatic  #199                // Method kotlin/collections/ArraysKt.slice:([Ljava/lang/Object;Ljava/lang/Iterable;)Ljava/util/List;
      23: areturn

  static {};
    Code:
       0: new           #203                // class adventofcode/PuzzleDay04$BingoBoard$Companion
       3: dup
       4: aconst_null
       5: invokespecial #206                // Method adventofcode/PuzzleDay04$BingoBoard$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #210                // Field Companion:Ladventofcode/PuzzleDay04$BingoBoard$Companion;
      11: return
}

Compiled from "PuzzleDay04.kt"
public final class adventofcode.PuzzleDay04 {
  public adventofcode.PuzzleDay04();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final java.util.List<adventofcode.PuzzleDay04$BingoBoard> determineWinningBoardOrder(java.io.File);
    Code:
       0: aload_1
       1: ldc           #16                 // String file
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #25                 // Method readPulls:(Ljava/io/File;)Ljava/util/List;
      11: astore_2
      12: aload_0
      13: aload_1
      14: invokespecial #28                 // Method readBoards:(Ljava/io/File;)Ljava/util/List;
      17: astore_3
      18: aload_2
      19: checkcast     #30                 // class java/lang/Iterable
      22: astore        4
      24: iconst_0
      25: istore        5
      27: aload         4
      29: astore        6
      31: new           #32                 // class java/util/ArrayList
      34: dup
      35: invokespecial #33                 // Method java/util/ArrayList."<init>":()V
      38: checkcast     #35                 // class java/util/Collection
      41: astore        7
      43: iconst_0
      44: istore        8
      46: aload         6
      48: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        9
      55: aload         9
      57: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          367
      65: aload         9
      67: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: astore        10
      74: aload         10
      76: checkcast     #51                 // class java/lang/Number
      79: invokevirtual #55                 // Method java/lang/Number.intValue:()I
      82: istore        11
      84: iconst_0
      85: istore        12
      87: aload_3
      88: checkcast     #30                 // class java/lang/Iterable
      91: astore        13
      93: iconst_0
      94: istore        14
      96: aload         13
      98: astore        15
     100: new           #32                 // class java/util/ArrayList
     103: dup
     104: invokespecial #33                 // Method java/util/ArrayList."<init>":()V
     107: checkcast     #35                 // class java/util/Collection
     110: astore        16
     112: iconst_0
     113: istore        17
     115: aload         15
     117: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     122: astore        18
     124: aload         18
     126: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     131: ifeq          182
     134: aload         18
     136: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     141: astore        19
     143: aload         19
     145: checkcast     #57                 // class adventofcode/PuzzleDay04$BingoBoard
     148: astore        20
     150: iconst_0
     151: istore        21
     153: aload         20
     155: invokevirtual #60                 // Method adventofcode/PuzzleDay04$BingoBoard.getWon:()Z
     158: ifne          165
     161: iconst_1
     162: goto          166
     165: iconst_0
     166: ifeq          124
     169: aload         16
     171: aload         19
     173: invokeinterface #64,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     178: pop
     179: goto          124
     182: aload         16
     184: checkcast     #66                 // class java/util/List
     187: nop
     188: checkcast     #30                 // class java/lang/Iterable
     191: astore        13
     193: nop
     194: iconst_0
     195: istore        14
     197: aload         13
     199: astore        15
     201: aload         15
     203: astore        16
     205: iconst_0
     206: istore        17
     208: aload         16
     210: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     215: astore        18
     217: aload         18
     219: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     224: ifeq          257
     227: aload         18
     229: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     234: astore        19
     236: aload         19
     238: checkcast     #57                 // class adventofcode/PuzzleDay04$BingoBoard
     241: astore        20
     243: iconst_0
     244: istore        21
     246: aload         20
     248: iload         11
     250: invokevirtual #70                 // Method adventofcode/PuzzleDay04$BingoBoard.drawNumber:(I)V
     253: nop
     254: goto          217
     257: aload         15
     259: nop
     260: astore        13
     262: nop
     263: iconst_0
     264: istore        14
     266: aload         13
     268: astore        15
     270: new           #32                 // class java/util/ArrayList
     273: dup
     274: invokespecial #33                 // Method java/util/ArrayList."<init>":()V
     277: checkcast     #35                 // class java/util/Collection
     280: astore        16
     282: iconst_0
     283: istore        17
     285: aload         15
     287: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     292: astore        18
     294: aload         18
     296: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     301: ifeq          344
     304: aload         18
     306: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     311: astore        19
     313: aload         19
     315: checkcast     #57                 // class adventofcode/PuzzleDay04$BingoBoard
     318: astore        20
     320: iconst_0
     321: istore        21
     323: aload         20
     325: invokevirtual #60                 // Method adventofcode/PuzzleDay04$BingoBoard.getWon:()Z
     328: ifeq          294
     331: aload         16
     333: aload         19
     335: invokeinterface #64,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     340: pop
     341: goto          294
     344: aload         16
     346: checkcast     #66                 // class java/util/List
     349: nop
     350: checkcast     #30                 // class java/lang/Iterable
     353: nop
     354: astore        11
     356: aload         7
     358: aload         11
     360: invokestatic  #76                 // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     363: pop
     364: goto          55
     367: aload         7
     369: checkcast     #66                 // class java/util/List
     372: nop
     373: areturn

  private final java.util.List<java.lang.Integer> readPulls(java.io.File);
    Code:
       0: aload_1
       1: astore_2
       2: getstatic     #118                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
       5: astore_3
       6: iconst_0
       7: istore        4
       9: aload_2
      10: astore        5
      12: sipush        8192
      15: istore        6
      17: aload         5
      19: astore        7
      21: new           #120                // class java/io/InputStreamReader
      24: dup
      25: new           #122                // class java/io/FileInputStream
      28: dup
      29: aload         7
      31: invokespecial #125                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      34: checkcast     #127                // class java/io/InputStream
      37: aload_3
      38: invokespecial #130                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      41: checkcast     #132                // class java/io/Reader
      44: astore        7
      46: aload         7
      48: instanceof    #134                // class java/io/BufferedReader
      51: ifeq          62
      54: aload         7
      56: checkcast     #134                // class java/io/BufferedReader
      59: goto          73
      62: new           #134                // class java/io/BufferedReader
      65: dup
      66: aload         7
      68: iload         6
      70: invokespecial #137                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      73: checkcast     #139                // class java/io/Closeable
      76: astore        5
      78: aconst_null
      79: astore        6
      81: nop
      82: aload         5
      84: checkcast     #134                // class java/io/BufferedReader
      87: astore        7
      89: iconst_0
      90: istore        8
      92: aload         7
      94: invokestatic  #145                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
      97: astore        9
      99: iconst_0
     100: istore        10
     102: aload         9
     104: invokestatic  #151                // Method kotlin/sequences/SequencesKt.first:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
     107: checkcast     #153                // class java/lang/CharSequence
     110: iconst_1
     111: anewarray     #155                // class java/lang/String
     114: astore        11
     116: aload         11
     118: iconst_0
     119: ldc           #157                // String ,
     121: aastore
     122: aload         11
     124: iconst_0
     125: iconst_0
     126: bipush        6
     128: aconst_null
     129: invokestatic  #163                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     132: checkcast     #30                 // class java/lang/Iterable
     135: astore        11
     137: iconst_0
     138: istore        12
     140: aload         11
     142: astore        13
     144: new           #32                 // class java/util/ArrayList
     147: dup
     148: aload         11
     150: bipush        10
     152: invokestatic  #167                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     155: invokespecial #169                // Method java/util/ArrayList."<init>":(I)V
     158: checkcast     #35                 // class java/util/Collection
     161: astore        14
     163: iconst_0
     164: istore        15
     166: aload         13
     168: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     173: astore        16
     175: aload         16
     177: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     182: ifeq          229
     185: aload         16
     187: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     192: astore        17
     194: aload         14
     196: aload         17
     198: checkcast     #155                // class java/lang/String
     201: astore        18
     203: astore        19
     205: iconst_0
     206: istore        20
     208: aload         18
     210: invokestatic  #175                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     213: nop
     214: invokestatic  #179                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     217: aload         19
     219: swap
     220: invokeinterface #64,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     225: pop
     226: goto          175
     229: aload         14
     231: checkcast     #66                 // class java/util/List
     234: nop
     235: nop
     236: astore        7
     238: aload         5
     240: aload         6
     242: invokestatic  #185                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     245: aload         7
     247: goto          271
     250: astore        8
     252: aload         8
     254: astore        6
     256: aload         8
     258: athrow
     259: astore        8
     261: aload         5
     263: aload         6
     265: invokestatic  #185                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     268: aload         8
     270: athrow
     271: nop
     272: areturn
    Exception table:
       from    to  target type
          81   238   250   Class java/lang/Throwable
          81   238   259   any
         250   259   259   any
         259   261   259   any

  private final java.util.List<adventofcode.PuzzleDay04$BingoBoard> readBoards(java.io.File);
    Code:
       0: aload_1
       1: astore_2
       2: getstatic     #118                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
       5: astore_3
       6: iconst_0
       7: istore        4
       9: aload_2
      10: astore        5
      12: sipush        8192
      15: istore        6
      17: aload         5
      19: astore        7
      21: new           #120                // class java/io/InputStreamReader
      24: dup
      25: new           #122                // class java/io/FileInputStream
      28: dup
      29: aload         7
      31: invokespecial #125                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      34: checkcast     #127                // class java/io/InputStream
      37: aload_3
      38: invokespecial #130                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      41: checkcast     #132                // class java/io/Reader
      44: astore        7
      46: aload         7
      48: instanceof    #134                // class java/io/BufferedReader
      51: ifeq          62
      54: aload         7
      56: checkcast     #134                // class java/io/BufferedReader
      59: goto          73
      62: new           #134                // class java/io/BufferedReader
      65: dup
      66: aload         7
      68: iload         6
      70: invokespecial #137                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      73: checkcast     #139                // class java/io/Closeable
      76: astore        5
      78: aconst_null
      79: astore        6
      81: nop
      82: aload         5
      84: checkcast     #134                // class java/io/BufferedReader
      87: astore        7
      89: iconst_0
      90: istore        8
      92: aload         7
      94: invokestatic  #145                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
      97: astore        9
      99: iconst_0
     100: istore        10
     102: aload         9
     104: iconst_2
     105: invokestatic  #209                // Method kotlin/sequences/SequencesKt.drop:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
     108: invokedynamic #228,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     113: invokestatic  #232                // Method kotlin/sequences/SequencesKt.flatMapIterable:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     116: invokedynamic #240,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
     121: invokestatic  #243                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     124: invokedynamic #250,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
     129: invokestatic  #253                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     132: bipush        25
     134: bipush        25
     136: iconst_0
     137: iconst_4
     138: aconst_null
     139: invokestatic  #257                // Method kotlin/sequences/SequencesKt.windowed$default:(Lkotlin/sequences/Sequence;IIZILjava/lang/Object;)Lkotlin/sequences/Sequence;
     142: invokedynamic #269,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function2;
     147: invokestatic  #273                // Method kotlin/sequences/SequencesKt.mapIndexed:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence;
     150: invokestatic  #277                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     153: astore        7
     155: aload         5
     157: aload         6
     159: invokestatic  #185                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     162: aload         7
     164: goto          188
     167: astore        8
     169: aload         8
     171: astore        6
     173: aload         8
     175: athrow
     176: astore        8
     178: aload         5
     180: aload         6
     182: invokestatic  #185                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     185: aload         8
     187: athrow
     188: nop
     189: areturn
    Exception table:
       from    to  target type
          81   155   167   Class java/lang/Throwable
          81   155   176   any
         167   176   176   any
         176   178   176   any

  private static final java.lang.Iterable readBoards$lambda$10$lambda$6(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #279                // String it
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #153                // class java/lang/CharSequence
      11: iconst_1
      12: anewarray     #155                // class java/lang/String
      15: astore_1
      16: aload_1
      17: iconst_0
      18: ldc_w         #281                // String
      21: aastore
      22: aload_1
      23: iconst_0
      24: iconst_0
      25: bipush        6
      27: aconst_null
      28: invokestatic  #163                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      31: checkcast     #30                 // class java/lang/Iterable
      34: areturn

  private static final boolean readBoards$lambda$10$lambda$7(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #279                // String it
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #153                // class java/lang/CharSequence
      11: invokeinterface #284,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      16: ifle          23
      19: iconst_1
      20: goto          24
      23: iconst_0
      24: ireturn

  private static final int readBoards$lambda$10$lambda$8(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #279                // String it
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokestatic  #175                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      11: ireturn

  private static final adventofcode.PuzzleDay04$BingoBoard readBoards$lambda$10$lambda$9(int, java.util.List);
    Code:
       0: aload_1
       1: ldc_w         #286                // String boardNumbers
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #57                 // class adventofcode/PuzzleDay04$BingoBoard
      10: dup
      11: iload_0
      12: iconst_1
      13: iadd
      14: aload_1
      15: checkcast     #35                 // class java/util/Collection
      18: invokestatic  #290                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
      21: invokespecial #293                // Method adventofcode/PuzzleDay04$BingoBoard."<init>":(I[I)V
      24: areturn
}


package adventofcode

import java.io.File
import kotlin.math.*

/**
 *
 * PART I
 * Interestingly enough, for any series of numbers in R^1 the central point that minimizes the sum of distances to each
 * other point is the median. In fact "The median minimizes the sum of absolute deviations". Until AoC 2021 I did not
 * realize that and wanted to see proof:
 *
 * A explanatory and a formal proof can be found here https://math.stackexchange.com/questions/113270/the-median-minimizes-the-sum-of-absolute-deviations-the-ell-1-norm
 * Also this paper https://tommasorigon.github.io/StatI/approfondimenti/Schwertman1990.pdf gives a similar proof
 *
 *
 * PART II
 * Mainly since the answer the first riddle was the median, I guessed, that the second might be the arithmetic average.
 * I still search for an explanation why this works and why we need to introduce the +.0.5 variance and why for some
 * it works without that adjustment. It might the difference between float and double based calculation
 *
 */
class PuzzleDay07 {

    fun findMostCentralPointForCrabsToRally(file: File, constantCost: Boolean): Pair<Int, Int> = file.useLines { seq ->
        return if (constantCost) findForConstantCostPerDistance(seq)
        else findForLinearIncreasingCostPerDistance(seq)
    }

    private fun findForConstantCostPerDistance(seq: Sequence<String>): Pair<Int, Int> {
        val crabPositions = seq.first().split(",").map { it.toInt() }.sorted()
        val medianIndex = crabPositions.size / 2
        val median = crabPositions[medianIndex]
        val sumOfDistances = crabPositions.fold(0) { sum, position -> sum + abs(position - median) }
        return median to sumOfDistances
    }

    private fun findForLinearIncreasingCostPerDistance(seq: Sequence<String>): Pair<Int, Int> {
        val crabPositions = seq.first().split(",").map { it.toInt() }
        val arithmeticAverage = crabPositions.average()
        val lowerBound = (arithmeticAverage - 0.5).roundToInt()
        val upperBound = (arithmeticAverage + 0.5).roundToInt()
        val resultLowerBound = calculateFuelUsage(crabPositions, lowerBound)
        val resultUpperBound = calculateFuelUsage(crabPositions, upperBound)
        return if (resultLowerBound.second < resultUpperBound.second) resultLowerBound else resultUpperBound
    }

    private fun calculateFuelUsage(crabPositions: List<Int>, rallyPoint: Int): Pair<Int, Int> {
        val fuelUsed = crabPositions.fold(0) { fuelAggregator, position ->
            val distance = abs(position - rallyPoint)
            val fuelConsumption = (0..distance).sum()
            fuelAggregator + fuelConsumption
        }
        return rallyPoint to fuelUsed
    }

}

Compiled from "PuzzleDay07.kt"
public final class adventofcode.PuzzleDay07 {
  public adventofcode.PuzzleDay07();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final kotlin.Pair<java.lang.Integer, java.lang.Integer> findMostCentralPointForCrabsToRally(java.io.File, boolean);
    Code:
       0: aload_1
       1: ldc           #18                 // String file
       3: invokestatic  #24                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: astore_3
       8: getstatic     #30                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      11: astore        4
      13: iconst_0
      14: istore        5
      16: aload_3
      17: astore        6
      19: sipush        8192
      22: istore        7
      24: aload         6
      26: astore        8
      28: new           #32                 // class java/io/InputStreamReader
      31: dup
      32: new           #34                 // class java/io/FileInputStream
      35: dup
      36: aload         8
      38: invokespecial #37                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      41: checkcast     #39                 // class java/io/InputStream
      44: aload         4
      46: invokespecial #42                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      49: checkcast     #44                 // class java/io/Reader
      52: astore        8
      54: aload         8
      56: instanceof    #46                 // class java/io/BufferedReader
      59: ifeq          70
      62: aload         8
      64: checkcast     #46                 // class java/io/BufferedReader
      67: goto          81
      70: new           #46                 // class java/io/BufferedReader
      73: dup
      74: aload         8
      76: iload         7
      78: invokespecial #49                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      81: checkcast     #51                 // class java/io/Closeable
      84: astore        6
      86: aconst_null
      87: astore        7
      89: nop
      90: aload         6
      92: checkcast     #46                 // class java/io/BufferedReader
      95: astore        8
      97: iconst_0
      98: istore        9
     100: aload         8
     102: invokestatic  #57                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     105: astore        10
     107: iconst_0
     108: istore        11
     110: iload_2
     111: ifeq          123
     114: aload_0
     115: aload         10
     117: invokespecial #61                 // Method findForConstantCostPerDistance:(Lkotlin/sequences/Sequence;)Lkotlin/Pair;
     120: goto          129
     123: aload_0
     124: aload         10
     126: invokespecial #64                 // Method findForLinearIncreasingCostPerDistance:(Lkotlin/sequences/Sequence;)Lkotlin/Pair;
     129: astore        12
     131: aload         6
     133: aload         7
     135: invokestatic  #70                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     138: aload         12
     140: areturn
     141: astore        9
     143: aload         9
     145: astore        7
     147: aload         9
     149: athrow
     150: astore        9
     152: aload         6
     154: aload         7
     156: invokestatic  #70                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     159: aload         9
     161: athrow
    Exception table:
       from    to  target type
          89   131   141   Class java/lang/Throwable
          89   131   150   any
         141   150   150   any
         150   152   150   any

  private final kotlin.Pair<java.lang.Integer, java.lang.Integer> findForConstantCostPerDistance(kotlin.sequences.Sequence<java.lang.String>);
    Code:
       0: aload_1
       1: invokestatic  #98                 // Method kotlin/sequences/SequencesKt.first:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
       4: checkcast     #100                // class java/lang/CharSequence
       7: iconst_1
       8: anewarray     #102                // class java/lang/String
      11: astore_3
      12: aload_3
      13: iconst_0
      14: ldc           #104                // String ,
      16: aastore
      17: aload_3
      18: iconst_0
      19: iconst_0
      20: bipush        6
      22: aconst_null
      23: invokestatic  #110                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      26: checkcast     #112                // class java/lang/Iterable
      29: astore_3
      30: iconst_0
      31: istore        4
      33: aload_3
      34: astore        5
      36: new           #114                // class java/util/ArrayList
      39: dup
      40: aload_3
      41: bipush        10
      43: invokestatic  #120                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      46: invokespecial #123                // Method java/util/ArrayList."<init>":(I)V
      49: checkcast     #125                // class java/util/Collection
      52: astore        6
      54: iconst_0
      55: istore        7
      57: aload         5
      59: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        8
      66: aload         8
      68: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         8
      78: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        9
      85: aload         6
      87: aload         9
      89: checkcast     #102                // class java/lang/String
      92: astore        10
      94: astore        15
      96: iconst_0
      97: istore        11
      99: aload         10
     101: invokestatic  #145                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         15
     110: swap
     111: invokeinterface #153,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         6
     122: checkcast     #155                // class java/util/List
     125: nop
     126: checkcast     #112                // class java/lang/Iterable
     129: invokestatic  #159                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     132: astore_2
     133: aload_2
     134: invokeinterface #163,  1          // InterfaceMethod java/util/List.size:()I
     139: iconst_2
     140: idiv
     141: istore_3
     142: aload_2
     143: iload_3
     144: invokeinterface #167,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     149: checkcast     #169                // class java/lang/Number
     152: invokevirtual #172                // Method java/lang/Number.intValue:()I
     155: istore        4
     157: aload_2
     158: checkcast     #112                // class java/lang/Iterable
     161: astore        6
     163: iconst_0
     164: istore        7
     166: iconst_0
     167: istore        8
     169: iload         7
     171: istore        9
     173: aload         6
     175: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     180: astore        10
     182: aload         10
     184: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     189: ifeq          234
     192: aload         10
     194: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     199: astore        11
     201: iload         9
     203: aload         11
     205: checkcast     #169                // class java/lang/Number
     208: invokevirtual #172                // Method java/lang/Number.intValue:()I
     211: istore        12
     213: istore        13
     215: iconst_0
     216: istore        14
     218: iload         13
     220: iload         12
     222: iload         4
     224: isub
     225: invokestatic  #178                // Method java/lang/Math.abs:(I)I
     228: iadd
     229: istore        9
     231: goto          182
     234: iload         9
     236: istore        5
     238: iload         4
     240: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     243: iload         5
     245: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     248: invokestatic  #184                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     251: areturn

  private final kotlin.Pair<java.lang.Integer, java.lang.Integer> findForLinearIncreasingCostPerDistance(kotlin.sequences.Sequence<java.lang.String>);
    Code:
       0: aload_1
       1: invokestatic  #98                 // Method kotlin/sequences/SequencesKt.first:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
       4: checkcast     #100                // class java/lang/CharSequence
       7: iconst_1
       8: anewarray     #102                // class java/lang/String
      11: astore_3
      12: aload_3
      13: iconst_0
      14: ldc           #104                // String ,
      16: aastore
      17: aload_3
      18: iconst_0
      19: iconst_0
      20: bipush        6
      22: aconst_null
      23: invokestatic  #110                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      26: checkcast     #112                // class java/lang/Iterable
      29: astore_3
      30: iconst_0
      31: istore        4
      33: aload_3
      34: astore        5
      36: new           #114                // class java/util/ArrayList
      39: dup
      40: aload_3
      41: bipush        10
      43: invokestatic  #120                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      46: invokespecial #123                // Method java/util/ArrayList."<init>":(I)V
      49: checkcast     #125                // class java/util/Collection
      52: astore        6
      54: iconst_0
      55: istore        7
      57: aload         5
      59: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        8
      66: aload         8
      68: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         8
      78: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        9
      85: aload         6
      87: aload         9
      89: checkcast     #102                // class java/lang/String
      92: astore        10
      94: astore        12
      96: iconst_0
      97: istore        11
      99: aload         10
     101: invokestatic  #145                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         12
     110: swap
     111: invokeinterface #153,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         6
     122: checkcast     #155                // class java/util/List
     125: nop
     126: astore_2
     127: aload_2
     128: checkcast     #112                // class java/lang/Iterable
     131: invokestatic  #213                // Method kotlin/collections/CollectionsKt.averageOfInt:(Ljava/lang/Iterable;)D
     134: dstore_3
     135: dload_3
     136: ldc2_w        #214                // double 0.5d
     139: dsub
     140: invokestatic  #221                // Method kotlin/math/MathKt.roundToInt:(D)I
     143: istore        5
     145: dload_3
     146: ldc2_w        #214                // double 0.5d
     149: dadd
     150: invokestatic  #221                // Method kotlin/math/MathKt.roundToInt:(D)I
     153: istore        6
     155: aload_0
     156: aload_2
     157: iload         5
     159: invokespecial #225                // Method calculateFuelUsage:(Ljava/util/List;I)Lkotlin/Pair;
     162: astore        7
     164: aload_0
     165: aload_2
     166: iload         6
     168: invokespecial #225                // Method calculateFuelUsage:(Ljava/util/List;I)Lkotlin/Pair;
     171: astore        8
     173: aload         7
     175: invokevirtual #228                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     178: checkcast     #169                // class java/lang/Number
     181: invokevirtual #172                // Method java/lang/Number.intValue:()I
     184: aload         8
     186: invokevirtual #228                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     189: checkcast     #169                // class java/lang/Number
     192: invokevirtual #172                // Method java/lang/Number.intValue:()I
     195: if_icmpge     203
     198: aload         7
     200: goto          205
     203: aload         8
     205: areturn

  private final kotlin.Pair<java.lang.Integer, java.lang.Integer> calculateFuelUsage(java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_1
       1: checkcast     #112                // class java/lang/Iterable
       4: astore        4
       6: iconst_0
       7: istore        5
       9: iconst_0
      10: istore        6
      12: iload         5
      14: istore        7
      16: aload         4
      18: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      23: astore        8
      25: aload         8
      27: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      32: ifeq          98
      35: aload         8
      37: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: astore        9
      44: iload         7
      46: aload         9
      48: checkcast     #169                // class java/lang/Number
      51: invokevirtual #172                // Method java/lang/Number.intValue:()I
      54: istore        10
      56: istore        11
      58: iconst_0
      59: istore        12
      61: iload         10
      63: iload_2
      64: isub
      65: invokestatic  #178                // Method java/lang/Math.abs:(I)I
      68: istore        13
      70: new           #239                // class kotlin/ranges/IntRange
      73: dup
      74: iconst_0
      75: iload         13
      77: invokespecial #242                // Method kotlin/ranges/IntRange."<init>":(II)V
      80: checkcast     #112                // class java/lang/Iterable
      83: invokestatic  #246                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      86: istore        14
      88: iload         11
      90: iload         14
      92: iadd
      93: istore        7
      95: goto          25
      98: iload         7
     100: istore_3
     101: iload_2
     102: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: iload_3
     106: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     109: invokestatic  #184                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     112: areturn
}


package adventofcode

import java.io.File

class PuzzleDay03(significantBits: Int) {

    private val histogramSize = significantBits * 2

    fun readGammaAndEpsilon(input: File): Pair<Int, Int> =
        input.useLines { bitsSequence ->
            val gammaBits = bitsSequence.deriveBitmask(true)
            val gamma = gammaBits.convertBitsToInt()
            val epsilon = gammaBits.flipBitmask().convertBitsToInt()
            gamma to epsilon
        }

    private fun Sequence<String>.deriveBitmask(mostCommonMode: Boolean) = calculateHistogramPerBitPosition()
        .collectBitmaskFromHistogram(mostCommonMode)

    private fun Sequence<String>.calculateHistogramPerBitPosition(): IntArray =
        fold(IntArray(histogramSize)) { histogram, bitString ->
            bitString.toCharArray().forEachIndexed { index, bit ->
                val histogramPos = if ('0' == bit) 2 * index else 2 * index + 1
                histogram[histogramPos]++
            }
            histogram
        }

    private fun IntArray.collectBitmaskFromHistogram(mostCommonMode: Boolean): CharArray =
        asIterable().windowed(2, 2).map {
            when (mostCommonMode) {
                true -> if (it[1] >= it[0]) '1' else '0'
                false -> if (it[1] < it[0]) '1' else '0'
            }
        }.toCharArray()

    private fun CharArray.flipBitmask(): CharArray = map { if (it == '0') '1' else '0' }.toCharArray()

    private fun CharArray.convertBitsToInt(): Int = fold(0) { int, bit ->
        val bitValue = if ('0' == bit) 0 else 1
        int * 2 + bitValue
    }

    fun readOxygenScrubberRatings(input: File): Int =
        readRatingForMode(input, true)

    fun readCO2ScrubberRatings(input: File): Int =
        readRatingForMode(input, false)

    fun readLifeSupportRating(file: File) = readOxygenScrubberRatings(file) * readCO2ScrubberRatings(file)

    private fun readRatingForMode(input: File, mostCommonMode: Boolean) =
        input.useLines { bitsSequence ->
            var filteredNumbers = bitsSequence.toList()
            var bitmask = filteredNumbers.asSequence().deriveBitmask(mostCommonMode)
            for (bitPosition in bitmask.indices) {
                filteredNumbers = filteredNumbers.filter { it[bitPosition] == bitmask[bitPosition] }
                if (filteredNumbers.count() == 1) break
                bitmask = filteredNumbers.asSequence().deriveBitmask(mostCommonMode)
            }
            filteredNumbers
        }.first().toCharArray().convertBitsToInt()

}

Compiled from "PuzzleDay03.kt"
public final class adventofcode.PuzzleDay03 {
  private final int histogramSize;

  public adventofcode.PuzzleDay03(int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: iconst_2
       7: imul
       8: putfield      #13                 // Field histogramSize:I
      11: return

  public final kotlin.Pair<java.lang.Integer, java.lang.Integer> readGammaAndEpsilon(java.io.File);
    Code:
       0: aload_1
       1: ldc           #24                 // String input
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: astore_2
       8: getstatic     #36                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      11: astore_3
      12: iconst_0
      13: istore        4
      15: aload_2
      16: astore        5
      18: sipush        8192
      21: istore        6
      23: aload         5
      25: astore        7
      27: new           #38                 // class java/io/InputStreamReader
      30: dup
      31: new           #40                 // class java/io/FileInputStream
      34: dup
      35: aload         7
      37: invokespecial #43                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      40: checkcast     #45                 // class java/io/InputStream
      43: aload_3
      44: invokespecial #48                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      47: checkcast     #50                 // class java/io/Reader
      50: astore        7
      52: aload         7
      54: instanceof    #52                 // class java/io/BufferedReader
      57: ifeq          68
      60: aload         7
      62: checkcast     #52                 // class java/io/BufferedReader
      65: goto          79
      68: new           #52                 // class java/io/BufferedReader
      71: dup
      72: aload         7
      74: iload         6
      76: invokespecial #55                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      79: checkcast     #57                 // class java/io/Closeable
      82: astore        5
      84: aconst_null
      85: astore        6
      87: nop
      88: aload         5
      90: checkcast     #52                 // class java/io/BufferedReader
      93: astore        7
      95: iconst_0
      96: istore        8
      98: aload         7
     100: invokestatic  #63                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     103: astore        9
     105: iconst_0
     106: istore        10
     108: aload_0
     109: aload         9
     111: iconst_1
     112: invokespecial #67                 // Method deriveBitmask:(Lkotlin/sequences/Sequence;Z)[C
     115: astore        11
     117: aload_0
     118: aload         11
     120: invokespecial #71                 // Method convertBitsToInt:([C)I
     123: istore        12
     125: aload_0
     126: aload_0
     127: aload         11
     129: invokespecial #75                 // Method flipBitmask:([C)[C
     132: invokespecial #71                 // Method convertBitsToInt:([C)I
     135: istore        13
     137: iload         12
     139: invokestatic  #81                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     142: iload         13
     144: invokestatic  #81                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     147: invokestatic  #87                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     150: astore        7
     152: aload         5
     154: aload         6
     156: invokestatic  #93                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     159: aload         7
     161: goto          185
     164: astore        8
     166: aload         8
     168: astore        6
     170: aload         8
     172: athrow
     173: astore        8
     175: aload         5
     177: aload         6
     179: invokestatic  #93                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     182: aload         8
     184: athrow
     185: nop
     186: areturn
    Exception table:
       from    to  target type
          87   152   164   Class java/lang/Throwable
          87   152   173   any
         164   173   173   any
         173   175   173   any

  private final char[] deriveBitmask(kotlin.sequences.Sequence<java.lang.String>, boolean);
    Code:
       0: aload_0
       1: aload_0
       2: aload_1
       3: invokespecial #121                // Method calculateHistogramPerBitPosition:(Lkotlin/sequences/Sequence;)[I
       6: iload_2
       7: invokespecial #125                // Method collectBitmaskFromHistogram:([IZ)[C
      10: areturn

  private final int[] calculateHistogramPerBitPosition(kotlin.sequences.Sequence<java.lang.String>);
    Code:
       0: aload_1
       1: astore_2
       2: aload_0
       3: getfield      #13                 // Field histogramSize:I
       6: newarray       int
       8: astore_3
       9: iconst_0
      10: istore        4
      12: aload_3
      13: astore        5
      15: aload_2
      16: invokeinterface #133,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      21: astore        6
      23: aload         6
      25: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          166
      33: aload         6
      35: invokeinterface #143,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      40: astore        7
      42: aload         5
      44: aload         7
      46: checkcast     #145                // class java/lang/String
      49: astore        8
      51: astore        9
      53: iconst_0
      54: istore        10
      56: aload         8
      58: invokevirtual #149                // Method java/lang/String.toCharArray:()[C
      61: dup
      62: ldc           #151                // String toCharArray(...)
      64: invokestatic  #154                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      67: astore        11
      69: nop
      70: iconst_0
      71: istore        12
      73: iconst_0
      74: istore        13
      76: iconst_0
      77: istore        14
      79: aload         11
      81: arraylength
      82: istore        15
      84: iload         14
      86: iload         15
      88: if_icmpge     158
      91: aload         11
      93: iload         14
      95: caload
      96: istore        16
      98: iload         13
     100: iinc          13, 1
     103: iload         16
     105: istore        17
     107: istore        18
     109: iconst_0
     110: istore        19
     112: bipush        48
     114: iload         17
     116: if_icmpne     126
     119: iconst_2
     120: iload         18
     122: imul
     123: goto          132
     126: iconst_2
     127: iload         18
     129: imul
     130: iconst_1
     131: iadd
     132: istore        20
     134: aload         9
     136: iload         20
     138: iaload
     139: istore        21
     141: aload         9
     143: iload         20
     145: iload         21
     147: iconst_1
     148: iadd
     149: iastore
     150: nop
     151: nop
     152: iinc          14, 1
     155: goto          84
     158: nop
     159: aload         9
     161: astore        5
     163: goto          23
     166: aload         5
     168: areturn

  private final char[] collectBitmaskFromHistogram(int[], boolean);
    Code:
       0: aload_1
       1: invokestatic  #182                // Method kotlin/collections/ArraysKt.asIterable:([I)Ljava/lang/Iterable;
       4: iconst_2
       5: iconst_2
       6: iconst_0
       7: iconst_4
       8: aconst_null
       9: invokestatic  #188                // Method kotlin/collections/CollectionsKt.windowed$default:(Ljava/lang/Iterable;IIZILjava/lang/Object;)Ljava/util/List;
      12: checkcast     #190                // class java/lang/Iterable
      15: astore_3
      16: iconst_0
      17: istore        4
      19: aload_3
      20: astore        5
      22: new           #192                // class java/util/ArrayList
      25: dup
      26: aload_3
      27: bipush        10
      29: invokestatic  #196                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      32: invokespecial #198                // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #200                // class java/util/Collection
      38: astore        6
      40: iconst_0
      41: istore        7
      43: aload         5
      45: invokeinterface #201,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        8
      52: aload         8
      54: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          205
      62: aload         8
      64: invokeinterface #143,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        9
      71: aload         6
      73: aload         9
      75: checkcast     #203                // class java/util/List
      78: astore        10
      80: astore        13
      82: iconst_0
      83: istore        11
      85: iload_2
      86: istore        12
      88: iload         12
      90: iconst_1
      91: if_icmpne     135
      94: aload         10
      96: iconst_1
      97: invokeinterface #207,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     102: checkcast     #209                // class java/lang/Number
     105: invokevirtual #213                // Method java/lang/Number.intValue:()I
     108: aload         10
     110: iconst_0
     111: invokeinterface #207,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     116: checkcast     #209                // class java/lang/Number
     119: invokevirtual #213                // Method java/lang/Number.intValue:()I
     122: if_icmplt     130
     125: bipush        49
     127: goto          189
     130: bipush        48
     132: goto          189
     135: iload         12
     137: ifne          181
     140: aload         10
     142: iconst_1
     143: invokeinterface #207,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     148: checkcast     #209                // class java/lang/Number
     151: invokevirtual #213                // Method java/lang/Number.intValue:()I
     154: aload         10
     156: iconst_0
     157: invokeinterface #207,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     162: checkcast     #209                // class java/lang/Number
     165: invokevirtual #213                // Method java/lang/Number.intValue:()I
     168: if_icmpge     176
     171: bipush        49
     173: goto          189
     176: bipush        48
     178: goto          189
     181: new           #215                // class kotlin/NoWhenBranchMatchedException
     184: dup
     185: invokespecial #216                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     188: athrow
     189: nop
     190: invokestatic  #221                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     193: aload         13
     195: swap
     196: invokeinterface #225,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     201: pop
     202: goto          52
     205: aload         6
     207: checkcast     #203                // class java/util/List
     210: nop
     211: checkcast     #200                // class java/util/Collection
     214: invokestatic  #228                // Method kotlin/collections/CollectionsKt.toCharArray:(Ljava/util/Collection;)[C
     217: areturn

  private final char[] flipBitmask(char[]);
    Code:
       0: aload_1
       1: astore_2
       2: iconst_0
       3: istore_3
       4: aload_2
       5: astore        4
       7: new           #192                // class java/util/ArrayList
      10: dup
      11: aload_2
      12: arraylength
      13: invokespecial #198                // Method java/util/ArrayList."<init>":(I)V
      16: checkcast     #200                // class java/util/Collection
      19: astore        5
      21: iconst_0
      22: istore        6
      24: iconst_0
      25: istore        7
      27: aload         4
      29: arraylength
      30: istore        8
      32: iload         7
      34: iload         8
      36: if_icmpge     89
      39: aload         4
      41: iload         7
      43: caload
      44: istore        9
      46: aload         5
      48: iload         9
      50: istore        10
      52: astore        12
      54: iconst_0
      55: istore        11
      57: iload         10
      59: bipush        48
      61: if_icmpne     69
      64: bipush        49
      66: goto          71
      69: bipush        48
      71: invokestatic  #221                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      74: aload         12
      76: swap
      77: invokeinterface #225,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      82: pop
      83: iinc          7, 1
      86: goto          32
      89: aload         5
      91: checkcast     #203                // class java/util/List
      94: nop
      95: checkcast     #200                // class java/util/Collection
      98: invokestatic  #228                // Method kotlin/collections/CollectionsKt.toCharArray:(Ljava/util/Collection;)[C
     101: areturn

  private final int convertBitsToInt(char[]);
    Code:
       0: aload_1
       1: astore_2
       2: iconst_0
       3: istore_3
       4: iconst_0
       5: istore        4
       7: iload_3
       8: istore        5
      10: iconst_0
      11: istore        6
      13: aload_2
      14: arraylength
      15: istore        7
      17: iload         6
      19: iload         7
      21: if_icmpge     70
      24: aload_2
      25: iload         6
      27: caload
      28: istore        8
      30: iload         5
      32: iload         8
      34: istore        9
      36: istore        10
      38: iconst_0
      39: istore        11
      41: bipush        48
      43: iload         9
      45: if_icmpne     52
      48: iconst_0
      49: goto          53
      52: iconst_1
      53: istore        12
      55: iload         10
      57: iconst_2
      58: imul
      59: iload         12
      61: iadd
      62: istore        5
      64: iinc          6, 1
      67: goto          17
      70: iload         5
      72: ireturn

  public final int readOxygenScrubberRatings(java.io.File);
    Code:
       0: aload_1
       1: ldc           #24                 // String input
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: iconst_1
       9: invokespecial #252                // Method readRatingForMode:(Ljava/io/File;Z)I
      12: ireturn

  public final int readCO2ScrubberRatings(java.io.File);
    Code:
       0: aload_1
       1: ldc           #24                 // String input
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: iconst_0
       9: invokespecial #252                // Method readRatingForMode:(Ljava/io/File;Z)I
      12: ireturn

  public final int readLifeSupportRating(java.io.File);
    Code:
       0: aload_1
       1: ldc_w         #256                // String file
       4: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: invokevirtual #258                // Method readOxygenScrubberRatings:(Ljava/io/File;)I
      12: aload_0
      13: aload_1
      14: invokevirtual #260                // Method readCO2ScrubberRatings:(Ljava/io/File;)I
      17: imul
      18: ireturn

  private final int readRatingForMode(java.io.File, boolean);
    Code:
       0: aload_0
       1: aload_1
       2: astore_3
       3: astore        25
       5: getstatic     #36                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
       8: astore        4
      10: iconst_0
      11: istore        5
      13: aload_3
      14: astore        6
      16: sipush        8192
      19: istore        7
      21: aload         6
      23: astore        8
      25: new           #38                 // class java/io/InputStreamReader
      28: dup
      29: new           #40                 // class java/io/FileInputStream
      32: dup
      33: aload         8
      35: invokespecial #43                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      38: checkcast     #45                 // class java/io/InputStream
      41: aload         4
      43: invokespecial #48                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      46: checkcast     #50                 // class java/io/Reader
      49: astore        8
      51: aload         8
      53: instanceof    #52                 // class java/io/BufferedReader
      56: ifeq          67
      59: aload         8
      61: checkcast     #52                 // class java/io/BufferedReader
      64: goto          78
      67: new           #52                 // class java/io/BufferedReader
      70: dup
      71: aload         8
      73: iload         7
      75: invokespecial #55                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      78: checkcast     #57                 // class java/io/Closeable
      81: astore        6
      83: aconst_null
      84: astore        7
      86: nop
      87: aload         6
      89: checkcast     #52                 // class java/io/BufferedReader
      92: astore        8
      94: iconst_0
      95: istore        9
      97: aload         8
      99: invokestatic  #63                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     102: astore        10
     104: iconst_0
     105: istore        11
     107: aload         10
     109: invokestatic  #266                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     112: astore        12
     114: aconst_null
     115: astore        13
     117: aload_0
     118: aload         12
     120: checkcast     #190                // class java/lang/Iterable
     123: invokestatic  #270                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     126: iload_2
     127: invokespecial #67                 // Method deriveBitmask:(Lkotlin/sequences/Sequence;Z)[C
     130: astore        13
     132: iconst_0
     133: istore        14
     135: aload         13
     137: arraylength
     138: istore        15
     140: iload         14
     142: iload         15
     144: if_icmpge     293
     147: aload         12
     149: checkcast     #190                // class java/lang/Iterable
     152: astore        16
     154: iconst_0
     155: istore        17
     157: aload         16
     159: astore        18
     161: new           #192                // class java/util/ArrayList
     164: dup
     165: invokespecial #271                // Method java/util/ArrayList."<init>":()V
     168: checkcast     #200                // class java/util/Collection
     171: astore        19
     173: iconst_0
     174: istore        20
     176: aload         18
     178: invokeinterface #201,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     183: astore        21
     185: aload         21
     187: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     192: ifeq          250
     195: aload         21
     197: invokeinterface #143,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     202: astore        22
     204: aload         22
     206: checkcast     #145                // class java/lang/String
     209: astore        23
     211: iconst_0
     212: istore        24
     214: aload         23
     216: iload         14
     218: invokevirtual #275                // Method java/lang/String.charAt:(I)C
     221: aload         13
     223: iload         14
     225: caload
     226: if_icmpne     233
     229: iconst_1
     230: goto          234
     233: iconst_0
     234: ifeq          185
     237: aload         19
     239: aload         22
     241: invokeinterface #225,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     246: pop
     247: goto          185
     250: aload         19
     252: checkcast     #203                // class java/util/List
     255: nop
     256: astore        12
     258: aload         12
     260: checkcast     #200                // class java/util/Collection
     263: invokeinterface #278,  1          // InterfaceMethod java/util/Collection.size:()I
     268: iconst_1
     269: if_icmpeq     293
     272: aload_0
     273: aload         12
     275: checkcast     #190                // class java/lang/Iterable
     278: invokestatic  #270                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     281: iload_2
     282: invokespecial #67                 // Method deriveBitmask:(Lkotlin/sequences/Sequence;Z)[C
     285: astore        13
     287: iinc          14, 1
     290: goto          140
     293: aload         12
     295: astore        8
     297: aload         6
     299: aload         7
     301: invokestatic  #93                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     304: aload         8
     306: goto          330
     309: astore        9
     311: aload         9
     313: astore        7
     315: aload         9
     317: athrow
     318: astore        9
     320: aload         6
     322: aload         7
     324: invokestatic  #93                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     327: aload         9
     329: athrow
     330: nop
     331: aload         25
     333: swap
     334: invokestatic  #282                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     337: checkcast     #145                // class java/lang/String
     340: invokevirtual #149                // Method java/lang/String.toCharArray:()[C
     343: dup
     344: ldc           #151                // String toCharArray(...)
     346: invokestatic  #154                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     349: invokespecial #71                 // Method convertBitsToInt:([C)I
     352: ireturn
    Exception table:
       from    to  target type
          86   297   309   Class java/lang/Throwable
          86   297   318   any
         309   318   318   any
         318   320   318   any
}