package com.codelicia.advent2021

class Day04(input: String) {
    private val newline = "\n"
    private val section = "\n\n"

    private val sections = input.split(section)

    private val draws = sections[0].trim().split(",").map(String::toInt)

    private val cards : List<BingoBoard> = buildList {
        for (i in 1 until sections.size) {
            val numbers = sections[i].split(newline).map { it.split(" ").filter(String::isNotBlank).map(String::toInt) }

            add(BingoBoard(numbers.map { row -> row.map { it to false } }))
        }
    }

    class BingoBoard(private var numbers: List<List<Pair<Int, Boolean>>>) {

        fun mark(number: Int) {
            numbers = numbers.map {
                it.map { pair ->
                    if (pair.first == number) pair.first to true else pair
                }
            }
        }

        fun unmarkedSum(): Int = numbers.flatten().filter { !it.second }.sumOf { it.first }

        fun hasBingo(): Boolean {
            val diagonal = List(numbers[0].size) { column -> List(numbers[0].size) { numbers[it][column] } }
            val merge = numbers + diagonal

           merge.forEach { row ->
                row.forEach { _ ->
                    if (row.count { it.second } == row.size) return true
                }
            }

            return false
        }
    }

    private fun cardsScore(): MutableSet<Pair<Int, Int>> {
        val cardsInBingoOrder = mutableSetOf<Pair<Int, Int>>()

        draws.forEach { numberCalled ->
            cards.forEach { it.mark(numberCalled) }

            val isBingo = cards.filter { it.hasBingo() }

            isBingo.forEach { card ->
                if (false == cardsInBingoOrder.map { it.first }.contains(card.hashCode())) {
                    cardsInBingoOrder.add(card.hashCode() to numberCalled * card.unmarkedSum())
                }
            }
        }
        return cardsInBingoOrder
    }

    fun part1(): Int = cardsScore().first().second

    fun part2(): Int = cardsScore().last().second
}

Compiled from "Day04.kt"
public final class com.codelicia.advent2021.Day04 {
  private final java.lang.String newline;

  private final java.lang.String section;

  private final java.util.List<java.lang.String> sections;

  private final java.util.List<java.lang.Integer> draws;

  private final java.util.List<com.codelicia.advent2021.Day04$BingoBoard> cards;

