package final_450.arrays

fun main() {

    val input = "23"
    val numbers = arrayOf<String>("123", "234", "567")
    val names = arrayOf<String>("chetan", "pokemon", "sokemon")

    val result = numbers
        .zip(names)
        .sortedBy { it.second }
        .firstOrNull {
            it.first.contains(input)
        } ?: "No Contact"

    println(result)

    val input0 = "00-44  48 5555 8361".apply { println(length % 2 == 0) }
    val input2 = "0 - 22 1985--324".trim().apply { println(length) } // even
    val result2 = input2.split("")
        .filter { it.toIntOrNull() != null }
        .chunked(3)
        .let {
            if (it.last().size == 1) {
                val newFormat = it.takeLast(2)
                    .joinToString("")
                    .split("")
                    .filter { it.toIntOrNull() != null }
                    .chunked(2)
                return@let it.dropLast(2) + newFormat
            }
            it
        }
        .joinToString(separator = "-") {
            it.joinToString(separator = "")
        }
    //022-198-53-24
    println(result2)

    val yearOfVacation: Int = 2014
    val startMonth: String = "April"
    val endMonth: String = "May"
    val dayOfWeek: String = "Wednesday"
    // answer = 7

    val holidays = getDays(startMonth, endMonth, yearOfVacation, dayOfWeek)
    println(holidays / 7)

    val target = 3
    val nodes1 = listOf(1, 3)
    val nodes2 = listOf(2, 2)
    val links = nodes1.zip(nodes2)
    val sorted = links.map {
        val (first,second) = it
        listOf(first,second).sorted()
    }
    println(sorted)

}

fun getDays(startMonth: String, endMonth: String, year: Int, startDay: String): Int {

    val weekIndex = listOf(
        "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
    )

    val monthIndex = listOf(
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December",
    )

    val dayInMonth = mapOf(
        "January" to 31,
        "February" to if (isLeapYear(year)) 29 else 28,
        "March" to 31,
        "April" to 30,
        "May" to 31,
        "June" to 30,
        "July" to 31,
        "August" to 31,
        "September" to 30,
        "October" to 31,
        "November" to 30,
        "December" to 31,
    )

    val indexOfStartMonth = monthIndex.indexOf(startMonth)
    val indexOfEndMonth = monthIndex.indexOf(endMonth)
    val result = (indexOfStartMonth..indexOfEndMonth).map {
        val month = monthIndex.get(it)
        dayInMonth.get(month) ?: 0
    }.sum()

    val startedOn = weekIndex.indexOf(startDay)

    return result - startedOn
}

fun isLeapYear(year: Int): Boolean {
    return when {
        year % 4 != 0 -> false
        year % 400 == 0 -> true
        else -> year % 100 != 0
    }
}

Compiled from "Comparisons.kt"
public final class final_450.arrays.ExamKt$main$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public final_450.arrays.ExamKt$main$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class kotlin/Pair
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      12: checkcast     #29                 // class java/lang/String
      15: checkcast     #31                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class kotlin/Pair
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      32: checkcast     #29                 // class java/lang/String
      35: aload         5
      37: swap
      38: checkcast     #31                 // class java/lang/Comparable
      41: invokestatic  #37                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}

Compiled from "exam.kt"
public final class final_450.arrays.ExamKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String 23
       2: astore_0
       3: iconst_3
       4: anewarray     #10                 // class java/lang/String
       7: astore_2
       8: aload_2
       9: iconst_0
      10: ldc           #12                 // String 123
      12: aastore
      13: aload_2
      14: iconst_1
      15: ldc           #14                 // String 234
      17: aastore
      18: aload_2
      19: iconst_2
      20: ldc           #16                 // String 567
      22: aastore
      23: aload_2
      24: astore_1
      25: iconst_3
      26: anewarray     #10                 // class java/lang/String
      29: astore_3
      30: aload_3
      31: iconst_0
      32: ldc           #18                 // String chetan
      34: aastore
      35: aload_3
      36: iconst_1
      37: ldc           #20                 // String pokemon
      39: aastore
      40: aload_3
      41: iconst_2
      42: ldc           #22                 // String sokemon
      44: aastore
      45: aload_3
      46: astore_2
      47: aload_1
      48: aload_2
      49: invokestatic  #28                 // Method kotlin/collections/ArraysKt.zip:([Ljava/lang/Object;[Ljava/lang/Object;)Ljava/util/List;
      52: checkcast     #30                 // class java/lang/Iterable
      55: astore        5
      57: nop
      58: iconst_0
      59: istore        6
      61: aload         5
      63: new           #32                 // class final_450/arrays/ExamKt$main$$inlined$sortedBy$1
      66: dup
      67: invokespecial #35                 // Method final_450/arrays/ExamKt$main$$inlined$sortedBy$1."<init>":()V
      70: checkcast     #37                 // class java/util/Comparator
      73: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
      76: checkcast     #30                 // class java/lang/Iterable
      79: astore        5
      81: nop
      82: iconst_0
      83: istore        6
      85: aload         5
      87: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      92: astore        7
      94: aload         7
      96: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     101: ifeq          149
     104: aload         7
     106: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     111: astore        8
     113: aload         8
     115: checkcast     #59                 // class kotlin/Pair
     118: astore        9
     120: iconst_0
     121: istore        10
     123: aload         9
     125: invokevirtual #62                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     128: checkcast     #64                 // class java/lang/CharSequence
     131: aload_0
     132: checkcast     #64                 // class java/lang/CharSequence
     135: iconst_0
     136: iconst_2
     137: aconst_null
     138: invokestatic  #70                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
     141: ifeq          94
     144: aload         8
     146: goto          150
     149: aconst_null
     150: checkcast     #59                 // class kotlin/Pair
     153: dup
     154: ifnull        163
     157: checkcast     #72                 // class java/io/Serializable
     160: goto          169
     163: pop
     164: ldc           #74                 // String No Contact
     166: checkcast     #72                 // class java/io/Serializable
     169: astore_3
     170: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     173: aload_3
     174: invokevirtual #86                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     177: ldc           #88                 // String 00-44  48 5555 8361
     179: astore        5
     181: aload         5
     183: astore        6
     185: iconst_0
     186: istore        7
     188: aload         6
     190: invokevirtual #92                 // Method java/lang/String.length:()I
     193: iconst_2
     194: irem
     195: ifne          202
     198: iconst_1
     199: goto          203
     202: iconst_0
     203: istore        8
     205: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     208: iload         8
     210: invokevirtual #95                 // Method java/io/PrintStream.println:(Z)V
     213: nop
     214: aload         5
     216: astore        4
     218: ldc           #97                 // String 0 - 22 1985--324
     220: checkcast     #64                 // class java/lang/CharSequence
     223: invokestatic  #101                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     226: invokevirtual #105                // Method java/lang/Object.toString:()Ljava/lang/String;
     229: astore        6
     231: aload         6
     233: astore        7
     235: iconst_0
     236: istore        8
     238: aload         7
     240: invokevirtual #92                 // Method java/lang/String.length:()I
     243: istore        9
     245: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     248: iload         9
     250: invokevirtual #108                // Method java/io/PrintStream.println:(I)V
     253: nop
     254: aload         6
     256: astore        5
     258: aload         5
     260: checkcast     #64                 // class java/lang/CharSequence
     263: iconst_1
     264: anewarray     #10                 // class java/lang/String
     267: astore        7
     269: aload         7
     271: iconst_0
     272: ldc           #110                // String
     274: aastore
     275: aload         7
     277: iconst_0
     278: iconst_0
     279: bipush        6
     281: aconst_null
     282: invokestatic  #114                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     285: checkcast     #30                 // class java/lang/Iterable
     288: astore        7
     290: nop
     291: iconst_0
     292: istore        8
     294: aload         7
     296: astore        9
     298: new           #116                // class java/util/ArrayList
     301: dup
     302: invokespecial #117                // Method java/util/ArrayList."<init>":()V
     305: checkcast     #119                // class java/util/Collection
     308: astore        10
     310: iconst_0
     311: istore        11
     313: aload         9
     315: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     320: astore        12
     322: aload         12
     324: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     329: ifeq          380
     332: aload         12
     334: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     339: astore        13
     341: aload         13
     343: checkcast     #10                 // class java/lang/String
     346: astore        14
     348: iconst_0
     349: istore        15
     351: aload         14
     353: invokestatic  #123                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
     356: ifnull        363
     359: iconst_1
     360: goto          364
     363: iconst_0
     364: ifeq          322
     367: aload         10
     369: aload         13
     371: invokeinterface #127,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     376: pop
     377: goto          322
     380: aload         10
     382: checkcast     #129                // class java/util/List
     385: nop
     386: checkcast     #30                 // class java/lang/Iterable
     389: iconst_3
     390: invokestatic  #133                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
     393: astore        8
     395: iconst_0
     396: istore        9
     398: aload         8
     400: invokestatic  #137                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     403: checkcast     #129                // class java/util/List
     406: invokeinterface #140,  1          // InterfaceMethod java/util/List.size:()I
     411: iconst_1
     412: if_icmpne     595
     415: aload         8
     417: iconst_2
     418: invokestatic  #144                // Method kotlin/collections/CollectionsKt.takeLast:(Ljava/util/List;I)Ljava/util/List;
     421: checkcast     #30                 // class java/lang/Iterable
     424: ldc           #110                // String
     426: checkcast     #64                 // class java/lang/CharSequence
     429: aconst_null
     430: aconst_null
     431: iconst_0
     432: aconst_null
     433: aconst_null
     434: bipush        62
     436: aconst_null
     437: invokestatic  #148                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     440: checkcast     #64                 // class java/lang/CharSequence
     443: iconst_1
     444: anewarray     #10                 // class java/lang/String
     447: astore        10
     449: aload         10
     451: iconst_0
     452: ldc           #110                // String
     454: aastore
     455: aload         10
     457: iconst_0
     458: iconst_0
     459: bipush        6
     461: aconst_null
     462: invokestatic  #114                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     465: checkcast     #30                 // class java/lang/Iterable
     468: astore        10
     470: nop
     471: iconst_0
     472: istore        11
     474: aload         10
     476: astore        12
     478: new           #116                // class java/util/ArrayList
     481: dup
     482: invokespecial #117                // Method java/util/ArrayList."<init>":()V
     485: checkcast     #119                // class java/util/Collection
     488: astore        13
     490: iconst_0
     491: istore        14
     493: aload         12
     495: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     500: astore        15
     502: aload         15
     504: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     509: ifeq          560
     512: aload         15
     514: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     519: astore        16
     521: aload         16
     523: checkcast     #10                 // class java/lang/String
     526: astore        17
     528: iconst_0
     529: istore        18
     531: aload         17
     533: invokestatic  #123                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
     536: ifnull        543
     539: iconst_1
     540: goto          544
     543: iconst_0
     544: ifeq          502
     547: aload         13
     549: aload         16
     551: invokeinterface #127,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     556: pop
     557: goto          502
     560: aload         13
     562: checkcast     #129                // class java/util/List
     565: nop
     566: checkcast     #30                 // class java/lang/Iterable
     569: iconst_2
     570: invokestatic  #133                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
     573: astore        19
     575: aload         8
     577: iconst_2
     578: invokestatic  #151                // Method kotlin/collections/CollectionsKt.dropLast:(Ljava/util/List;I)Ljava/util/List;
     581: checkcast     #119                // class java/util/Collection
     584: aload         19
     586: checkcast     #30                 // class java/lang/Iterable
     589: invokestatic  #155                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     592: goto          597
     595: aload         8
     597: checkcast     #30                 // class java/lang/Iterable
     600: ldc           #157                // String -
     602: checkcast     #64                 // class java/lang/CharSequence
     605: aconst_null
     606: aconst_null
     607: iconst_0
     608: aconst_null
     609: invokedynamic #176,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     614: bipush        30
     616: aconst_null
     617: invokestatic  #148                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     620: astore        6
     622: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     625: aload         6
     627: invokevirtual #86                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     630: sipush        2014
     633: istore        7
     635: ldc           #178                // String April
     637: astore        8
     639: ldc           #180                // String May
     641: astore        9
     643: ldc           #182                // String Wednesday
     645: astore        10
     647: aload         8
     649: aload         9
     651: iload         7
     653: aload         10
     655: invokestatic  #186                // Method getDays:(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)I
     658: istore        11
     660: iload         11
     662: bipush        7
     664: idiv
     665: istore        12
     667: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     670: iload         12
     672: invokevirtual #108                // Method java/io/PrintStream.println:(I)V
     675: iconst_3
     676: istore        12
     678: iconst_2
     679: anewarray     #188                // class java/lang/Integer
     682: astore        14
     684: aload         14
     686: iconst_0
     687: iconst_1
     688: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     691: aastore
     692: aload         14
     694: iconst_1
     695: iconst_3
     696: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     699: aastore
     700: aload         14
     702: invokestatic  #196                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     705: astore        13
     707: iconst_2
     708: anewarray     #188                // class java/lang/Integer
     711: astore        15
     713: aload         15
     715: iconst_0
     716: iconst_2
     717: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     720: aastore
     721: aload         15
     723: iconst_1
     724: iconst_2
     725: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     728: aastore
     729: aload         15
     731: invokestatic  #196                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     734: astore        14
     736: aload         13
     738: checkcast     #30                 // class java/lang/Iterable
     741: aload         14
     743: checkcast     #30                 // class java/lang/Iterable
     746: invokestatic  #199                // Method kotlin/collections/CollectionsKt.zip:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
     749: astore        15
     751: aload         15
     753: checkcast     #30                 // class java/lang/Iterable
     756: astore        17
     758: iconst_0
     759: istore        18
     761: aload         17
     763: astore        19
     765: new           #116                // class java/util/ArrayList
     768: dup
     769: aload         17
     771: bipush        10
     773: invokestatic  #203                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     776: invokespecial #205                // Method java/util/ArrayList."<init>":(I)V
     779: checkcast     #119                // class java/util/Collection
     782: astore        20
     784: iconst_0
     785: istore        21
     787: aload         19
     789: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     794: astore        22
     796: aload         22
     798: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     803: ifeq          902
     806: aload         22
     808: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     813: astore        23
     815: aload         20
     817: aload         23
     819: checkcast     #59                 // class kotlin/Pair
     822: astore        24
     824: astore        29
     826: iconst_0
     827: istore        25
     829: aload         24
     831: invokevirtual #208                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     834: checkcast     #210                // class java/lang/Number
     837: invokevirtual #213                // Method java/lang/Number.intValue:()I
     840: istore        26
     842: aload         24
     844: invokevirtual #216                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     847: checkcast     #210                // class java/lang/Number
     850: invokevirtual #213                // Method java/lang/Number.intValue:()I
     853: istore        27
     855: iconst_2
     856: anewarray     #188                // class java/lang/Integer
     859: astore        28
     861: aload         28
     863: iconst_0
     864: iload         26
     866: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     869: aastore
     870: aload         28
     872: iconst_1
     873: iload         27
     875: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     878: aastore
     879: aload         28
     881: invokestatic  #196                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     884: checkcast     #30                 // class java/lang/Iterable
     887: invokestatic  #220                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     890: aload         29
     892: swap
     893: invokeinterface #127,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     898: pop
     899: goto          796
     902: aload         20
     904: checkcast     #129                // class java/util/List
     907: nop
     908: astore        16
     910: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     913: aload         16
     915: invokevirtual #86                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     918: return

  public static final int getDays(java.lang.String, java.lang.String, int, java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #277                // String startMonth
       4: invokestatic  #283                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: ldc_w         #284                // String endMonth
      11: invokestatic  #283                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_3
      15: ldc_w         #286                // String startDay
      18: invokestatic  #283                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      21: bipush        7
      23: anewarray     #10                 // class java/lang/String
      26: astore        5
      28: aload         5
      30: iconst_0
      31: ldc_w         #288                // String Monday
      34: aastore
      35: aload         5
      37: iconst_1
      38: ldc_w         #290                // String Tuesday
      41: aastore
      42: aload         5
      44: iconst_2
      45: ldc           #182                // String Wednesday
      47: aastore
      48: aload         5
      50: iconst_3
      51: ldc_w         #292                // String Thursday
      54: aastore
      55: aload         5
      57: iconst_4
      58: ldc_w         #294                // String Friday
      61: aastore
      62: aload         5
      64: iconst_5
      65: ldc_w         #296                // String Saturday
      68: aastore
      69: aload         5
      71: bipush        6
      73: ldc_w         #298                // String Sunday
      76: aastore
      77: aload         5
      79: invokestatic  #196                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      82: astore        4
      84: bipush        12
      86: anewarray     #10                 // class java/lang/String
      89: astore        6
      91: aload         6
      93: iconst_0
      94: ldc_w         #300                // String January
      97: aastore
      98: aload         6
     100: iconst_1
     101: ldc_w         #302                // String February
     104: aastore
     105: aload         6
     107: iconst_2
     108: ldc_w         #304                // String March
     111: aastore
     112: aload         6
     114: iconst_3
     115: ldc           #178                // String April
     117: aastore
     118: aload         6
     120: iconst_4
     121: ldc           #180                // String May
     123: aastore
     124: aload         6
     126: iconst_5
     127: ldc_w         #306                // String June
     130: aastore
     131: aload         6
     133: bipush        6
     135: ldc_w         #308                // String July
     138: aastore
     139: aload         6
     141: bipush        7
     143: ldc_w         #310                // String August
     146: aastore
     147: aload         6
     149: bipush        8
     151: ldc_w         #312                // String September
     154: aastore
     155: aload         6
     157: bipush        9
     159: ldc_w         #314                // String October
     162: aastore
     163: aload         6
     165: bipush        10
     167: ldc_w         #316                // String November
     170: aastore
     171: aload         6
     173: bipush        11
     175: ldc_w         #318                // String December
     178: aastore
     179: aload         6
     181: invokestatic  #196                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     184: astore        5
     186: bipush        12
     188: anewarray     #59                 // class kotlin/Pair
     191: astore        7
     193: aload         7
     195: iconst_0
     196: ldc_w         #300                // String January
     199: bipush        31
     201: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     204: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     207: aastore
     208: aload         7
     210: iconst_1
     211: ldc_w         #302                // String February
     214: iload_2
     215: invokestatic  #328                // Method isLeapYear:(I)Z
     218: ifeq          226
     221: bipush        29
     223: goto          228
     226: bipush        28
     228: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     231: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     234: aastore
     235: aload         7
     237: iconst_2
     238: ldc_w         #304                // String March
     241: bipush        31
     243: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     246: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     249: aastore
     250: aload         7
     252: iconst_3
     253: ldc           #178                // String April
     255: bipush        30
     257: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     260: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     263: aastore
     264: aload         7
     266: iconst_4
     267: ldc           #180                // String May
     269: bipush        31
     271: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     274: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     277: aastore
     278: aload         7
     280: iconst_5
     281: ldc_w         #306                // String June
     284: bipush        30
     286: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     289: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     292: aastore
     293: aload         7
     295: bipush        6
     297: ldc_w         #308                // String July
     300: bipush        31
     302: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     305: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     308: aastore
     309: aload         7
     311: bipush        7
     313: ldc_w         #310                // String August
     316: bipush        31
     318: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     321: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     324: aastore
     325: aload         7
     327: bipush        8
     329: ldc_w         #312                // String September
     332: bipush        30
     334: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     337: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     340: aastore
     341: aload         7
     343: bipush        9
     345: ldc_w         #314                // String October
     348: bipush        31
     350: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     353: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     356: aastore
     357: aload         7
     359: bipush        10
     361: ldc_w         #316                // String November
     364: bipush        30
     366: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     369: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     372: aastore
     373: aload         7
     375: bipush        11
     377: ldc_w         #318                // String December
     380: bipush        31
     382: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     385: invokestatic  #324                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     388: aastore
     389: aload         7
     391: invokestatic  #334                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     394: astore        6
     396: aload         5
     398: aload_0
     399: invokeinterface #338,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     404: istore        7
     406: aload         5
     408: aload_1
     409: invokeinterface #338,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     414: istore        8
     416: new           #340                // class kotlin/ranges/IntRange
     419: dup
     420: iload         7
     422: iload         8
     424: invokespecial #343                // Method kotlin/ranges/IntRange."<init>":(II)V
     427: checkcast     #30                 // class java/lang/Iterable
     430: astore        10
     432: iconst_0
     433: istore        11
     435: aload         10
     437: astore        12
     439: new           #116                // class java/util/ArrayList
     442: dup
     443: aload         10
     445: bipush        10
     447: invokestatic  #203                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     450: invokespecial #205                // Method java/util/ArrayList."<init>":(I)V
     453: checkcast     #119                // class java/util/Collection
     456: astore        13
     458: iconst_0
     459: istore        14
     461: aload         12
     463: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     468: astore        15
     470: aload         15
     472: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     477: ifeq          554
     480: aload         15
     482: checkcast     #345                // class kotlin/collections/IntIterator
     485: invokevirtual #348                // Method kotlin/collections/IntIterator.nextInt:()I
     488: istore        16
     490: aload         13
     492: iload         16
     494: istore        17
     496: astore        20
     498: iconst_0
     499: istore        18
     501: aload         5
     503: iload         17
     505: invokeinterface #352,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     510: checkcast     #10                 // class java/lang/String
     513: astore        19
     515: aload         6
     517: aload         19
     519: invokeinterface #356,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     524: checkcast     #188                // class java/lang/Integer
     527: dup
     528: ifnull        537
     531: invokevirtual #357                // Method java/lang/Integer.intValue:()I
     534: goto          539
     537: pop
     538: iconst_0
     539: invokestatic  #192                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     542: aload         20
     544: swap
     545: invokeinterface #127,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     550: pop
     551: goto          470
     554: aload         13
     556: checkcast     #129                // class java/util/List
     559: nop
     560: checkcast     #30                 // class java/lang/Iterable
     563: invokestatic  #361                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     566: istore        9
     568: aload         4
     570: aload_3
     571: invokeinterface #338,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     576: istore        10
     578: iload         9
     580: iload         10
     582: isub
     583: ireturn

  public static final boolean isLeapYear(int);
    Code:
       0: nop
       1: iload_0
       2: iconst_4
       3: irem
       4: ifeq          11
       7: iconst_0
       8: goto          35
      11: iload_0
      12: sipush        400
      15: irem
      16: ifne          23
      19: iconst_1
      20: goto          35
      23: iload_0
      24: bipush        100
      26: irem
      27: ifeq          34
      30: iconst_1
      31: goto          35
      34: iconst_0
      35: ireturn

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

  private static final java.lang.CharSequence main$lambda$7(java.util.List);
    Code:
       0: aload_0
       1: ldc_w         #378                // String it
       4: invokestatic  #283                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #30                 // class java/lang/Iterable
      11: ldc           #110                // String
      13: checkcast     #64                 // class java/lang/CharSequence
      16: aconst_null
      17: aconst_null
      18: iconst_0
      19: aconst_null
      20: aconst_null
      21: bipush        62
      23: aconst_null
      24: invokestatic  #148                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      27: checkcast     #64                 // class java/lang/CharSequence
      30: areturn
}