  public com.codelicia.advent2021.Day04(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String input
       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: ldc           #20                 // String \n
      13: putfield      #24                 // Field newline:Ljava/lang/String;
      16: aload_0
      17: ldc           #26                 // String \n\n
      19: putfield      #29                 // Field section:Ljava/lang/String;
      22: aload_0
      23: aload_1
      24: checkcast     #31                 // class java/lang/CharSequence
      27: iconst_1
      28: anewarray     #33                 // class java/lang/String
      31: astore_2
      32: aload_2
      33: iconst_0
      34: aload_0
      35: getfield      #29                 // Field section:Ljava/lang/String;
      38: aastore
      39: aload_2
      40: iconst_0
      41: iconst_0
      42: bipush        6
      44: aconst_null
      45: invokestatic  #39                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      48: putfield      #43                 // Field sections:Ljava/util/List;
      51: aload_0
      52: aload_0
      53: getfield      #43                 // Field sections:Ljava/util/List;
      56: iconst_0
      57: invokeinterface #49,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      62: checkcast     #33                 // class java/lang/String
      65: checkcast     #31                 // class java/lang/CharSequence
      68: invokestatic  #53                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      71: invokevirtual #57                 // Method java/lang/Object.toString:()Ljava/lang/String;
      74: checkcast     #31                 // class java/lang/CharSequence
      77: iconst_1
      78: anewarray     #33                 // class java/lang/String
      81: astore_2
      82: aload_2
      83: iconst_0
      84: ldc           #59                 // String ,
      86: aastore
      87: aload_2
      88: iconst_0
      89: iconst_0
      90: bipush        6
      92: aconst_null
      93: invokestatic  #39                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      96: checkcast     #61                 // class java/lang/Iterable
      99: astore_2
     100: astore        29
     102: iconst_0
     103: istore_3
     104: aload_2
     105: astore        4
     107: new           #63                 // class java/util/ArrayList
     110: dup
     111: aload_2
     112: bipush        10
     114: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     117: invokespecial #72                 // Method java/util/ArrayList."<init>":(I)V
     120: checkcast     #74                 // class java/util/Collection
     123: astore        5
     125: iconst_0
     126: istore        6
     128: aload         4
     130: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     135: astore        7
     137: aload         7
     139: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     144: ifeq          191
     147: aload         7
     149: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     154: astore        8
     156: aload         5
     158: aload         8
     160: checkcast     #33                 // class java/lang/String
     163: astore        9
     165: astore        30
     167: iconst_0
     168: istore        10
     170: aload         9
     172: invokestatic  #94                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     175: nop
     176: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     179: aload         30
     181: swap
     182: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     187: pop
     188: goto          137
     191: aload         5
     193: checkcast     #45                 // class java/util/List
     196: nop
     197: aload         29
     199: swap
     200: putfield      #105                // Field draws:Ljava/util/List;
     203: aload_0
     204: invokestatic  #109                // Method kotlin/collections/CollectionsKt.createListBuilder:()Ljava/util/List;
     207: astore_2
     208: aload_2
     209: astore_3
     210: astore        29
     212: iconst_0
     213: istore        4
     215: iconst_1
     216: istore        5
     218: aload_0
     219: getfield      #43                 // Field sections:Ljava/util/List;
     222: invokeinterface #113,  1          // InterfaceMethod java/util/List.size:()I
     227: istore        6
     229: iload         5
     231: iload         6
     233: if_icmpge     843
     236: aload_0
     237: getfield      #43                 // Field sections:Ljava/util/List;
     240: iload         5
     242: invokeinterface #49,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     247: checkcast     #31                 // class java/lang/CharSequence
     250: iconst_1
     251: anewarray     #33                 // class java/lang/String
     254: astore        7
     256: aload         7
     258: iconst_0
     259: aload_0
     260: getfield      #24                 // Field newline:Ljava/lang/String;
     263: aastore
     264: aload         7
     266: iconst_0
     267: iconst_0
     268: bipush        6
     270: aconst_null
     271: invokestatic  #39                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     274: checkcast     #61                 // class java/lang/Iterable
     277: astore        7
     279: iconst_0
     280: istore        8
     282: aload         7
     284: astore        9
     286: new           #63                 // class java/util/ArrayList
     289: dup
     290: aload         7
     292: bipush        10
     294: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     297: invokespecial #72                 // Method java/util/ArrayList."<init>":(I)V
     300: checkcast     #74                 // class java/util/Collection
     303: astore        10
     305: iconst_0
     306: istore        11
     308: aload         9
     310: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     315: astore        12
     317: aload         12
     319: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     324: ifeq          598
     327: aload         12
     329: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     334: astore        13
     336: aload         10
     338: aload         13
     340: checkcast     #33                 // class java/lang/String
     343: astore        14
     345: astore        15
     347: iconst_0
     348: istore        16
     350: aload         14
     352: checkcast     #31                 // class java/lang/CharSequence
     355: iconst_1
     356: anewarray     #33                 // class java/lang/String
     359: astore        17
     361: aload         17
     363: iconst_0
     364: ldc           #115                // String
     366: aastore
     367: aload         17
     369: iconst_0
     370: iconst_0
     371: bipush        6
     373: aconst_null
     374: invokestatic  #39                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     377: checkcast     #61                 // class java/lang/Iterable
     380: astore        17
     382: iconst_0
     383: istore        18
     385: aload         17
     387: astore        19
     389: new           #63                 // class java/util/ArrayList
     392: dup
     393: invokespecial #116                // Method java/util/ArrayList."<init>":()V
     396: checkcast     #74                 // class java/util/Collection
     399: astore        20
     401: iconst_0
     402: istore        21
     404: aload         19
     406: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     411: astore        22
     413: aload         22
     415: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     420: ifeq          475
     423: aload         22
     425: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     430: astore        23
     432: aload         23
     434: checkcast     #33                 // class java/lang/String
     437: astore        24
     439: iconst_0
     440: istore        25
     442: aload         24
     444: checkcast     #31                 // class java/lang/CharSequence
     447: invokestatic  #120                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
     450: ifne          457
     453: iconst_1
     454: goto          458
     457: iconst_0
     458: nop
     459: ifeq          413
     462: aload         20
     464: aload         23
     466: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     471: pop
     472: goto          413
     475: aload         20
     477: checkcast     #45                 // class java/util/List
     480: nop
     481: checkcast     #61                 // class java/lang/Iterable
     484: astore        17
     486: nop
     487: iconst_0
     488: istore        18
     490: aload         17
     492: astore        19
     494: new           #63                 // class java/util/ArrayList
     497: dup
     498: aload         17
     500: bipush        10
     502: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     505: invokespecial #72                 // Method java/util/ArrayList."<init>":(I)V
     508: checkcast     #74                 // class java/util/Collection
     511: astore        20
     513: iconst_0
     514: istore        21
     516: aload         19
     518: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     523: astore        22
     525: aload         22
     527: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     532: ifeq          579
     535: aload         22
     537: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     542: astore        23
     544: aload         20
     546: aload         23
     548: checkcast     #33                 // class java/lang/String
     551: astore        24
     553: astore        26
     555: iconst_0
     556: istore        25
     558: aload         24
     560: invokestatic  #94                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     563: nop
     564: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     567: aload         26
     569: swap
     570: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     575: pop
     576: goto          525
     579: aload         20
     581: checkcast     #45                 // class java/util/List
     584: nop
     585: nop
     586: aload         15
     588: swap
     589: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     594: pop
     595: goto          317
     598: aload         10
     600: checkcast     #45                 // class java/util/List
     603: nop
     604: astore        27
     606: aload_3
     607: aload         27
     609: checkcast     #61                 // class java/lang/Iterable
     612: astore        7
     614: astore        15
     616: iconst_0
     617: istore        8
     619: aload         7
     621: astore        9
     623: new           #63                 // class java/util/ArrayList
     626: dup
     627: aload         7
     629: bipush        10
     631: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     634: invokespecial #72                 // Method java/util/ArrayList."<init>":(I)V
     637: checkcast     #74                 // class java/util/Collection
     640: astore        10
     642: iconst_0
     643: istore        11
     645: aload         9
     647: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     652: astore        12
     654: aload         12
     656: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     661: ifeq          811
     664: aload         12
     666: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     671: astore        13
     673: aload         10
     675: aload         13
     677: checkcast     #45                 // class java/util/List
     680: astore        14
     682: astore        28
     684: iconst_0
     685: istore        16
     687: aload         14
     689: checkcast     #61                 // class java/lang/Iterable
     692: astore        17
     694: iconst_0
     695: istore        18
     697: aload         17
     699: astore        19
     701: new           #63                 // class java/util/ArrayList
     704: dup
     705: aload         17
     707: bipush        10
     709: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     712: invokespecial #72                 // Method java/util/ArrayList."<init>":(I)V
     715: checkcast     #74                 // class java/util/Collection
     718: astore        20
     720: iconst_0
     721: istore        21
     723: aload         19
     725: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     730: astore        22
     732: aload         22
     734: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     739: ifeq          792
     742: aload         22
     744: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     749: astore        23
     751: aload         20
     753: aload         23
     755: checkcast     #122                // class java/lang/Number
     758: invokevirtual #125                // Method java/lang/Number.intValue:()I
     761: istore        24
     763: astore        25
     765: iconst_0
     766: istore        26
     768: iload         24
     770: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     773: iconst_0
     774: invokestatic  #130                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     777: invokestatic  #136                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     780: aload         25
     782: swap
     783: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     788: pop
     789: goto          732
     792: aload         20
     794: checkcast     #45                 // class java/util/List
     797: nop
     798: nop
     799: aload         28
     801: swap
     802: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     807: pop
     808: goto          654
     811: aload         10
     813: checkcast     #45                 // class java/util/List
     816: nop
     817: aload         15
     819: swap
     820: astore        31
     822: new           #138                // class com/codelicia/advent2021/Day04$BingoBoard
     825: dup
     826: aload         31
     828: invokespecial #141                // Method com/codelicia/advent2021/Day04$BingoBoard."<init>":(Ljava/util/List;)V
     831: invokeinterface #142,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     836: pop
     837: iinc          5, 1
     840: goto          229
     843: nop
     844: aload         29
     846: aload_2
     847: invokestatic  #146                // Method kotlin/collections/CollectionsKt.build:(Ljava/util/List;)Ljava/util/List;
     850: putfield      #149                // Field cards:Ljava/util/List;
     853: return

  private final java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>> cardsScore();
    Code:
       0: new           #184                // class java/util/LinkedHashSet
       3: dup
       4: invokespecial #185                // Method java/util/LinkedHashSet."<init>":()V
       7: checkcast     #187                // class java/util/Set
      10: astore_1
      11: aload_0
      12: getfield      #105                // Field draws:Ljava/util/List;
      15: checkcast     #61                 // class java/lang/Iterable
      18: astore_2
      19: iconst_0
      20: istore_3
      21: aload_2
      22: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      27: astore        4
      29: aload         4
      31: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          443
      39: aload         4
      41: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        5
      48: aload         5
      50: checkcast     #122                // class java/lang/Number
      53: invokevirtual #125                // Method java/lang/Number.intValue:()I
      56: istore        6
      58: iconst_0
      59: istore        7
      61: aload_0
      62: getfield      #149                // Field cards:Ljava/util/List;
      65: checkcast     #61                 // class java/lang/Iterable
      68: astore        8
      70: iconst_0
      71: istore        9
      73: aload         8
      75: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      80: astore        10
      82: aload         10
      84: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      89: ifeq          122
      92: aload         10
      94: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      99: astore        11
     101: aload         11
     103: checkcast     #138                // class com/codelicia/advent2021/Day04$BingoBoard
     106: astore        12
     108: iconst_0
     109: istore        13
     111: aload         12
     113: iload         6
     115: invokevirtual #190                // Method com/codelicia/advent2021/Day04$BingoBoard.mark:(I)V
     118: nop
     119: goto          82
     122: nop
     123: aload_0
     124: getfield      #149                // Field cards:Ljava/util/List;
     127: checkcast     #61                 // class java/lang/Iterable
     130: astore        9
     132: iconst_0
     133: istore        10
     135: aload         9
     137: astore        11
     139: new           #63                 // class java/util/ArrayList
     142: dup
     143: invokespecial #116                // Method java/util/ArrayList."<init>":()V
     146: checkcast     #74                 // class java/util/Collection
     149: astore        12
     151: iconst_0
     152: istore        13
     154: aload         11
     156: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     161: astore        14
     163: aload         14
     165: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     170: ifeq          213
     173: aload         14
     175: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     180: astore        15
     182: aload         15
     184: checkcast     #138                // class com/codelicia/advent2021/Day04$BingoBoard
     187: astore        16
     189: iconst_0
     190: istore        17
     192: aload         16
     194: invokevirtual #193                // Method com/codelicia/advent2021/Day04$BingoBoard.hasBingo:()Z
     197: ifeq          163
     200: aload         12
     202: aload         15
     204: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     209: pop
     210: goto          163
     213: aload         12
     215: checkcast     #45                 // class java/util/List
     218: nop
     219: astore        8
     221: aload         8
     223: checkcast     #61                 // class java/lang/Iterable
     226: astore        9
     228: iconst_0
     229: istore        10
     231: aload         9
     233: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     238: astore        11
     240: aload         11
     242: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     247: ifeq          437
     250: aload         11
     252: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     257: astore        12
     259: aload         12
     261: checkcast     #138                // class com/codelicia/advent2021/Day04$BingoBoard
     264: astore        13
     266: iconst_0
     267: istore        14
     269: iconst_0
     270: aload_1
     271: checkcast     #61                 // class java/lang/Iterable
     274: astore        15
     276: istore        16
     278: iconst_0
     279: istore        17
     281: aload         15
     283: astore        18
     285: new           #63                 // class java/util/ArrayList
     288: dup
     289: aload         15
     291: bipush        10
     293: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     296: invokespecial #72                 // Method java/util/ArrayList."<init>":(I)V
     299: checkcast     #74                 // class java/util/Collection
     302: astore        19
     304: iconst_0
     305: istore        20
     307: aload         18
     309: invokeinterface #78,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     314: astore        21
     316: aload         21
     318: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     323: ifeq          375
     326: aload         21
     328: invokeinterface #88,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     333: astore        22
     335: aload         19
     337: aload         22
     339: checkcast     #195                // class kotlin/Pair
     342: astore        23
     344: astore        24
     346: iconst_0
     347: istore        25
     349: aload         23
     351: invokevirtual #198                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     354: checkcast     #122                // class java/lang/Number
     357: invokevirtual #125                // Method java/lang/Number.intValue:()I
     360: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     363: aload         24
     365: swap
     366: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     371: pop
     372: goto          316
     375: aload         19
     377: checkcast     #45                 // class java/util/List
     380: nop
     381: astore        24
     383: iload         16
     385: aload         24
     387: aload         13
     389: invokevirtual #201                // Method com/codelicia/advent2021/Day04$BingoBoard.hashCode:()I
     392: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     395: invokeinterface #204,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     400: if_icmpne     432
     403: aload_1
     404: aload         13
     406: invokevirtual #201                // Method com/codelicia/advent2021/Day04$BingoBoard.hashCode:()I
     409: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     412: iload         6
     414: aload         13
     416: invokevirtual #207                // Method com/codelicia/advent2021/Day04$BingoBoard.unmarkedSum:()I
     419: imul
     420: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     423: invokestatic  #136                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     426: invokeinterface #208,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     431: pop
     432: nop
     433: nop
     434: goto          240
     437: nop
     438: nop
     439: nop
     440: goto          29
     443: nop
     444: aload_1
     445: areturn

  public final int part1();
    Code:
       0: aload_0
       1: invokespecial #226                // Method cardsScore:()Ljava/util/Set;
       4: checkcast     #61                 // class java/lang/Iterable
       7: invokestatic  #230                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
      10: checkcast     #195                // class kotlin/Pair
      13: invokevirtual #233                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      16: checkcast     #122                // class java/lang/Number
      19: invokevirtual #125                // Method java/lang/Number.intValue:()I
      22: ireturn

  public final int part2();
    Code:
       0: aload_0
       1: invokespecial #226                // Method cardsScore:()Ljava/util/Set;
       4: checkcast     #61                 // class java/lang/Iterable
       7: invokestatic  #237                // Method kotlin/collections/CollectionsKt.last:(Ljava/lang/Iterable;)Ljava/lang/Object;
      10: checkcast     #195                // class kotlin/Pair
      13: invokevirtual #233                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      16: checkcast     #122                // class java/lang/Number
      19: invokevirtual #125                // Method java/lang/Number.intValue:()I
      22: ireturn
}

Compiled from "Day04.kt"
public final class com.codelicia.advent2021.Day04$BingoBoard {
  private java.util.List<? extends java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Boolean>>> numbers;