package final_450.arrays

fun main() {
    // Given an array arr[] and a number K where K is smaller
    // than size of array, the task is to find the Kth smallest
    // element in the given array.
    // It is given that all array elements are distinct.

    /**
     * * N = 6 arr[] = 7 10 4 3 20 15 K = 3 Output : 7 Explanation : 3rd smallest element in the
     * given array is 7.
     */
    val k = 3
    val input = arrayOf(7, 10, 4, 3, 20, 15)
    val kSmallest = input.sorted().get(k - 1)
    println(kSmallest)

    mergesort(input.toList(), mutableListOf())
}

// 7,10,4,3,20,15
// 7 10 4  | 3 20 15
fun mergesort(list: List<Int>, acc: MutableList<List<Int>>) {
    sliceOrAdd(list, acc)
    println(acc)
}

fun sliceOrAdd(list: List<Int>, acc: MutableList<List<Int>>) {
    val (first, last) = list.equalSplit()
    val isFirstHavingOneItem = first.size == 1
    val isLastHavingOneItem = last.size == 1
    if (!isFirstHavingOneItem) {
        sliceOrAdd(first, acc)
    } else {
        val index = acc.indexOfFirst { it[0] < first[0] }
        acc.add(index, first)
    }
    if (!isLastHavingOneItem) {
        sliceOrAdd(last, acc)
    } else {
        val index = acc.indexOfFirst { it[0] < last[0] }
        acc.add(index, last)
    }
}

fun merge() {
    val input = listOf(0, 0, 0, 1, 2, 2, 2, 1, 0, 1).toMutableList()
    var pointer0 = 0
    var pointer1 = pointer0
    var pointer2 = input.lastIndex
    while (pointer0 <= pointer2) {
        val value = input[pointer0]
        when (value) {
            0 -> {
                val first = input[pointer0]
                val mid = input[pointer1]
                input.set(pointer0, mid)
                input.set(pointer1, first)
                ++pointer0
                ++pointer1
            }
            1 -> {
                ++pointer1
            }
            2 -> {
                val last = input[pointer2]
                val mid = input[pointer1]
                input.set(pointer2, mid)
                input.set(pointer1, last)
                --pointer2
            }
        }
    }
}

fun List<Int>.equalSplit(): Pair<List<Int>, List<Int>> {
    val length = size
    return take(length / 2) to drop(length / 2)
}

Compiled from "kthSmallOrLargeElement.kt"
public final class final_450.arrays.KthSmallOrLargeElementKt {
  public static final void main();
    Code:
       0: iconst_3
       1: istore_0
       2: bipush        6
       4: anewarray     #8                  // class java/lang/Integer
       7: astore_2
       8: aload_2
       9: iconst_0
      10: bipush        7
      12: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: aastore
      16: aload_2
      17: iconst_1
      18: bipush        10
      20: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: aastore
      24: aload_2
      25: iconst_2
      26: iconst_4
      27: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      30: aastore
      31: aload_2
      32: iconst_3
      33: iconst_3
      34: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      37: aastore
      38: aload_2
      39: iconst_4
      40: bipush        20
      42: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      45: aastore
      46: aload_2
      47: iconst_5
      48: bipush        15
      50: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      53: aastore
      54: aload_2
      55: astore_1
      56: aload_1
      57: checkcast     #14                 // class "[Ljava/lang/Comparable;"
      60: invokestatic  #20                 // Method kotlin/collections/ArraysKt.sorted:([Ljava/lang/Comparable;)Ljava/util/List;
      63: iload_0
      64: iconst_1
      65: isub
      66: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      71: checkcast     #28                 // class java/lang/Number
      74: invokevirtual #32                 // Method java/lang/Number.intValue:()I
      77: istore_2
      78: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      81: iload_2
      82: invokevirtual #44                 // Method java/io/PrintStream.println:(I)V
      85: aload_1
      86: invokestatic  #48                 // Method kotlin/collections/ArraysKt.toList:([Ljava/lang/Object;)Ljava/util/List;
      89: new           #50                 // class java/util/ArrayList
      92: dup
      93: invokespecial #53                 // Method java/util/ArrayList."<init>":()V
      96: checkcast     #22                 // class java/util/List
      99: invokestatic  #57                 // Method mergesort:(Ljava/util/List;Ljava/util/List;)V
     102: return