  public com.codelicia.advent2021.Day04$BingoBoard(java.util.List<? extends java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Boolean>>>);
    Code:
       0: aload_1
       1: ldc           #10                 // String numbers
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #22                 // Field numbers:Ljava/util/List;
      15: return

  public final void mark(int);
    Code:
       0: aload_0
       1: aload_0
       2: getfield      #22                 // Field numbers:Ljava/util/List;
       5: checkcast     #28                 // class java/lang/Iterable
       8: astore_2
       9: astore        21
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #30                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #40                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          220
      56: aload         7
      58: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #56                 // class java/util/List
      72: astore        9
      74: astore        22
      76: iconst_0
      77: istore        10
      79: aload         9
      81: checkcast     #28                 // class java/lang/Iterable
      84: astore        11
      86: iconst_0
      87: istore        12
      89: aload         11
      91: astore        13
      93: new           #30                 // class java/util/ArrayList
      96: dup
      97: aload         11
      99: bipush        10
     101: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     104: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     107: checkcast     #40                 // class java/util/Collection
     110: astore        14
     112: iconst_0
     113: istore        15
     115: aload         13
     117: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     122: astore        16
     124: aload         16
     126: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     131: ifeq          201
     134: aload         16
     136: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     141: astore        17
     143: aload         14
     145: aload         17
     147: checkcast     #58                 // class kotlin/Pair
     150: astore        18
     152: astore        19
     154: iconst_0
     155: istore        20
     157: aload         18
     159: invokevirtual #61                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     162: checkcast     #63                 // class java/lang/Number
     165: invokevirtual #67                 // Method java/lang/Number.intValue:()I
     168: iload_1
     169: if_icmpne     187
     172: aload         18
     174: invokevirtual #61                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     177: iconst_1
     178: invokestatic  #73                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     181: invokestatic  #79                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     184: goto          189
     187: aload         18
     189: aload         19
     191: swap
     192: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     197: pop
     198: goto          124
     201: aload         14
     203: checkcast     #56                 // class java/util/List
     206: nop
     207: nop
     208: aload         22
     210: swap
     211: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     216: pop
     217: goto          46
     220: aload         5
     222: checkcast     #56                 // class java/util/List
     225: nop
     226: aload         21
     228: swap
     229: putfield      #22                 // Field numbers:Ljava/util/List;
     232: return

  public final int unmarkedSum();
    Code:
       0: aload_0
       1: getfield      #22                 // Field numbers:Ljava/util/List;
       4: checkcast     #28                 // class java/lang/Iterable
       7: invokestatic  #104                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
      10: checkcast     #28                 // class java/lang/Iterable
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_1
      17: astore_3
      18: new           #30                 // class java/util/ArrayList
      21: dup
      22: invokespecial #105                // Method java/util/ArrayList."<init>":()V
      25: checkcast     #40                 // class java/util/Collection
      28: astore        4
      30: iconst_0
      31: istore        5
      33: aload_3
      34: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        6
      41: aload         6
      43: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          105
      51: aload         6
      53: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        7
      60: aload         7
      62: checkcast     #58                 // class kotlin/Pair
      65: astore        8
      67: iconst_0
      68: istore        9
      70: aload         8
      72: invokevirtual #108                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      75: checkcast     #69                 // class java/lang/Boolean
      78: invokevirtual #111                // Method java/lang/Boolean.booleanValue:()Z
      81: ifne          88
      84: iconst_1
      85: goto          89
      88: iconst_0
      89: ifeq          41
      92: aload         4
      94: aload         7
      96: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     101: pop
     102: goto          41
     105: aload         4
     107: checkcast     #56                 // class java/util/List
     110: nop
     111: checkcast     #28                 // class java/lang/Iterable
     114: astore_1
     115: iconst_0
     116: istore_2
     117: aload_1
     118: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     123: astore_3
     124: aload_3
     125: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     130: ifeq          176
     133: aload_3
     134: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     139: astore        4
     141: iload_2
     142: aload         4
     144: checkcast     #58                 // class kotlin/Pair
     147: astore        5
     149: istore        10
     151: iconst_0
     152: istore        6
     154: aload         5
     156: invokevirtual #61                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     159: checkcast     #63                 // class java/lang/Number
     162: invokevirtual #67                 // Method java/lang/Number.intValue:()I
     165: istore        11
     167: iload         10
     169: iload         11
     171: iadd
     172: istore_2
     173: goto          124
     176: iload_2
     177: ireturn

  public final boolean hasBingo();
    Code:
       0: aload_0
       1: getfield      #22                 // Field numbers:Ljava/util/List;
       4: iconst_0
       5: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      10: checkcast     #56                 // class java/util/List
      13: invokeinterface #126,  1          // InterfaceMethod java/util/List.size:()I
      18: istore_2
      19: new           #30                 // class java/util/ArrayList
      22: dup
      23: iload_2
      24: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
      27: astore_3
      28: iconst_0
      29: istore        4
      31: iload         4
      33: iload_2
      34: if_icmpge     163
      37: iload         4
      39: istore        5
      41: aload_3
      42: iload         5
      44: istore        6
      46: astore        21
      48: iconst_0
      49: istore        7
      51: aload_0
      52: getfield      #22                 // Field numbers:Ljava/util/List;
      55: iconst_0
      56: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      61: checkcast     #56                 // class java/util/List
      64: invokeinterface #126,  1          // InterfaceMethod java/util/List.size:()I
      69: istore        8
      71: new           #30                 // class java/util/ArrayList
      74: dup
      75: iload         8
      77: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
      80: astore        9
      82: iconst_0
      83: istore        10
      85: iload         10
      87: iload         8
      89: if_icmpge     144
      92: iload         10
      94: istore        11
      96: aload         9
      98: iload         11
     100: istore        12
     102: astore        13
     104: iconst_0
     105: istore        14
     107: aload_0
     108: getfield      #22                 // Field numbers:Ljava/util/List;
     111: iload         12
     113: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     118: checkcast     #56                 // class java/util/List
     121: iload         6
     123: invokeinterface #123,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     128: checkcast     #58                 // class kotlin/Pair
     131: aload         13
     133: swap
     134: invokevirtual #127                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     137: pop
     138: iinc          10, 1
     141: goto          85
     144: aload         9
     146: checkcast     #56                 // class java/util/List
     149: nop
     150: aload         21
     152: swap
     153: invokevirtual #127                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     156: pop
     157: iinc          4, 1
     160: goto          31
     163: aload_3
     164: checkcast     #56                 // class java/util/List
     167: astore_1
     168: aload_0
     169: getfield      #22                 // Field numbers:Ljava/util/List;
     172: checkcast     #40                 // class java/util/Collection
     175: aload_1
     176: checkcast     #28                 // class java/lang/Iterable
     179: invokestatic  #131                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     182: astore_2
     183: aload_2
     184: checkcast     #28                 // class java/lang/Iterable
     187: astore_3
     188: iconst_0
     189: istore        4
     191: aload_3
     192: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     197: astore        5
     199: aload         5
     201: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     206: ifeq          404
     209: aload         5
     211: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     216: astore        6
     218: aload         6
     220: checkcast     #56                 // class java/util/List
     223: astore        7
     225: iconst_0
     226: istore        8
     228: aload         7
     230: checkcast     #28                 // class java/lang/Iterable
     233: astore        9
     235: iconst_0
     236: istore        10
     238: aload         9
     240: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     245: astore        11
     247: aload         11
     249: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     254: ifeq          398
     257: aload         11
     259: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     264: astore        12
     266: aload         12
     268: checkcast     #58                 // class kotlin/Pair
     271: pop
     272: iconst_0
     273: istore        13
     275: aload         7
     277: checkcast     #28                 // class java/lang/Iterable
     280: astore        14
     282: iconst_0
     283: istore        15
     285: aload         14
     287: instanceof    #40                 // class java/util/Collection
     290: ifeq          310
     293: aload         14
     295: checkcast     #40                 // class java/util/Collection
     298: invokeinterface #134,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     303: ifeq          310
     306: iconst_0
     307: goto          381
     310: iconst_0
     311: istore        16
     313: aload         14
     315: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     320: astore        17
     322: aload         17
     324: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     329: ifeq          379
     332: aload         17
     334: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     339: astore        18
     341: aload         18
     343: checkcast     #58                 // class kotlin/Pair
     346: astore        19
     348: iconst_0
     349: istore        20
     351: aload         19
     353: invokevirtual #108                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     356: checkcast     #69                 // class java/lang/Boolean
     359: invokevirtual #111                // Method java/lang/Boolean.booleanValue:()Z
     362: ifeq          322
     365: iinc          16, 1
     368: iload         16
     370: ifge          322
     373: invokestatic  #137                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     376: goto          322
     379: iload         16
     381: aload         7
     383: invokeinterface #126,  1          // InterfaceMethod java/util/List.size:()I
     388: if_icmpne     393
     391: iconst_1
     392: ireturn
     393: nop
     394: nop
     395: goto          247
     398: nop
     399: nop
     400: nop
     401: goto          199
     404: nop
     405: iconst_0
     406: ireturn
}


package utils

import java.math.BigDecimal

class BBSAnalyzer {
    fun countOnes(bbs: String): Int = bbs.count { c: Char ->  c == '1'}

    fun countSeries(bbs: String, character: Char): Map<Int, Int> {
        val occurrencesMap: MutableMap<Int, Int> = initializeOccurrencesMap()
        var lastFoundChar: Char = 'x'
        var counter: Int = 0
        var position: Int = 0
        bbs.forEach { char: Char ->
            if ((char == lastFoundChar) and (position != bbs.length - 1)) {
                counter++
            } else if ((char == lastFoundChar) and (position == bbs.length - 1)) {
                val flattenCounter = flatCounter(++counter)
                if (lastFoundChar == character) {
                    incrementOccurrencesMap(occurrencesMap, flattenCounter)
                }
                counter = 0
            } else if ((char != lastFoundChar) and (position == bbs.length - 1)) {
                val flattenCounter = flatCounter(counter)
                if (lastFoundChar == character) {
                    incrementOccurrencesMap(occurrencesMap, flattenCounter)
                }
                counter = 1
                if (char == character) {
                    incrementOccurrencesMap(occurrencesMap, counter)
                }
            } else {
                val flattenCounter = flatCounter(counter)
                if ((position != 0) and (lastFoundChar == character)) {
                    incrementOccurrencesMap(occurrencesMap, flattenCounter)
                }
                lastFoundChar = char
                counter = 1
            }
            position++
        }
        return occurrencesMap
    }

    fun checkIfLongSeriesExists(bbs: String): Boolean {
        var counter: Int = 0
        var lastFoundChar: Char = 'x'
        bbs.forEach { char -> Char
            counter = if (lastFoundChar == char) counter++ else 0
        }
        return counter >= 26
    }

    fun pokerize(bbs: String): Map<String, Int> {
        val partitions: List<String> = divideStringIntoPartitions(bbs)
        return groupPartitions(partitions)
    }

    fun calculatePokerScore(partitions: Map<String, Int>): BigDecimal {
        val fraction = BigDecimal(16).divide(BigDecimal(5000))
        return partitions.values
            .sumOf { Math.pow(it.toDouble(), 2.0) }.toBigDecimal()
            .multiply(fraction)
            .minus(BigDecimal(5000))
    }

    private fun divideStringIntoPartitions(input: String): List<String> = input.chunked(4)

    private fun groupPartitions(partitions: List<String>): Map<String, Int> =
        partitions
            .groupBy { it }
            .mapValues { it.value.size }

    private fun flatCounter(counter: Int): Int = if (counter < 6) counter else 6

    private fun incrementOccurrencesMap(occurrencesMap: MutableMap<Int, Int>, counter: Int) {
        occurrencesMap.merge(counter, 1, Int::plus)
    }

    private fun initializeOccurrencesMap() = mutableMapOf(
        1 to 0,
        2 to 0,
        3 to 0,
        4 to 0,
        5 to 0,
        6 to 0
    )
}

Compiled from "BBSAnalyzer.kt"
final class utils.BBSAnalyzer$incrementOccurrencesMap$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<java.lang.Integer, java.lang.Integer, java.lang.Integer> {
  public static final utils.BBSAnalyzer$incrementOccurrencesMap$1 INSTANCE;

  utils.BBSAnalyzer$incrementOccurrencesMap$1();
    Code:
       0: aload_0
       1: iconst_2
       2: getstatic     #15                 // Field java/lang/Integer.TYPE:Ljava/lang/Class;
       5: ldc           #17                 // String plus
       7: ldc           #19                 // String plus(I)I
       9: iconst_0
      10: invokespecial #22                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Integer invoke(int, int);
    Code:
       0: iload_1
       1: iload_2
       2: iadd
       3: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       6: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #36                 // class java/lang/Number
       5: invokevirtual #40                 // Method java/lang/Number.intValue:()I
       8: aload_2
       9: checkcast     #36                 // class java/lang/Number
      12: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      15: invokevirtual #42                 // Method invoke:(II)Ljava/lang/Integer;
      18: areturn