  public static final void mergesort(java.util.List<java.lang.Integer>, java.util.List<java.util.List<java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #66                 // String list
       3: invokestatic  #72                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #74                 // String acc
       9: invokestatic  #72                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokestatic  #77                 // Method sliceOrAdd:(Ljava/util/List;Ljava/util/List;)V
      17: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
      20: aload_1
      21: invokevirtual #80                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      24: return

  public static final void sliceOrAdd(java.util.List<java.lang.Integer>, java.util.List<java.util.List<java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #66                 // String list
       3: invokestatic  #72                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #74                 // String acc
       9: invokestatic  #72                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokestatic  #85                 // Method equalSplit:(Ljava/util/List;)Lkotlin/Pair;
      16: astore_2
      17: aload_2
      18: invokevirtual #91                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
      21: checkcast     #22                 // class java/util/List
      24: astore_3
      25: aload_2
      26: invokevirtual #94                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
      29: checkcast     #22                 // class java/util/List
      32: astore        4
      34: aload_3
      35: invokeinterface #97,  1           // InterfaceMethod java/util/List.size:()I
      40: iconst_1
      41: if_icmpne     48
      44: iconst_1
      45: goto          49
      48: iconst_0
      49: istore        5
      51: aload         4
      53: invokeinterface #97,  1           // InterfaceMethod java/util/List.size:()I
      58: iconst_1
      59: if_icmpne     66
      62: iconst_1
      63: goto          67
      66: iconst_0
      67: istore        6
      69: iload         5
      71: ifne          82
      74: aload_3
      75: aload_1
      76: invokestatic  #77                 // Method sliceOrAdd:(Ljava/util/List;Ljava/util/List;)V
      79: goto          190
      82: aload_1
      83: astore        8
      85: iconst_0
      86: istore        9
      88: iconst_0
      89: istore        10
      91: aload         8
      93: invokeinterface #101,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      98: astore        11
     100: aload         11
     102: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     107: ifeq          178
     110: aload         11
     112: invokeinterface #110,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     117: astore        12
     119: aload         12
     121: checkcast     #22                 // class java/util/List
     124: astore        13
     126: iconst_0
     127: istore        14
     129: aload         13
     131: iconst_0
     132: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     137: checkcast     #28                 // class java/lang/Number
     140: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     143: aload_3
     144: iconst_0
     145: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     150: checkcast     #28                 // class java/lang/Number
     153: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     156: if_icmpge     163
     159: iconst_1
     160: goto          164
     163: iconst_0
     164: ifeq          172
     167: iload         10
     169: goto          179
     172: iinc          10, 1
     175: goto          100
     178: iconst_m1
     179: istore        7
     181: aload_1
     182: iload         7
     184: aload_3
     185: invokeinterface #114,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     190: iload         6
     192: ifne          204
     195: aload         4
     197: aload_1
     198: invokestatic  #77                 // Method sliceOrAdd:(Ljava/util/List;Ljava/util/List;)V
     201: goto          314
     204: aload_1
     205: astore        8
     207: iconst_0
     208: istore        9
     210: iconst_0
     211: istore        10
     213: aload         8
     215: invokeinterface #101,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     220: astore        11
     222: aload         11
     224: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     229: ifeq          301
     232: aload         11
     234: invokeinterface #110,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     239: astore        12
     241: aload         12
     243: checkcast     #22                 // class java/util/List
     246: astore        13
     248: iconst_0
     249: istore        14
     251: aload         13
     253: iconst_0
     254: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     259: checkcast     #28                 // class java/lang/Number
     262: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     265: aload         4
     267: iconst_0
     268: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     273: checkcast     #28                 // class java/lang/Number
     276: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     279: if_icmpge     286
     282: iconst_1
     283: goto          287
     286: iconst_0
     287: ifeq          295
     290: iload         10
     292: goto          302
     295: iinc          10, 1
     298: goto          222
     301: iconst_m1
     302: istore        7
     304: aload_1
     305: iload         7
     307: aload         4
     309: invokeinterface #114,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     314: return

  public static final void merge();
    Code:
       0: bipush        10
       2: anewarray     #8                  // class java/lang/Integer
       5: astore_1
       6: aload_1
       7: iconst_0
       8: iconst_0
       9: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      12: aastore
      13: aload_1
      14: iconst_1
      15: iconst_0
      16: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      19: aastore
      20: aload_1
      21: iconst_2
      22: iconst_0
      23: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      26: aastore
      27: aload_1
      28: iconst_3
      29: iconst_1
      30: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: aastore
      34: aload_1
      35: iconst_4
      36: iconst_2
      37: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: aastore
      41: aload_1
      42: iconst_5
      43: iconst_2
      44: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: aastore
      48: aload_1
      49: bipush        6
      51: iconst_2
      52: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: aastore
      56: aload_1
      57: bipush        7
      59: iconst_1
      60: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      63: aastore
      64: aload_1
      65: bipush        8
      67: iconst_0
      68: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      71: aastore
      72: aload_1
      73: bipush        9
      75: iconst_1
      76: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      79: aastore
      80: aload_1
      81: invokestatic  #134                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      84: checkcast     #136                // class java/util/Collection
      87: invokestatic  #140                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      90: astore_0
      91: iconst_0
      92: istore_1
      93: iload_1
      94: istore_2
      95: aload_0
      96: invokestatic  #144                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
      99: istore_3
     100: iload_1
     101: iload_3
     102: if_icmpgt     281
     105: aload_0
     106: iload_1
     107: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     112: checkcast     #28                 // class java/lang/Number
     115: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     118: istore        4
     120: iload         4
     122: tableswitch   { // 0 to 2
                     0: 148
                     1: 213
                     2: 219
               default: 278
          }
     148: aload_0
     149: iload_1
     150: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     155: checkcast     #28                 // class java/lang/Number
     158: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     161: istore        5
     163: aload_0
     164: iload_2
     165: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     170: checkcast     #28                 // class java/lang/Number
     173: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     176: istore        6
     178: aload_0
     179: iload_1
     180: iload         6
     182: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     185: invokeinterface #148,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     190: pop
     191: aload_0
     192: iload_2
     193: iload         5
     195: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     198: invokeinterface #148,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     203: pop
     204: iinc          1, 1
     207: iinc          2, 1
     210: goto          100
     213: iinc          2, 1
     216: goto          100
     219: aload_0
     220: iload_3
     221: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     226: checkcast     #28                 // class java/lang/Number
     229: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     232: istore        5
     234: aload_0
     235: iload_2
     236: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     241: checkcast     #28                 // class java/lang/Number
     244: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     247: istore        6
     249: aload_0
     250: iload_3
     251: iload         6
     253: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     256: invokeinterface #148,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     261: pop
     262: aload_0
     263: iload_2
     264: iload         5
     266: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     269: invokeinterface #148,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     274: pop
     275: iinc          3, -1
     278: goto          100
     281: return

  public static final kotlin.Pair<java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>> equalSplit(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #156                // String <this>
       3: invokestatic  #72                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #97,  1           // InterfaceMethod java/util/List.size:()I
      12: istore_1
      13: aload_0
      14: checkcast     #158                // class java/lang/Iterable
      17: iload_1
      18: iconst_2
      19: idiv
      20: invokestatic  #162                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      23: aload_0
      24: checkcast     #158                // class java/lang/Iterable
      27: iload_1
      28: iconst_2
      29: idiv
      30: invokestatic  #165                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      33: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      36: areturn

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


package elves.day03

class RuckSack(private val elveEncodedContent: String) {

    val priorityOfSharedCategory: Int?

    init {
        val firstCompartment = Compartment(elveEncodedContent.take(elveEncodedContent.length / 2))
        val secondCompartment = Compartment(elveEncodedContent.takeLast(elveEncodedContent.length / 2))

        priorityOfSharedCategory =
            firstCompartment.intersectionWith(secondCompartment).categoryInBothCompartments?.priority
    }

    fun badge(vararg rucksacksOfTheSameGroup: RuckSack): ItemCategory? {
        return rucksacksOfTheSameGroup
            .map { it.elveEncodedContent }
            .map { it.asIterable() }
            .fold(elveEncodedContent.asIterable()) { acc, cur -> acc.intersect(cur) }
            .map { ItemCategory(it) }
            .firstOrNull()
    }

}

private class Compartment(s: String) {
    fun intersectionWith(secondCompartment: Compartment): PackingReport {
        val other: CharArray = secondCompartment.content.toCharArray()
        val intersect: Set<Char> = content.toCharArray().intersect(other.asIterable().toSet())
        return PackingReport(intersect.firstOrNull())
    }

    private var content: String

    init {
        content = s
    }
}

const val ASCIICODE_FOR_A_LOWERCASE = 97
const val ASCIICODE_FOR_A_UPPERCASE = 65

class ItemCategory(categoryCode: Char) {
    val priority: Int

    init {
        priority = priorityOf(categoryCode)
    }

    private fun priorityOf(typeObjet: Char): Int {

        val asciiCode = typeObjet.code

        return if (asciiCode in (97..122))
            asciiCode - ASCIICODE_FOR_A_LOWERCASE + 1 // ici le 1 c'est la priorité de départ depuis "a"
        else {
            asciiCode - ASCIICODE_FOR_A_UPPERCASE + 27 // 27 c'est la priorité de départ depuis "A"
        }
// c'est bien ici, on peut s'errêter là.

    }

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

        other as ItemCategory

        if (priority != other.priority) return false

        return true
    }

    override fun hashCode(): Int {
        return priority
    }

    override fun toString(): String {
        return "ItemCategory(priority=$priority)"
    }

}

private class PackingReport(s: Char?) {
    val categoryInBothCompartments: ItemCategory?

    init {

        if (s != null) {
            categoryInBothCompartments = ItemCategory(s)
        } else {
            categoryInBothCompartments = null

        }
    }

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

        other as PackingReport

        if (categoryInBothCompartments != other.categoryInBothCompartments) return false

        return true
    }

    override fun hashCode(): Int {
        return categoryInBothCompartments?.hashCode() ?: 0
    }

    override fun toString(): String {
        return "PackingReport(categoryInBothCompartments=$categoryInBothCompartments)"
    }

}

Compiled from "RuckSack.kt"
public final class elves.day03.RuckSackKt {
  public static final int ASCIICODE_FOR_A_LOWERCASE;

  public static final int ASCIICODE_FOR_A_UPPERCASE;

}

Compiled from "RuckSack.kt"
public final class elves.day03.RuckSack {
  private final java.lang.String elveEncodedContent;

  private final java.lang.Integer priorityOfSharedCategory;

  public elves.day03.RuckSack(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String elveEncodedContent
       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: aload_1
      12: putfield      #21                 // Field elveEncodedContent:Ljava/lang/String;
      15: nop
      16: new           #23                 // class elves/day03/Compartment
      19: dup
      20: aload_0
      21: getfield      #21                 // Field elveEncodedContent:Ljava/lang/String;
      24: aload_0
      25: getfield      #21                 // Field elveEncodedContent:Ljava/lang/String;
      28: invokevirtual #29                 // Method java/lang/String.length:()I
      31: iconst_2
      32: idiv
      33: invokestatic  #35                 // Method kotlin/text/StringsKt.take:(Ljava/lang/String;I)Ljava/lang/String;
      36: invokespecial #37                 // Method elves/day03/Compartment."<init>":(Ljava/lang/String;)V
      39: astore_2
      40: new           #23                 // class elves/day03/Compartment
      43: dup
      44: aload_0
      45: getfield      #21                 // Field elveEncodedContent:Ljava/lang/String;
      48: aload_0
      49: getfield      #21                 // Field elveEncodedContent:Ljava/lang/String;
      52: invokevirtual #29                 // Method java/lang/String.length:()I
      55: iconst_2
      56: idiv
      57: invokestatic  #40                 // Method kotlin/text/StringsKt.takeLast:(Ljava/lang/String;I)Ljava/lang/String;
      60: invokespecial #37                 // Method elves/day03/Compartment."<init>":(Ljava/lang/String;)V
      63: astore_3
      64: aload_0
      65: aload_2
      66: aload_3
      67: invokevirtual #44                 // Method elves/day03/Compartment.intersectionWith:(Lelves/day03/Compartment;)Lelves/day03/PackingReport;
      70: invokevirtual #50                 // Method elves/day03/PackingReport.getCategoryInBothCompartments:()Lelves/day03/ItemCategory;
      73: dup
      74: ifnull        86
      77: invokevirtual #55                 // Method elves/day03/ItemCategory.getPriority:()I
      80: invokestatic  #61                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      83: goto          88
      86: pop
      87: aconst_null
      88: putfield      #65                 // Field priorityOfSharedCategory:Ljava/lang/Integer;
      91: nop
      92: return

  public final java.lang.Integer getPriorityOfSharedCategory();
    Code:
       0: aload_0
       1: getfield      #65                 // Field priorityOfSharedCategory:Ljava/lang/Integer;
       4: areturn

  public final elves.day03.ItemCategory badge(elves.day03.RuckSack...);
    Code:
       0: aload_1
       1: ldc           #77                 // String rucksacksOfTheSameGroup
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: astore_2
       8: nop
       9: iconst_0
      10: istore_3
      11: aload_2
      12: astore        4
      14: new           #79                 // class java/util/ArrayList
      17: dup
      18: aload_2
      19: arraylength
      20: invokespecial #82                 // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #84                 // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        6
      31: iconst_0
      32: istore        7
      34: aload         4
      36: arraylength
      37: istore        8
      39: iload         7
      41: iload         8
      43: if_icmpge     84
      46: aload         4
      48: iload         7
      50: aaload
      51: astore        9
      53: aload         5
      55: aload         9
      57: astore        10
      59: astore        12
      61: iconst_0
      62: istore        11
      64: aload         10
      66: getfield      #21                 // Field elveEncodedContent:Ljava/lang/String;
      69: aload         12
      71: swap
      72: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      77: pop
      78: iinc          7, 1
      81: goto          39
      84: aload         5
      86: checkcast     #90                 // class java/util/List
      89: nop
      90: checkcast     #92                 // class java/lang/Iterable
      93: astore_2
      94: nop
      95: iconst_0
      96: istore_3
      97: aload_2
      98: astore        4
     100: new           #79                 // class java/util/ArrayList
     103: dup
     104: aload_2
     105: bipush        10
     107: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     110: invokespecial #82                 // Method java/util/ArrayList."<init>":(I)V
     113: checkcast     #84                 // class java/util/Collection
     116: astore        5
     118: iconst_0
     119: istore        6
     121: aload         4
     123: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     128: astore        7
     130: aload         7
     132: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     137: ifeq          183
     140: aload         7
     142: invokeinterface #112,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     147: astore        8
     149: aload         5
     151: aload         8
     153: checkcast     #25                 // class java/lang/String
     156: astore        9
     158: astore        12
     160: iconst_0
     161: istore        10
     163: aload         9
     165: checkcast     #114                // class java/lang/CharSequence
     168: invokestatic  #118                // Method kotlin/text/StringsKt.asIterable:(Ljava/lang/CharSequence;)Ljava/lang/Iterable;
     171: aload         12
     173: swap
     174: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     179: pop
     180: goto          130
     183: aload         5
     185: checkcast     #90                 // class java/util/List
     188: nop
     189: checkcast     #92                 // class java/lang/Iterable
     192: astore_2
     193: aload_0
     194: getfield      #21                 // Field elveEncodedContent:Ljava/lang/String;
     197: checkcast     #114                // class java/lang/CharSequence
     200: invokestatic  #118                // Method kotlin/text/StringsKt.asIterable:(Ljava/lang/CharSequence;)Ljava/lang/Iterable;
     203: astore_3
     204: iconst_0
     205: istore        4
     207: aload_3
     208: astore        5
     210: aload_2
     211: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     216: astore        6
     218: aload         6
     220: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     225: ifeq          266
     228: aload         6
     230: invokeinterface #112,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     235: astore        7
     237: aload         5
     239: aload         7
     241: checkcast     #92                 // class java/lang/Iterable
     244: astore        8
     246: astore        9
     248: iconst_0
     249: istore        10
     251: aload         9
     253: aload         8
     255: invokestatic  #122                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     258: checkcast     #92                 // class java/lang/Iterable
     261: astore        5
     263: goto          218
     266: aload         5
     268: astore_2
     269: nop
     270: iconst_0
     271: istore_3
     272: aload_2
     273: astore        4
     275: new           #79                 // class java/util/ArrayList
     278: dup
     279: aload_2
     280: bipush        10
     282: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     285: invokespecial #82                 // Method java/util/ArrayList."<init>":(I)V
     288: checkcast     #84                 // class java/util/Collection
     291: astore        5
     293: iconst_0
     294: istore        6
     296: aload         4
     298: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     303: astore        7
     305: aload         7
     307: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     312: ifeq          362
     315: aload         7
     317: invokeinterface #112,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     322: astore        8
     324: aload         5
     326: aload         8
     328: checkcast     #124                // class java/lang/Character
     331: invokevirtual #128                // Method java/lang/Character.charValue:()C
     334: istore        9
     336: astore        12
     338: iconst_0
     339: istore        10
     341: new           #52                 // class elves/day03/ItemCategory
     344: dup
     345: iload         9
     347: invokespecial #131                // Method elves/day03/ItemCategory."<init>":(C)V
     350: aload         12
     352: swap
     353: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     358: pop
     359: goto          305
     362: aload         5
     364: checkcast     #90                 // class java/util/List
     367: nop
     368: invokestatic  #135                // Method kotlin/collections/CollectionsKt.firstOrNull:(Ljava/util/List;)Ljava/lang/Object;
     371: checkcast     #52                 // class elves/day03/ItemCategory
     374: areturn
}