  static {};
    Code:
       0: new           #2                  // class utils/BBSAnalyzer$incrementOccurrencesMap$1
       3: dup
       4: invokespecial #47                 // Method "<init>":()V
       7: putstatic     #50                 // Field INSTANCE:Lutils/BBSAnalyzer$incrementOccurrencesMap$1;
      10: return
}

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

  public final int countOnes(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String bbs
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #23                 // class java/lang/CharSequence
      10: astore_2
      11: iconst_0
      12: istore_3
      13: iconst_0
      14: istore        4
      16: iconst_0
      17: istore        5
      19: iload         5
      21: aload_2
      22: invokeinterface #27,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      27: if_icmpge     71
      30: aload_2
      31: iload         5
      33: invokeinterface #31,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      38: istore        6
      40: iload         6
      42: istore        7
      44: iconst_0
      45: istore        8
      47: iload         7
      49: bipush        49
      51: if_icmpne     58
      54: iconst_1
      55: goto          59
      58: iconst_0
      59: ifeq          65
      62: iinc          4, 1
      65: iinc          5, 1
      68: goto          19
      71: iload         4
      73: ireturn

  public final java.util.Map<java.lang.Integer, java.lang.Integer> countSeries(java.lang.String, char);
    Code:
       0: aload_1
       1: ldc           #15                 // String bbs
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #50                 // Method initializeOccurrencesMap:()Ljava/util/Map;
      10: astore_3
      11: iconst_0
      12: istore        4
      14: bipush        120
      16: istore        4
      18: iconst_0
      19: istore        5
      21: iconst_0
      22: istore        6
      24: aload_1
      25: checkcast     #23                 // class java/lang/CharSequence
      28: astore        7
      30: iconst_0
      31: istore        8
      33: iconst_0
      34: istore        9
      36: iload         9
      38: aload         7
      40: invokeinterface #27,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      45: if_icmpge     312
      48: aload         7
      50: iload         9
      52: invokeinterface #31,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      57: istore        10
      59: iload         10
      61: istore        11
      63: iconst_0
      64: istore        12
      66: iload         11
      68: iload         4
      70: if_icmpne     77
      73: iconst_1
      74: goto          78
      77: iconst_0
      78: iload         6
      80: aload_1
      81: invokevirtual #51                 // Method java/lang/String.length:()I
      84: iconst_1
      85: isub
      86: if_icmpeq     93
      89: iconst_1
      90: goto          94
      93: iconst_0
      94: iand
      95: ifeq          114
      98: iload         5
     100: istore        13
     102: iload         13
     104: iconst_1
     105: iadd
     106: istore        5
     108: iload         13
     110: pop
     111: goto          298
     114: iload         11
     116: iload         4
     118: if_icmpne     125
     121: iconst_1
     122: goto          126
     125: iconst_0
     126: iload         6
     128: aload_1
     129: invokevirtual #51                 // Method java/lang/String.length:()I
     132: iconst_1
     133: isub
     134: if_icmpne     141
     137: iconst_1
     138: goto          142
     141: iconst_0
     142: iand
     143: ifeq          179
     146: aload_0
     147: iload         5
     149: iconst_1
     150: iadd
     151: istore        5
     153: iload         5
     155: invokespecial #55                 // Method flatCounter:(I)I
     158: istore        13
     160: iload         4
     162: iload_2
     163: if_icmpne     173
     166: aload_0
     167: aload_3
     168: iload         13
     170: invokespecial #59                 // Method incrementOccurrencesMap:(Ljava/util/Map;I)V
     173: iconst_0
     174: istore        5
     176: goto          298
     179: iload         11
     181: iload         4
     183: if_icmpeq     190
     186: iconst_1
     187: goto          191
     190: iconst_0
     191: iload         6
     193: aload_1
     194: invokevirtual #51                 // Method java/lang/String.length:()I
     197: iconst_1
     198: isub
     199: if_icmpne     206
     202: iconst_1
     203: goto          207
     206: iconst_0
     207: iand
     208: ifeq          251
     211: aload_0
     212: iload         5
     214: invokespecial #55                 // Method flatCounter:(I)I
     217: istore        13
     219: iload         4
     221: iload_2
     222: if_icmpne     232
     225: aload_0
     226: aload_3
     227: iload         13
     229: invokespecial #59                 // Method incrementOccurrencesMap:(Ljava/util/Map;I)V
     232: iconst_1
     233: istore        5
     235: iload         11
     237: iload_2
     238: if_icmpne     298
     241: aload_0
     242: aload_3
     243: iload         5
     245: invokespecial #59                 // Method incrementOccurrencesMap:(Ljava/util/Map;I)V
     248: goto          298
     251: aload_0
     252: iload         5
     254: invokespecial #55                 // Method flatCounter:(I)I
     257: istore        13
     259: iload         6
     261: ifeq          268
     264: iconst_1
     265: goto          269
     268: iconst_0
     269: iload         4
     271: iload_2
     272: if_icmpne     279
     275: iconst_1
     276: goto          280
     279: iconst_0
     280: iand
     281: ifeq          291
     284: aload_0
     285: aload_3
     286: iload         13
     288: invokespecial #59                 // Method incrementOccurrencesMap:(Ljava/util/Map;I)V
     291: iload         11
     293: istore        4
     295: iconst_1
     296: istore        5
     298: iload         6
     300: iconst_1
     301: iadd
     302: istore        6
     304: nop
     305: nop
     306: iinc          9, 1
     309: goto          36
     312: nop
     313: aload_3
     314: areturn

  public final boolean checkIfLongSeriesExists(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String bbs
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: bipush        120
      12: istore_3
      13: aload_1
      14: checkcast     #23                 // class java/lang/CharSequence
      17: astore        4
      19: iconst_0
      20: istore        5
      22: iconst_0
      23: istore        6
      25: iload         6
      27: aload         4
      29: invokeinterface #27,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      34: if_icmpge     88
      37: aload         4
      39: iload         6
      41: invokeinterface #31,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      46: istore        7
      48: iload         7
      50: istore        8
      52: iconst_0
      53: istore        9
      55: getstatic     #80                 // Field kotlin/jvm/internal/CharCompanionObject.INSTANCE:Lkotlin/jvm/internal/CharCompanionObject;
      58: pop
      59: iload_3
      60: iload         8
      62: if_icmpne     78
      65: iload_2
      66: istore        10
      68: iload         10
      70: iconst_1
      71: iadd
      72: istore_2
      73: iload         10
      75: goto          79
      78: iconst_0
      79: istore_2
      80: nop
      81: nop
      82: iinc          6, 1
      85: goto          25
      88: nop
      89: iconst_0
      90: ireturn

  public final java.util.Map<java.lang.String, java.lang.Integer> pokerize(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String bbs
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #88                 // Method divideStringIntoPartitions:(Ljava/lang/String;)Ljava/util/List;
      11: astore_2
      12: aload_0
      13: aload_2
      14: invokespecial #92                 // Method groupPartitions:(Ljava/util/List;)Ljava/util/Map;
      17: areturn

  public final java.math.BigDecimal calculatePokerScore(java.util.Map<java.lang.String, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #98                 // String partitions
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #100                // class java/math/BigDecimal
       9: dup
      10: bipush        16
      12: invokespecial #103                // Method java/math/BigDecimal."<init>":(I)V
      15: new           #100                // class java/math/BigDecimal
      18: dup
      19: sipush        5000
      22: invokespecial #103                // Method java/math/BigDecimal."<init>":(I)V
      25: invokevirtual #107                // Method java/math/BigDecimal.divide:(Ljava/math/BigDecimal;)Ljava/math/BigDecimal;
      28: astore_2
      29: aload_1
      30: invokeinterface #111,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      35: checkcast     #113                // class java/lang/Iterable
      38: astore        4
      40: dconst_0
      41: dstore        5
      43: aload         4
      45: invokeinterface #117,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        7
      52: aload         7
      54: invokeinterface #123,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          109
      62: aload         7
      64: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        8
      71: dload         5
      73: aload         8
      75: checkcast     #129                // class java/lang/Number
      78: invokevirtual #132                // Method java/lang/Number.intValue:()I
      81: istore        9
      83: dstore        11
      85: iconst_0
      86: istore        10
      88: iload         9
      90: i2d
      91: ldc2_w        #133                // double 2.0d
      94: invokestatic  #140                // Method java/lang/Math.pow:(DD)D
      97: dstore        13
      99: dload         11
     101: dload         13
     103: dadd
     104: dstore        5
     106: goto          52
     109: dload         5
     111: dstore        4
     113: new           #100                // class java/math/BigDecimal
     116: dup
     117: dload         4
     119: invokestatic  #144                // Method java/lang/String.valueOf:(D)Ljava/lang/String;
     122: invokespecial #147                // Method java/math/BigDecimal."<init>":(Ljava/lang/String;)V
     125: aload_2
     126: invokevirtual #150                // Method java/math/BigDecimal.multiply:(Ljava/math/BigDecimal;)Ljava/math/BigDecimal;
     129: dup
     130: ldc           #152                // String multiply(...)
     132: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     135: astore_3
     136: new           #100                // class java/math/BigDecimal
     139: dup
     140: sipush        5000
     143: invokespecial #103                // Method java/math/BigDecimal."<init>":(I)V
     146: aload_3
     147: swap
     148: invokevirtual #158                // Method java/math/BigDecimal.subtract:(Ljava/math/BigDecimal;)Ljava/math/BigDecimal;
     151: dup
     152: ldc           #160                // String subtract(...)
     154: invokestatic  #155                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     157: areturn

  private final java.util.List<java.lang.String> divideStringIntoPartitions(java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #23                 // class java/lang/CharSequence
       4: iconst_4
       5: invokestatic  #171                // Method kotlin/text/StringsKt.chunked:(Ljava/lang/CharSequence;I)Ljava/util/List;
       8: areturn

  private final java.util.Map<java.lang.String, java.lang.Integer> groupPartitions(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #113                // class java/lang/Iterable
       4: astore_2
       5: nop
       6: iconst_0
       7: istore_3
       8: aload_2
       9: astore        4
      11: new           #175                // class java/util/LinkedHashMap
      14: dup
      15: invokespecial #176                // Method java/util/LinkedHashMap."<init>":()V
      18: checkcast     #72                 // class java/util/Map
      21: astore        5
      23: iconst_0
      24: istore        6
      26: aload         4
      28: invokeinterface #117,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        7
      35: aload         7
      37: invokeinterface #123,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          144
      45: aload         7
      47: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        8
      54: aload         8
      56: checkcast     #43                 // class java/lang/String
      59: astore        9
      61: iconst_0
      62: istore        10
      64: aload         9
      66: astore        11
      68: aload         5
      70: astore        12
      72: iconst_0
      73: istore        13
      75: aload         12
      77: aload         11
      79: invokeinterface #180,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      84: astore        14
      86: aload         14
      88: ifnonnull     123
      91: iconst_0
      92: istore        15
      94: new           #182                // class java/util/ArrayList
      97: dup
      98: invokespecial #183                // Method java/util/ArrayList."<init>":()V
     101: checkcast     #185                // class java/util/List
     104: astore        15
     106: aload         12
     108: aload         11
     110: aload         15
     112: invokeinterface #189,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     117: pop
     118: aload         15
     120: goto          125
     123: aload         14
     125: nop
     126: checkcast     #185                // class java/util/List
     129: astore        9
     131: aload         9
     133: aload         8
     135: invokeinterface #193,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     140: pop
     141: goto          35
     144: aload         5
     146: nop
     147: astore_2
     148: nop
     149: iconst_0
     150: istore_3
     151: aload_2
     152: astore        4
     154: new           #175                // class java/util/LinkedHashMap
     157: dup
     158: aload_2
     159: invokeinterface #196,  1          // InterfaceMethod java/util/Map.size:()I
     164: invokestatic  #201                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     167: invokespecial #202                // Method java/util/LinkedHashMap."<init>":(I)V
     170: checkcast     #72                 // class java/util/Map
     173: astore        5
     175: iconst_0
     176: istore        6
     178: aload         4
     180: invokeinterface #206,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     185: checkcast     #113                // class java/lang/Iterable
     188: astore        7
     190: iconst_0
     191: istore        8
     193: aload         7
     195: invokeinterface #117,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     200: astore        9
     202: aload         9
     204: invokeinterface #123,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     209: ifeq          294
     212: aload         9
     214: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     219: astore        10
     221: aload         5
     223: aload         10
     225: checkcast     #208                // class java/util/Map$Entry
     228: astore        11
     230: astore        12
     232: iconst_0
     233: istore        13
     235: aload         11
     237: invokeinterface #211,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     242: aload         12
     244: swap
     245: aload         10
     247: checkcast     #208                // class java/util/Map$Entry
     250: astore        14
     252: astore        17
     254: astore        16
     256: iconst_0
     257: istore        15
     259: aload         14
     261: invokeinterface #214,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     266: checkcast     #185                // class java/util/List
     269: invokeinterface #215,  1          // InterfaceMethod java/util/List.size:()I
     274: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     277: astore        18
     279: aload         16
     281: aload         17
     283: aload         18
     285: invokeinterface #189,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     290: pop
     291: goto          202
     294: aload         5
     296: nop
     297: nop
     298: areturn

  private final int flatCounter(int);
    Code:
       0: iload_1
       1: bipush        6
       3: if_icmpge     10
       6: iload_1
       7: goto          12
      10: bipush        6
      12: ireturn

  private final void incrementOccurrencesMap(java.util.Map<java.lang.Integer, java.lang.Integer>, int);
    Code:
       0: aload_1
       1: iload_2
       2: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       5: iconst_1
       6: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       9: getstatic     #253                // Field utils/BBSAnalyzer$incrementOccurrencesMap$1.INSTANCE:Lutils/BBSAnalyzer$incrementOccurrencesMap$1;
      12: checkcast     #255                // class kotlin/jvm/functions/Function2
      15: invokedynamic #274,  0            // InvokeDynamic #0:apply:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiFunction;
      20: invokeinterface #278,  4          // InterfaceMethod java/util/Map.merge:(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;
      25: pop
      26: return

  private final java.util.Map<java.lang.Integer, java.lang.Integer> initializeOccurrencesMap();
    Code:
       0: bipush        6
       2: anewarray     #281                // class kotlin/Pair
       5: astore_1
       6: aload_1
       7: iconst_0
       8: iconst_1
       9: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      12: iconst_0
      13: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      16: invokestatic  #287                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      19: aastore
      20: aload_1
      21: iconst_1
      22: iconst_2
      23: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      26: iconst_0
      27: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      30: invokestatic  #287                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      33: aastore
      34: aload_1
      35: iconst_2
      36: iconst_3
      37: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: iconst_0
      41: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      44: invokestatic  #287                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      47: aastore
      48: aload_1
      49: iconst_3
      50: iconst_4
      51: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: iconst_0
      55: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      58: invokestatic  #287                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      61: aastore
      62: aload_1
      63: iconst_4
      64: iconst_5
      65: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      68: iconst_0
      69: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: invokestatic  #287                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      75: aastore
      76: aload_1
      77: iconst_5
      78: bipush        6
      80: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      83: iconst_0
      84: invokestatic  #220                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      87: invokestatic  #287                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      90: aastore
      91: aload_1
      92: invokestatic  #291                // Method kotlin/collections/MapsKt.mutableMapOf:([Lkotlin/Pair;)Ljava/util/Map;
      95: areturn

  private static final java.lang.Integer incrementOccurrencesMap$lambda$6(kotlin.jvm.functions.Function2, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokeinterface #294,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
       8: checkcast     #217                // class java/lang/Integer
      11: areturn
}


package com.kentvu.csproblems

import kotlin.reflect.full.hasAnnotation
import kotlin.reflect.full.memberFunctions

class Playground {
    @Target(AnnotationTarget.FUNCTION)
    annotation class AlgoFunction

    @OptIn(ExperimentalStdlibApi::class)
    val algos: List<String> get() {
        return Playground::class.memberFunctions.filter {
            it.hasAnnotation<AlgoFunction>()
        }.map { it.name }.toList()
    }

    // https://www.hackerrank.com/challenges/insertion-sort/problem
    @AlgoFunction
    fun insertionSortDec(arr: IntArray): Int {
        val max = arr.max()!!
        val bit = BIT(max)
        bit.update(arr[0], 1)
        var swaps = 0
        for (i in 1 until arr.size) {
            // Get count of elements smaller than arr[i]
            swaps += bit.sum(arr[i])
            bit.update(arr[i], 1)
        }
        return swaps
    }

    @AlgoFunction
    fun insertionSortAsc(arr: IntArray): Long {
        val max = arr.max()!!
        val bit = BIT(max)
        bit.update(arr[arr.lastIndex], 1)
        var swaps = 0L
        for (i in arr.lastIndex - 1 downTo 0) {
            swaps += bit.sum(arr[i] - 1) // Get count of elements smaller than arr[i]
            bit.update(arr[i], 1)
        }
        return swaps
    }

    fun invoke(algo: String, vararg args: Any?): Any? {
        return Playground::class.memberFunctions.first { it.name == algo }.run {
            call(this@Playground, *args)
        }
    }

}

class BIT(max: Int) {
    private val bit: Array<Int>

    init {
        //val max = arr.max()!!
        // build
        bit = Array(max + 1) { i -> 0 }
//        for (v in arr) {
//            bit[v]++
//        }
    }

    fun update(v: Int, inc: Int) {
        var index = v
        // Traverse all ancestors and add 'val'
        while (index <= bit.size - 1) {
            // Add 'val' to current node of BI Tree
            bit[index] += inc

            // Update index to that of parent in update View
            index += index and -index
        }
    }

    fun sum(v: Int): Int {
        var sum = 0 // Initialize result
        // Traverse ancestors of BITree[index]
        var index = v
        while (index > 0) {
            // Add current element of BITree to sum
            sum += bit[index]

            // Move index to parent node in getSum View
            index -= index and -index
        }
        return sum
    }

    fun mark(v: Int) {
        if (bit[v] == 0) {
            update(v, 1)
        }
    }
}

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

  public final java.util.List<java.lang.String> getAlgos();
    Code:
       0: ldc           #2                  // class com/kentvu/csproblems/Playground
       2: invokestatic  #20                 // Method kotlin/jvm/internal/Reflection.getOrCreateKotlinClass:(Ljava/lang/Class;)Lkotlin/reflect/KClass;
       5: invokestatic  #26                 // Method kotlin/reflect/full/KClasses.getMemberFunctions:(Lkotlin/reflect/KClass;)Ljava/util/Collection;
       8: checkcast     #28                 // class java/lang/Iterable
      11: astore_1
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #30                 // class java/util/ArrayList
      19: dup
      20: invokespecial #31                 // Method java/util/ArrayList."<init>":()V
      23: checkcast     #33                 // class java/util/Collection
      26: astore        4
      28: iconst_0
      29: istore        5
      31: aload_3
      32: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        6
      39: aload         6
      41: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          184
      49: aload         6
      51: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        7
      58: aload         7
      60: checkcast     #49                 // class kotlin/reflect/KFunction
      63: astore        8
      65: iconst_0
      66: istore        9
      68: aload         8
      70: checkcast     #51                 // class kotlin/reflect/KAnnotatedElement
      73: astore        10
      75: iconst_0
      76: istore        11
      78: aload         10
      80: astore        12
      82: iconst_0
      83: istore        13
      85: aload         12
      87: invokeinterface #54,  1           // InterfaceMethod kotlin/reflect/KAnnotatedElement.getAnnotations:()Ljava/util/List;
      92: checkcast     #28                 // class java/lang/Iterable
      95: astore        14
      97: iconst_0
      98: istore        15
     100: aload         14
     102: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     107: astore        16
     109: aload         16
     111: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     116: ifeq          151
     119: aload         16
     121: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     126: astore        17
     128: aload         17
     130: checkcast     #56                 // class java/lang/annotation/Annotation
     133: astore        18
     135: iconst_0
     136: istore        19
     138: aload         18
     140: instanceof    #58                 // class com/kentvu/csproblems/Playground$AlgoFunction
     143: ifeq          109
     146: aload         17
     148: goto          152
     151: aconst_null
     152: checkcast     #58                 // class com/kentvu/csproblems/Playground$AlgoFunction
     155: checkcast     #56                 // class java/lang/annotation/Annotation
     158: nop
     159: ifnull        166
     162: iconst_1
     163: goto          167
     166: iconst_0
     167: nop
     168: ifeq          39
     171: aload         4
     173: aload         7
     175: invokeinterface #62,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     180: pop
     181: goto          39
     184: aload         4
     186: checkcast     #64                 // class java/util/List
     189: nop
     190: checkcast     #28                 // class java/lang/Iterable
     193: astore_1
     194: nop
     195: iconst_0
     196: istore_2
     197: aload_1
     198: astore_3
     199: new           #30                 // class java/util/ArrayList
     202: dup
     203: aload_1
     204: bipush        10
     206: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     209: invokespecial #73                 // Method java/util/ArrayList."<init>":(I)V
     212: checkcast     #33                 // class java/util/Collection
     215: astore        4
     217: iconst_0
     218: istore        5
     220: aload_3
     221: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     226: astore        6
     228: aload         6
     230: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     235: ifeq          280
     238: aload         6
     240: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     245: astore        7
     247: aload         4
     249: aload         7
     251: checkcast     #49                 // class kotlin/reflect/KFunction
     254: astore        8
     256: astore        20
     258: iconst_0
     259: istore        9
     261: aload         8
     263: invokeinterface #77,  1           // InterfaceMethod kotlin/reflect/KFunction.getName:()Ljava/lang/String;
     268: aload         20
     270: swap
     271: invokeinterface #62,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     276: pop
     277: goto          228
     280: aload         4
     282: checkcast     #64                 // class java/util/List
     285: nop
     286: checkcast     #28                 // class java/lang/Iterable
     289: invokestatic  #81                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     292: areturn

  public static void getAlgos$annotations();
    Code:
       0: return

  public final int insertionSortDec(int[]);
    Code:
       0: aload_1
       1: ldc           #117                // String arr
       3: invokestatic  #123                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #128                // Method kotlin/collections/ArraysKt.maxOrThrow:([I)I
      10: istore_2
      11: new           #130                // class com/kentvu/csproblems/BIT
      14: dup
      15: iload_2
      16: invokespecial #131                // Method com/kentvu/csproblems/BIT."<init>":(I)V
      19: astore_3
      20: aload_3
      21: aload_1
      22: iconst_0
      23: iaload
      24: iconst_1
      25: invokevirtual #135                // Method com/kentvu/csproblems/BIT.update:(II)V
      28: iconst_0
      29: istore        4
      31: iconst_1
      32: istore        5
      34: aload_1
      35: arraylength
      36: istore        6
      38: iload         5
      40: iload         6
      42: if_icmpge     73
      45: iload         4
      47: aload_3
      48: aload_1
      49: iload         5
      51: iaload
      52: invokevirtual #139                // Method com/kentvu/csproblems/BIT.sum:(I)I
      55: iadd
      56: istore        4
      58: aload_3
      59: aload_1
      60: iload         5
      62: iaload
      63: iconst_1
      64: invokevirtual #135                // Method com/kentvu/csproblems/BIT.update:(II)V
      67: iinc          5, 1
      70: goto          38
      73: iload         4
      75: ireturn

  public final long insertionSortAsc(int[]);
    Code:
       0: aload_1
       1: ldc           #117                // String arr
       3: invokestatic  #123                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #128                // Method kotlin/collections/ArraysKt.maxOrThrow:([I)I
      10: istore_2
      11: new           #130                // class com/kentvu/csproblems/BIT
      14: dup
      15: iload_2
      16: invokespecial #131                // Method com/kentvu/csproblems/BIT."<init>":(I)V
      19: astore_3
      20: aload_3
      21: aload_1
      22: aload_1
      23: invokestatic  #151                // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      26: iaload
      27: iconst_1
      28: invokevirtual #135                // Method com/kentvu/csproblems/BIT.update:(II)V
      31: lconst_0
      32: lstore        4
      34: aload_1
      35: invokestatic  #151                // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      38: iconst_1
      39: isub
      40: istore        6
      42: iconst_m1
      43: iload         6
      45: if_icmpge     79
      48: lload         4
      50: aload_3
      51: aload_1
      52: iload         6
      54: iaload
      55: iconst_1
      56: isub
      57: invokevirtual #139                // Method com/kentvu/csproblems/BIT.sum:(I)I
      60: i2l
      61: ladd
      62: lstore        4
      64: aload_3
      65: aload_1
      66: iload         6
      68: iaload
      69: iconst_1
      70: invokevirtual #135                // Method com/kentvu/csproblems/BIT.update:(II)V
      73: iinc          6, -1
      76: goto          42
      79: lload         4
      81: lreturn

  public final java.lang.Object invoke(java.lang.String, java.lang.Object...);
    Code:
       0: aload_1
       1: ldc           #157                // String algo
       3: invokestatic  #123                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #159                // String args
       9: invokestatic  #123                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: ldc           #2                  // class com/kentvu/csproblems/Playground
      14: invokestatic  #20                 // Method kotlin/jvm/internal/Reflection.getOrCreateKotlinClass:(Ljava/lang/Class;)Lkotlin/reflect/KClass;
      17: invokestatic  #26                 // Method kotlin/reflect/full/KClasses.getMemberFunctions:(Lkotlin/reflect/KClass;)Ljava/util/Collection;
      20: checkcast     #28                 // class java/lang/Iterable
      23: astore_3
      24: iconst_0
      25: istore        4
      27: aload_3
      28: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        5
      35: aload         5
      37: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          83
      45: aload         5
      47: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        6
      54: aload         6
      56: checkcast     #49                 // class kotlin/reflect/KFunction
      59: astore        7
      61: iconst_0
      62: istore        8
      64: aload         7
      66: invokeinterface #77,  1           // InterfaceMethod kotlin/reflect/KFunction.getName:()Ljava/lang/String;
      71: aload_1
      72: invokestatic  #163                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      75: ifeq          35
      78: aload         6
      80: goto          93
      83: new           #165                // class java/util/NoSuchElementException
      86: dup
      87: ldc           #167                // String Collection contains no element matching the predicate.
      89: invokespecial #170                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
      92: athrow
      93: checkcast     #49                 // class kotlin/reflect/KFunction
      96: astore        4
      98: iconst_0
      99: istore        5
     101: aload         4
     103: new           #172                // class kotlin/jvm/internal/SpreadBuilder
     106: dup
     107: iconst_2
     108: invokespecial #173                // Method kotlin/jvm/internal/SpreadBuilder."<init>":(I)V
     111: astore        6
     113: aload         6
     115: aload_0
     116: invokevirtual #176                // Method kotlin/jvm/internal/SpreadBuilder.add:(Ljava/lang/Object;)V
     119: aload         6
     121: aload_2
     122: invokevirtual #179                // Method kotlin/jvm/internal/SpreadBuilder.addSpread:(Ljava/lang/Object;)V
     125: aload         6
     127: aload         6
     129: invokevirtual #183                // Method kotlin/jvm/internal/SpreadBuilder.size:()I
     132: anewarray     #4                  // class java/lang/Object
     135: invokevirtual #187                // Method kotlin/jvm/internal/SpreadBuilder.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     138: invokeinterface #191,  2          // InterfaceMethod kotlin/reflect/KFunction.call:([Ljava/lang/Object;)Ljava/lang/Object;
     143: nop
     144: areturn
}

Compiled from "Playground.kt"
public interface com.kentvu.csproblems.Playground$AlgoFunction extends java.lang.annotation.Annotation {
}


package com.arindam.kotlin.ds

/**
 * Kotlin program to find out all combinations of positive numbers that add up to given number.
 *
 * Created by <NAME> on 29/7/19.
 */

fun main() {
    val k = 5
    findCombinations(k)
}

/**
 * @param arr        array to store the combination
 * @param index      next location in array
 * @param num        given number
 * @param reducedNum reduced number
 */
fun findCombinationsUtil(arr: IntArray, index: Int, num: Int, reducedNum: Int) {

    // Base condition
    if (reducedNum < 0)
        return

    // If combination is
    // found, print it
    if (reducedNum == 0) {
        for (i in 0 until index)
            print(arr[i].toString() + " ")

        println()
        return
    }

    // Find the previous number
    // stored in arr[]. It helps
    // in maintaining increasing
    // order
    val prev = if (index == 0) 1 else arr[index - 1]

    // note loop starts from
    // previous number i.e. at
    // array location index - 1
    for (k in prev..num) {
        // next element of
        // array is k
        arr[index] = k

        // call recursively with
        // reduced number
        findCombinationsUtil(arr, index + 1, num, reducedNum - k)
    }
}

/**
 * Function to find out all combinations of positive numbers that add up to given number.
 * It uses findCombinationsUtil()
 *
 * @param n max n elements
 */
fun findCombinations(n: Int) {
    // array to store the combinations
    // It can contain max n elements
    val arr = IntArray(n)

    // find all combinations
    findCombinationsUtil(arr, 0, n, n)
}

Compiled from "GFG.kt"
public final class com.arindam.kotlin.ds.GFGKt {
  public static final void main();
    Code:
       0: iconst_5
       1: istore_0
       2: iload_0
       3: invokestatic  #10                 // Method findCombinations:(I)V
       6: return

  public static final void findCombinationsUtil(int[], int, int, int);
    Code:
       0: aload_0
       1: ldc           #17                 // String arr
       3: invokestatic  #23                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_3
       7: ifge          11
      10: return
      11: iload_3
      12: ifne          66
      15: iconst_0
      16: istore        4
      18: iload         4
      20: iload_1
      21: if_icmpge     59
      24: new           #25                 // class java/lang/StringBuilder
      27: dup
      28: invokespecial #28                 // Method java/lang/StringBuilder."<init>":()V
      31: aload_0
      32: iload         4
      34: iaload
      35: invokevirtual #32                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      38: bipush        32
      40: invokevirtual #35                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      43: invokevirtual #39                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      46: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
      49: swap
      50: invokevirtual #51                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      53: iinc          4, 1
      56: goto          18
      59: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: invokevirtual #54                 // Method java/io/PrintStream.println:()V
      65: return
      66: iload_1
      67: ifne          74
      70: iconst_1
      71: goto          79
      74: aload_0
      75: iload_1
      76: iconst_1
      77: isub
      78: iaload
      79: istore        4
      81: iload         4
      83: istore        5
      85: iload         5
      87: iload_2
      88: if_icmpgt     120
      91: aload_0
      92: iload_1
      93: iload         5
      95: iastore
      96: aload_0
      97: iload_1
      98: iconst_1
      99: iadd
     100: iload_2
     101: iload_3
     102: iload         5
     104: isub
     105: invokestatic  #56                 // Method findCombinationsUtil:([IIII)V
     108: iload         5
     110: iload_2
     111: if_icmpeq     120
     114: iinc          5, 1
     117: goto          91
     120: return

  public static final void findCombinations(int);
    Code:
       0: iload_0
       1: newarray       int
       3: astore_1
       4: aload_1
       5: iconst_0
       6: iload_0
       7: iload_0
       8: invokestatic  #56                 // Method findCombinationsUtil:([IIII)V
      11: return

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