import java.io.File

fun main(){

    val groupSize = 3

    val sumOfPriorities = File("src/Day03.txt")
        .readText()
        .also { println(it) }
        .split("\n")
        .flatMap { it.lines() }
        .map { getCommonCharacters(it) }
        .flatMap { it.map { elf -> getPriority(elf) } }
        .sum()

    println(sumOfPriorities)

    val sunOfPriorities = File("src/Day03.txt")
        .readText()
        .split("\n")
        .chunked(3)
        .map { getBadgesFromRuckSacks(it) }
        .sumOf { getPriority(it)  }

    println(sunOfPriorities)

}

fun getPriority(char: Char): Int {
    return when {
        char.isLowerCase() -> char - 'a' + 1
        char.isUpperCase() -> char - 'A' + 27
        else -> error("Check Input")
    }
}

fun getCommonCharacters(input: String): Set<Char> {

    val (firstCompartment,secondCompartment) = input.chunked(input.length / 2)
    return firstCompartment.toSet() intersect secondCompartment.toSet()

}

fun getBadgesFromRuckSacks(ruckSacks: List<String>): Char{
    val (first, second, third)  = ruckSacks
    return(first.toSet() intersect second.toSet() intersect third.toSet()).single()
}

fun solution1(){
    File("src/Day03.txt")
        .readText()
        .split("\n")
        .flatMap { it.lines() }
        .map { it.chunked(it.length /2) }
        .map { it[0].toSet() intersect it[1].toSet() }
        .sumOf { getPriority(it.first()) }
}

Compiled from "Day03.kt"
public final class Day03Kt {
  public static final void main();
    Code:
       0: iconst_3
       1: istore_0
       2: new           #8                  // class java/io/File
       5: dup
       6: ldc           #10                 // String src/Day03.txt
       8: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      11: aconst_null
      12: iconst_1
      13: aconst_null
      14: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      17: astore_2
      18: aload_2
      19: astore_3
      20: iconst_0
      21: istore        4
      23: getstatic     #26                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: aload_3
      27: invokevirtual #32                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: nop
      31: aload_2
      32: checkcast     #34                 // class java/lang/CharSequence
      35: iconst_1
      36: anewarray     #36                 // class java/lang/String
      39: astore_2
      40: aload_2
      41: iconst_0
      42: ldc           #38                 // String \n
      44: aastore
      45: aload_2
      46: iconst_0
      47: iconst_0
      48: bipush        6
      50: aconst_null
      51: invokestatic  #44                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      54: checkcast     #46                 // class java/lang/Iterable
      57: astore_2
      58: nop
      59: iconst_0
      60: istore_3
      61: aload_2
      62: astore        4
      64: new           #48                 // class java/util/ArrayList
      67: dup
      68: invokespecial #50                 // Method java/util/ArrayList."<init>":()V
      71: checkcast     #52                 // class java/util/Collection
      74: astore        5
      76: iconst_0
      77: istore        6
      79: aload         4
      81: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      86: astore        7
      88: aload         7
      90: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      95: ifeq          141
      98: aload         7
     100: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     105: astore        8
     107: aload         8
     109: checkcast     #36                 // class java/lang/String
     112: astore        9
     114: iconst_0
     115: istore        10
     117: aload         9
     119: checkcast     #34                 // class java/lang/CharSequence
     122: invokestatic  #70                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     125: checkcast     #46                 // class java/lang/Iterable
     128: astore        9
     130: aload         5
     132: aload         9
     134: invokestatic  #76                 // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     137: pop
     138: goto          88
     141: aload         5
     143: checkcast     #78                 // class java/util/List
     146: nop
     147: checkcast     #46                 // class java/lang/Iterable
     150: astore_2
     151: nop
     152: iconst_0
     153: istore_3
     154: aload_2
     155: astore        4
     157: new           #48                 // class java/util/ArrayList
     160: dup
     161: aload_2
     162: bipush        10
     164: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     167: invokespecial #85                 // Method java/util/ArrayList."<init>":(I)V
     170: checkcast     #52                 // class java/util/Collection
     173: astore        5
     175: iconst_0
     176: istore        6
     178: aload         4
     180: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     185: astore        7
     187: aload         7
     189: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     194: ifeq          237
     197: aload         7
     199: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     204: astore        8
     206: aload         5
     208: aload         8
     210: checkcast     #36                 // class java/lang/String
     213: astore        9
     215: astore        21
     217: iconst_0
     218: istore        10
     220: aload         9
     222: invokestatic  #89                 // Method getCommonCharacters:(Ljava/lang/String;)Ljava/util/Set;
     225: aload         21
     227: swap
     228: invokeinterface #93,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     233: pop
     234: goto          187
     237: aload         5
     239: checkcast     #78                 // class java/util/List
     242: nop
     243: checkcast     #46                 // class java/lang/Iterable
     246: astore_2
     247: nop
     248: iconst_0
     249: istore_3
     250: aload_2
     251: astore        4
     253: new           #48                 // class java/util/ArrayList
     256: dup
     257: invokespecial #50                 // Method java/util/ArrayList."<init>":()V
     260: checkcast     #52                 // class java/util/Collection
     263: astore        5
     265: iconst_0
     266: istore        6
     268: aload         4
     270: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     275: astore        7
     277: aload         7
     279: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     284: ifeq          430
     287: aload         7
     289: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     294: astore        8
     296: aload         8
     298: checkcast     #95                 // class java/util/Set
     301: astore        9
     303: iconst_0
     304: istore        10
     306: aload         9
     308: checkcast     #46                 // class java/lang/Iterable
     311: astore        11
     313: iconst_0
     314: istore        12
     316: aload         11
     318: astore        13
     320: new           #48                 // class java/util/ArrayList
     323: dup
     324: aload         11
     326: bipush        10
     328: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     331: invokespecial #85                 // Method java/util/ArrayList."<init>":(I)V
     334: checkcast     #52                 // class java/util/Collection
     337: astore        14
     339: iconst_0
     340: istore        15
     342: aload         13
     344: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     349: astore        16
     351: aload         16
     353: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     358: ifeq          407
     361: aload         16
     363: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     368: astore        17
     370: aload         14
     372: aload         17
     374: checkcast     #97                 // class java/lang/Character
     377: invokevirtual #101                // Method java/lang/Character.charValue:()C
     380: istore        18
     382: astore        19
     384: iconst_0
     385: istore        20
     387: iload         18
     389: invokestatic  #105                // Method getPriority:(C)I
     392: invokestatic  #111                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     395: aload         19
     397: swap
     398: invokeinterface #93,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     403: pop
     404: goto          351
     407: aload         14
     409: checkcast     #78                 // class java/util/List
     412: nop
     413: checkcast     #46                 // class java/lang/Iterable
     416: nop
     417: astore        9
     419: aload         5
     421: aload         9
     423: invokestatic  #76                 // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     426: pop
     427: goto          277
     430: aload         5
     432: checkcast     #78                 // class java/util/List
     435: nop
     436: checkcast     #46                 // class java/lang/Iterable
     439: invokestatic  #115                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     442: istore_1
     443: getstatic     #26                 // Field java/lang/System.out:Ljava/io/PrintStream;
     446: iload_1
     447: invokevirtual #117                // Method java/io/PrintStream.println:(I)V
     450: new           #8                  // class java/io/File
     453: dup
     454: ldc           #10                 // String src/Day03.txt
     456: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
     459: aconst_null
     460: iconst_1
     461: aconst_null
     462: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
     465: checkcast     #34                 // class java/lang/CharSequence
     468: iconst_1
     469: anewarray     #36                 // class java/lang/String
     472: astore_3
     473: aload_3
     474: iconst_0
     475: ldc           #38                 // String \n
     477: aastore
     478: aload_3
     479: iconst_0
     480: iconst_0
     481: bipush        6
     483: aconst_null
     484: invokestatic  #44                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     487: checkcast     #46                 // class java/lang/Iterable
     490: iconst_3
     491: invokestatic  #121                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
     494: checkcast     #46                 // class java/lang/Iterable
     497: astore_3
     498: nop
     499: iconst_0
     500: istore        4
     502: aload_3
     503: astore        5
     505: new           #48                 // class java/util/ArrayList
     508: dup
     509: aload_3
     510: bipush        10
     512: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     515: invokespecial #85                 // Method java/util/ArrayList."<init>":(I)V
     518: checkcast     #52                 // class java/util/Collection
     521: astore        6
     523: iconst_0
     524: istore        7
     526: aload         5
     528: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     533: astore        8
     535: aload         8
     537: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     542: ifeq          588
     545: aload         8
     547: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     552: astore        9
     554: aload         6
     556: aload         9
     558: checkcast     #78                 // class java/util/List
     561: astore        10
     563: astore        21
     565: iconst_0
     566: istore        11
     568: aload         10
     570: invokestatic  #125                // Method getBadgesFromRuckSacks:(Ljava/util/List;)C
     573: invokestatic  #128                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     576: aload         21
     578: swap
     579: invokeinterface #93,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     584: pop
     585: goto          535
     588: aload         6
     590: checkcast     #78                 // class java/util/List
     593: nop
     594: checkcast     #46                 // class java/lang/Iterable
     597: astore_3
     598: iconst_0
     599: istore        4
     601: aload_3
     602: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     607: astore        5
     609: aload         5
     611: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     616: ifeq          662
     619: aload         5
     621: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     626: astore        6
     628: iload         4
     630: aload         6
     632: checkcast     #97                 // class java/lang/Character
     635: invokevirtual #101                // Method java/lang/Character.charValue:()C
     638: istore        7
     640: istore        21
     642: iconst_0
     643: istore        8
     645: iload         7
     647: invokestatic  #105                // Method getPriority:(C)I
     650: istore        22
     652: iload         21
     654: iload         22
     656: iadd
     657: istore        4
     659: goto          609
     662: iload         4
     664: istore_2
     665: getstatic     #26                 // Field java/lang/System.out:Ljava/io/PrintStream;
     668: iload_2
     669: invokevirtual #117                // Method java/io/PrintStream.println:(I)V
     672: return

  public static final int getPriority(char);
    Code:
       0: nop
       1: iload_0
       2: invokestatic  #164                // Method java/lang/Character.isLowerCase:(C)Z
       5: ifeq          17
       8: iload_0
       9: bipush        97
      11: isub
      12: iconst_1
      13: iadd
      14: goto          47
      17: iload_0
      18: invokestatic  #167                // Method java/lang/Character.isUpperCase:(C)Z
      21: ifeq          34
      24: iload_0
      25: bipush        65
      27: isub
      28: bipush        27
      30: iadd
      31: goto          47
      34: new           #169                // class java/lang/IllegalStateException
      37: dup
      38: ldc           #171                // String Check Input
      40: invokevirtual #175                // Method java/lang/Object.toString:()Ljava/lang/String;
      43: invokespecial #176                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      46: athrow
      47: ireturn

  public static final java.util.Set<java.lang.Character> getCommonCharacters(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #181                // String input
       3: invokestatic  #187                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #34                 // class java/lang/CharSequence
      10: aload_0
      11: invokevirtual #191                // Method java/lang/String.length:()I
      14: iconst_2
      15: idiv
      16: invokestatic  #194                // Method kotlin/text/StringsKt.chunked:(Ljava/lang/CharSequence;I)Ljava/util/List;
      19: astore_1
      20: aload_1
      21: iconst_0
      22: invokeinterface #198,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      27: checkcast     #36                 // class java/lang/String
      30: astore_2
      31: aload_1
      32: iconst_1
      33: invokeinterface #198,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      38: checkcast     #36                 // class java/lang/String
      41: astore_3
      42: aload_2
      43: checkcast     #34                 // class java/lang/CharSequence
      46: invokestatic  #202                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
      49: checkcast     #46                 // class java/lang/Iterable
      52: aload_3
      53: checkcast     #34                 // class java/lang/CharSequence
      56: invokestatic  #202                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
      59: checkcast     #46                 // class java/lang/Iterable
      62: invokestatic  #206                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
      65: areturn

  public static final char getBadgesFromRuckSacks(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #211                // String ruckSacks
       3: invokestatic  #187                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iconst_0
       8: invokeinterface #198,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #36                 // class java/lang/String
      16: astore_1
      17: aload_0
      18: iconst_1
      19: invokeinterface #198,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      24: checkcast     #36                 // class java/lang/String
      27: astore_2
      28: aload_0
      29: iconst_2
      30: invokeinterface #198,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: checkcast     #36                 // class java/lang/String
      38: astore_3
      39: aload_1
      40: checkcast     #34                 // class java/lang/CharSequence
      43: invokestatic  #202                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
      46: checkcast     #46                 // class java/lang/Iterable
      49: aload_2
      50: checkcast     #34                 // class java/lang/CharSequence
      53: invokestatic  #202                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
      56: checkcast     #46                 // class java/lang/Iterable
      59: invokestatic  #206                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
      62: checkcast     #46                 // class java/lang/Iterable
      65: aload_3
      66: checkcast     #34                 // class java/lang/CharSequence
      69: invokestatic  #202                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
      72: checkcast     #46                 // class java/lang/Iterable
      75: invokestatic  #206                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
      78: checkcast     #46                 // class java/lang/Iterable
      81: invokestatic  #215                // Method kotlin/collections/CollectionsKt.single:(Ljava/lang/Iterable;)Ljava/lang/Object;
      84: checkcast     #97                 // class java/lang/Character
      87: invokevirtual #101                // Method java/lang/Character.charValue:()C
      90: ireturn

  public static final void solution1();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/Day03.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: checkcast     #34                 // class java/lang/CharSequence
      18: iconst_1
      19: anewarray     #36                 // class java/lang/String
      22: astore_0
      23: aload_0
      24: iconst_0
      25: ldc           #38                 // String \n
      27: aastore
      28: aload_0
      29: iconst_0
      30: iconst_0
      31: bipush        6
      33: aconst_null
      34: invokestatic  #44                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      37: checkcast     #46                 // class java/lang/Iterable
      40: astore_0
      41: nop
      42: iconst_0
      43: istore_1
      44: aload_0
      45: astore_2
      46: new           #48                 // class java/util/ArrayList
      49: dup
      50: invokespecial #50                 // Method java/util/ArrayList."<init>":()V
      53: checkcast     #52                 // class java/util/Collection
      56: astore_3
      57: iconst_0
      58: istore        4
      60: aload_2
      61: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      66: astore        5
      68: aload         5
      70: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      75: ifeq          120
      78: aload         5
      80: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      85: astore        6
      87: aload         6
      89: checkcast     #36                 // class java/lang/String
      92: astore        7
      94: iconst_0
      95: istore        8
      97: aload         7
      99: checkcast     #34                 // class java/lang/CharSequence
     102: invokestatic  #70                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     105: checkcast     #46                 // class java/lang/Iterable
     108: astore        7
     110: aload_3
     111: aload         7
     113: invokestatic  #76                 // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     116: pop
     117: goto          68
     120: aload_3
     121: checkcast     #78                 // class java/util/List
     124: nop
     125: checkcast     #46                 // class java/lang/Iterable
     128: astore_0
     129: nop
     130: iconst_0
     131: istore_1
     132: aload_0
     133: astore_2
     134: new           #48                 // class java/util/ArrayList
     137: dup
     138: aload_0
     139: bipush        10
     141: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     144: invokespecial #85                 // Method java/util/ArrayList."<init>":(I)V
     147: checkcast     #52                 // class java/util/Collection
     150: astore_3
     151: iconst_0
     152: istore        4
     154: aload_2
     155: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     160: astore        5
     162: aload         5
     164: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     169: ifeq          221
     172: aload         5
     174: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     179: astore        6
     181: aload_3
     182: aload         6
     184: checkcast     #36                 // class java/lang/String
     187: astore        7
     189: astore        9
     191: iconst_0
     192: istore        8
     194: aload         7
     196: checkcast     #34                 // class java/lang/CharSequence
     199: aload         7
     201: invokevirtual #191                // Method java/lang/String.length:()I
     204: iconst_2
     205: idiv
     206: invokestatic  #194                // Method kotlin/text/StringsKt.chunked:(Ljava/lang/CharSequence;I)Ljava/util/List;
     209: aload         9
     211: swap
     212: invokeinterface #93,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     217: pop
     218: goto          162
     221: aload_3
     222: checkcast     #78                 // class java/util/List
     225: nop
     226: checkcast     #46                 // class java/lang/Iterable
     229: astore_0
     230: nop
     231: iconst_0
     232: istore_1
     233: aload_0
     234: astore_2
     235: new           #48                 // class java/util/ArrayList
     238: dup
     239: aload_0
     240: bipush        10
     242: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     245: invokespecial #85                 // Method java/util/ArrayList."<init>":(I)V
     248: checkcast     #52                 // class java/util/Collection
     251: astore_3
     252: iconst_0
     253: istore        4
     255: aload_2
     256: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     261: astore        5
     263: aload         5
     265: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     270: ifeq          344
     273: aload         5
     275: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     280: astore        6
     282: aload_3
     283: aload         6
     285: checkcast     #78                 // class java/util/List
     288: astore        7
     290: astore        9
     292: iconst_0
     293: istore        8
     295: aload         7
     297: iconst_0
     298: invokeinterface #198,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     303: checkcast     #34                 // class java/lang/CharSequence
     306: invokestatic  #202                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
     309: checkcast     #46                 // class java/lang/Iterable
     312: aload         7
     314: iconst_1
     315: invokeinterface #198,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     320: checkcast     #34                 // class java/lang/CharSequence
     323: invokestatic  #202                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
     326: checkcast     #46                 // class java/lang/Iterable
     329: invokestatic  #206                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     332: aload         9
     334: swap
     335: invokeinterface #93,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     340: pop
     341: goto          263
     344: aload_3
     345: checkcast     #78                 // class java/util/List
     348: nop
     349: checkcast     #46                 // class java/lang/Iterable
     352: astore_0
     353: iconst_0
     354: istore_1
     355: aload_0
     356: invokeinterface #56,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     361: astore_2
     362: aload_2
     363: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     368: ifeq          418
     371: aload_2
     372: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     377: astore_3
     378: iload_1
     379: aload_3
     380: checkcast     #95                 // class java/util/Set
     383: astore        4
     385: istore        9
     387: iconst_0
     388: istore        5
     390: aload         4
     392: checkcast     #46                 // class java/lang/Iterable
     395: invokestatic  #221                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
     398: checkcast     #97                 // class java/lang/Character
     401: invokevirtual #101                // Method java/lang/Character.charValue:()C
     404: invokestatic  #105                // Method getPriority:(C)I
     407: istore        10
     409: iload         9
     411: iload         10
     413: iadd
     414: istore_1
     415: goto          362
     418: return

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


import java.io.File

fun main(){

    val score = File("src/Day02.txt")
        .readText()
        .split("\n")
        .flatMap { it.lines() }
        .map { it.split(" ") }
        .sumOf { getPointOfRoundSecondPart(it[0].first(), it[1].first()) }

    println(score)
}

fun getPointOfRound(first: Char, second: Char): Int {
   return when (second) {
      'X' -> {
          return when (first) {
              'A' -> 1 + 3
              'B' -> 1
              'C' -> 1 + 6
              else -> error("Check Input")
          }

      }
      'Y' -> {
          return when (first) {
              'A' -> 2 + 6
              'B' -> 2 + 3
              'C' -> 2
              else -> error("Check Input")
          }
      }
      'Z' -> {
          return when (first) {
              'A' -> 3
              'B' -> 3 + 6
              'C' -> 3 + 3
              else -> error("Check Input")
          }
      }
       else -> error("Check Input")
    }
}

fun getPointOfRoundSecondPart(first: Char, second: Char): Int {
    return when (second) {
        'X' -> {
            return when (first) {
                'A' -> 3
                'B' -> 1
                'C' -> 2
                else -> error("Check Input")
            }

        }
        'Y' -> {
            return when (first) {
                'A' -> 1 + 3
                'B' -> 2 + 3
                'C' -> 3 + 3
                else -> error("Check Input")
            }
        }
        'Z' -> {
            return when (first) {
                'A' -> 2 + 6
                'B' -> 3 + 6
                'C' -> 1 + 6
                else -> error("Check Input")
            }
        }
        else -> error("Check Input")
    }
}

Compiled from "Day02.kt"
public final class Day02Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/Day02.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: checkcast     #22                 // class java/lang/CharSequence
      18: iconst_1
      19: anewarray     #24                 // class java/lang/String
      22: astore_1
      23: aload_1
      24: iconst_0
      25: ldc           #26                 // String \n
      27: aastore
      28: aload_1
      29: iconst_0
      30: iconst_0
      31: bipush        6
      33: aconst_null
      34: invokestatic  #32                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      37: checkcast     #34                 // class java/lang/Iterable
      40: astore_1
      41: nop
      42: iconst_0
      43: istore_2
      44: aload_1
      45: astore_3
      46: new           #36                 // class java/util/ArrayList
      49: dup
      50: invokespecial #38                 // Method java/util/ArrayList."<init>":()V
      53: checkcast     #40                 // class java/util/Collection
      56: astore        4
      58: iconst_0
      59: istore        5
      61: aload_3
      62: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      67: astore        6
      69: aload         6
      71: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          122
      79: aload         6
      81: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: astore        7
      88: aload         7
      90: checkcast     #24                 // class java/lang/String
      93: astore        8
      95: iconst_0
      96: istore        9
      98: aload         8
     100: checkcast     #22                 // class java/lang/CharSequence
     103: invokestatic  #58                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     106: checkcast     #34                 // class java/lang/Iterable
     109: astore        8
     111: aload         4
     113: aload         8
     115: invokestatic  #64                 // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     118: pop
     119: goto          69
     122: aload         4
     124: checkcast     #66                 // class java/util/List
     127: nop
     128: checkcast     #34                 // class java/lang/Iterable
     131: astore_1
     132: nop
     133: iconst_0
     134: istore_2
     135: aload_1
     136: astore_3
     137: new           #36                 // class java/util/ArrayList
     140: dup
     141: aload_1
     142: bipush        10
     144: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     147: invokespecial #73                 // Method java/util/ArrayList."<init>":(I)V
     150: checkcast     #40                 // class java/util/Collection
     153: astore        4
     155: iconst_0
     156: istore        5
     158: aload_3
     159: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     164: astore        6
     166: aload         6
     168: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     173: ifeq          238
     176: aload         6
     178: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     183: astore        7
     185: aload         4
     187: aload         7
     189: checkcast     #24                 // class java/lang/String
     192: astore        8
     194: astore        11
     196: iconst_0
     197: istore        9
     199: aload         8
     201: checkcast     #22                 // class java/lang/CharSequence
     204: iconst_1
     205: anewarray     #24                 // class java/lang/String
     208: astore        10
     210: aload         10
     212: iconst_0
     213: ldc           #75                 // String
     215: aastore
     216: aload         10
     218: iconst_0
     219: iconst_0
     220: bipush        6
     222: aconst_null
     223: invokestatic  #32                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     226: aload         11
     228: swap
     229: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     234: pop
     235: goto          166
     238: aload         4
     240: checkcast     #66                 // class java/util/List
     243: nop
     244: checkcast     #34                 // class java/lang/Iterable
     247: astore_1
     248: iconst_0
     249: istore_2
     250: aload_1
     251: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     256: astore_3
     257: aload_3
     258: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     263: ifeq          329
     266: aload_3
     267: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     272: astore        4
     274: iload_2
     275: aload         4
     277: checkcast     #66                 // class java/util/List
     280: astore        5
     282: istore        11
     284: iconst_0
     285: istore        6
     287: aload         5
     289: iconst_0
     290: invokeinterface #83,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     295: checkcast     #22                 // class java/lang/CharSequence
     298: invokestatic  #87                 // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     301: aload         5
     303: iconst_1
     304: invokeinterface #83,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     309: checkcast     #22                 // class java/lang/CharSequence
     312: invokestatic  #87                 // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     315: invokestatic  #91                 // Method getPointOfRoundSecondPart:(CC)I
     318: istore        12
     320: iload         11
     322: iload         12
     324: iadd
     325: istore_2
     326: goto          257
     329: iload_2
     330: istore_0
     331: getstatic     #97                 // Field java/lang/System.out:Ljava/io/PrintStream;
     334: iload_0
     335: invokevirtual #102                // Method java/io/PrintStream.println:(I)V
     338: return

  public static final int getPointOfRound(char, char);
    Code:
       0: iload_1
       1: tableswitch   { // 88 to 90
                    88: 28
                    89: 83
                    90: 139
               default: 196
          }
      28: iload_0
      29: tableswitch   { // 65 to 67
                    65: 56
                    66: 60
                    67: 64
               default: 69
          }
      56: iconst_4
      57: goto          82
      60: iconst_1
      61: goto          82
      64: bipush        7
      66: goto          82
      69: new           #128                // class java/lang/IllegalStateException
      72: dup
      73: ldc           #130                // String Check Input
      75: invokevirtual #134                // Method java/lang/Object.toString:()Ljava/lang/String;
      78: invokespecial #135                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      81: athrow
      82: ireturn
      83: iload_0
      84: tableswitch   { // 65 to 67
                    65: 112
                    66: 117
                    67: 121
               default: 125
          }
     112: bipush        8
     114: goto          138
     117: iconst_5
     118: goto          138
     121: iconst_2
     122: goto          138
     125: new           #128                // class java/lang/IllegalStateException
     128: dup
     129: ldc           #130                // String Check Input
     131: invokevirtual #134                // Method java/lang/Object.toString:()Ljava/lang/String;
     134: invokespecial #135                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     137: athrow
     138: ireturn
     139: iload_0
     140: tableswitch   { // 65 to 67
                    65: 168
                    66: 172
                    67: 177
               default: 182
          }
     168: iconst_3
     169: goto          195
     172: bipush        9
     174: goto          195
     177: bipush        6
     179: goto          195
     182: new           #128                // class java/lang/IllegalStateException
     185: dup
     186: ldc           #130                // String Check Input
     188: invokevirtual #134                // Method java/lang/Object.toString:()Ljava/lang/String;
     191: invokespecial #135                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     194: athrow
     195: ireturn
     196: new           #128                // class java/lang/IllegalStateException
     199: dup
     200: ldc           #130                // String Check Input
     202: invokevirtual #134                // Method java/lang/Object.toString:()Ljava/lang/String;
     205: invokespecial #135                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     208: athrow

  public static final int getPointOfRoundSecondPart(char, char);
    Code:
       0: iload_1
       1: tableswitch   { // 88 to 90
                    88: 28
                    89: 82
                    90: 135
               default: 193
          }
      28: iload_0
      29: tableswitch   { // 65 to 67
                    65: 56
                    66: 60
                    67: 64
               default: 68
          }
      56: iconst_3
      57: goto          81
      60: iconst_1
      61: goto          81
      64: iconst_2
      65: goto          81
      68: new           #128                // class java/lang/IllegalStateException
      71: dup
      72: ldc           #130                // String Check Input
      74: invokevirtual #134                // Method java/lang/Object.toString:()Ljava/lang/String;
      77: invokespecial #135                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      80: athrow
      81: ireturn
      82: iload_0
      83: tableswitch   { // 65 to 67
                    65: 108
                    66: 112
                    67: 116
               default: 121
          }
     108: iconst_4
     109: goto          134
     112: iconst_5
     113: goto          134
     116: bipush        6
     118: goto          134
     121: new           #128                // class java/lang/IllegalStateException
     124: dup
     125: ldc           #130                // String Check Input
     127: invokevirtual #134                // Method java/lang/Object.toString:()Ljava/lang/String;
     130: invokespecial #135                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     133: athrow
     134: ireturn
     135: iload_0
     136: tableswitch   { // 65 to 67
                    65: 164
                    66: 169
                    67: 174
               default: 179
          }
     164: bipush        8
     166: goto          192
     169: bipush        9
     171: goto          192
     174: bipush        7
     176: goto          192
     179: new           #128                // class java/lang/IllegalStateException
     182: dup
     183: ldc           #130                // String Check Input
     185: invokevirtual #134                // Method java/lang/Object.toString:()Ljava/lang/String;
     188: invokespecial #135                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     191: athrow
     192: ireturn
     193: new           #128                // class java/lang/IllegalStateException
     196: dup
     197: ldc           #130                // String Check Input
     199: invokevirtual #134                // Method java/lang/Object.toString:()Ljava/lang/String;
     202: invokespecial #135                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     205: athrow

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


/**
* https://www.codechef.com/problems/LAPIN
*
*
* Lapindromes Problem Code: LAPIN
*
* Lapindrome is defined as a string which when split in the middle, gives two halves
* having the same characters and same frequency of each character. If there are odd
* number of characters in the string, we ignore the middle character and check for
* lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have
* the same characters with same frequency. Also, abccab, rotor and xyzxy are a few
* examples of lapindromes. Note that abbaab is NOT a lapindrome. The two halves
* contain the same characters but their frequencies do not match.
*
* Your task is simple. Given a string, you need to tell if it is a lapindrome.
*
* Input:
* First line of input contains a single integer T, the number of test cases.
* Each test is a single line containing a string S composed of only lowercase English
* alphabet.
*
* Output:
* For each test case, output on a separate line: "YES" if the string is a lapindrome
* and "NO" if it is not.
*
* Constraints:
* 1 ≤ T ≤ 100
* 2 ≤ |S| ≤ 1000, where |S| denotes the length of S
*
*
* Example:
* Input:
* 6
* gaga
* abcde
* rotor
* xyzxy
* abbaab
* ababc
*
* Output:
* YES
* NO
* YES
* YES
* NO
* NO
*/

fun main(){
	//val inpString = "gaga"
	//val inpString = "abcde"
	//val inpString = "rotor"
	val inpString = "xyzxy"
	//val inpString = "abbaab"
	//val inpString = "ababc"
	//val inpString = "gotrej"
	//val inpString = "abcabcbb"
	//val inpString = "bbbbb"
	//val inpString = "pwwkew"
	//val inpString = ""

	LapindromeCheck(inpString)
}

fun LapindromeCheck(inputString: String): String{
	var isLapindrome = "NO"
	var strLen = inputString.trim().length
	var evenOdd = if (strLen % 2 == 0) 0 else 1

	if (strLen == 0) {
		println("Is BLANK a Lapindrome? : $isLapindrome")
		return isLapindrome
	}

	var charArray1 = inputString.substring(0, evenOdd+strLen/2).toCharArray()
	var charArray2 = inputString.substring(strLen/2, strLen).toCharArray()
	//println(charArray1)
	//println(charArray2)
	//println(charArray1.sorted().toString())
	//println(charArray2.sorted().toString())

	if (charArray1.sorted() == charArray2.sorted())
		isLapindrome = "YES"

	//var charArray1 = inputString.toList().slice(0..evenOdd+strLen/2)
	//var charArray2 = inputString.toList().slice(-1+strLen/2..strLen-1)
	//println(charArray1)
	//println(charArray2)

	println("Is $inputString a Lapindrome? : $isLapindrome")
	return isLapindrome
}

Compiled from "Lapindrome.kt"
public final class LapindromeKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String xyzxy
       2: astore_0
       3: aload_0
       4: invokestatic  #12                 // Method LapindromeCheck:(Ljava/lang/String;)Ljava/lang/String;
       7: pop
       8: return

  public static final java.lang.String LapindromeCheck(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #17                 // String inputString
       3: invokestatic  #23                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #25                 // String NO
       8: astore_1
       9: aload_0
      10: checkcast     #27                 // class java/lang/CharSequence
      13: invokestatic  #33                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      16: invokevirtual #37                 // Method java/lang/Object.toString:()Ljava/lang/String;
      19: invokevirtual #43                 // Method java/lang/String.length:()I
      22: istore_2
      23: iload_2
      24: iconst_2
      25: irem
      26: ifne          33
      29: iconst_0
      30: goto          34
      33: iconst_1
      34: istore_3
      35: iload_2
      36: ifne          67
      39: new           #45                 // class java/lang/StringBuilder
      42: dup
      43: invokespecial #48                 // Method java/lang/StringBuilder."<init>":()V
      46: ldc           #50                 // String Is BLANK a Lapindrome? :
      48: invokevirtual #54                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      51: aload_1
      52: invokevirtual #54                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      55: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      58: getstatic     #61                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: swap
      62: invokevirtual #67                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      65: aload_1
      66: areturn
      67: nop
      68: aload_0
      69: iconst_0
      70: iload_3
      71: iload_2
      72: iconst_2
      73: idiv
      74: iadd
      75: invokevirtual #71                 // Method java/lang/String.substring:(II)Ljava/lang/String;
      78: dup
      79: ldc           #73                 // String substring(...)
      81: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      84: invokevirtual #80                 // Method java/lang/String.toCharArray:()[C
      87: dup
      88: ldc           #82                 // String toCharArray(...)
      90: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      93: astore        4
      95: nop
      96: aload_0
      97: iload_2
      98: iconst_2
      99: idiv
     100: iload_2
     101: invokevirtual #71                 // Method java/lang/String.substring:(II)Ljava/lang/String;
     104: dup
     105: ldc           #73                 // String substring(...)
     107: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     110: invokevirtual #80                 // Method java/lang/String.toCharArray:()[C
     113: dup
     114: ldc           #82                 // String toCharArray(...)
     116: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     119: astore        5
     121: aload         4
     123: invokestatic  #88                 // Method kotlin/collections/ArraysKt.sorted:([C)Ljava/util/List;
     126: aload         5
     128: invokestatic  #88                 // Method kotlin/collections/ArraysKt.sorted:([C)Ljava/util/List;
     131: invokestatic  #92                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     134: ifeq          140
     137: ldc           #94                 // String YES
     139: astore_1
     140: new           #45                 // class java/lang/StringBuilder
     143: dup
     144: invokespecial #48                 // Method java/lang/StringBuilder."<init>":()V
     147: ldc           #96                 // String Is
     149: invokevirtual #54                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     152: aload_0
     153: invokevirtual #54                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     156: ldc           #98                 // String  a Lapindrome? :
     158: invokevirtual #54                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     161: aload_1
     162: invokevirtual #54                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     165: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     168: getstatic     #61                 // Field java/lang/System.out:Ljava/io/PrintStream;
     171: swap
     172: invokevirtual #67                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     175: aload_1
     176: areturn

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


/**
* https://leetcode.com/problems/two-sum/
*
* Two Sum Less Than K
*
* Given an array of integers nums and an integer target, return indices of the
* two numbers such that they add up to target.
*
* You may assume that each input would have exactly one solution, and you may
* not use the same element twice.
*
* You can return the answer in any order.
*
* Example 1:
* Input: nums = [2,7,11,15], target = 9
* Output: [0,1]
* Output: Because nums[0] + nums[1] == 9, we return [0, 1].
*
* Example 2:
* Input: nums = [3,2,4], target = 6
* Output: [1,2]
*
* Example 3:
* Input: nums = [3,3], target = 6
* Output: [0,1]
*
* Constraints:
*
* 2 <= nums.length <= 10^3
* -10^9 <= nums[i] <= 10^9
* -10^9 <= target <= 10^9
* Only one valid answer exists.
*/
import java.util.Arrays

fun main(){
	//val inputArray: IntArray = intArrayOf(2,7,11,15)
	//val targetSum = 9
	//val inputArray: IntArray = intArrayOf(3,2,4)
	//val targetSum = 6
	val inputArray: IntArray = intArrayOf(3,3)
	val targetSum = 6

	SumTwoNumbersEqualToTarget(inputArray, targetSum)
}

fun SumTwoNumbersEqualToTarget(intArray: IntArray, target: Int): IntArray {

	var result: IntArray = IntArray(2)
	val sumCheck: HashMap<Int, Int> = hashMapOf<Int, Int>()
	var sumPair = 0

	for (cnt in intArray.indices){
		sumPair = target - intArray[cnt]

		if (sumCheck.containsKey(sumPair)) {
			result[0] = sumCheck[sumPair]!!
			result[1] = cnt
		}
		sumCheck[intArray[cnt]] = cnt
	}

	println(Arrays.toString(result))
	return result
}

Compiled from "TwoSumEqualToTarget.kt"
public final class TwoSumEqualToTargetKt {
  public static final void main();
    Code:
       0: iconst_2
       1: newarray       int
       3: astore_1
       4: aload_1
       5: iconst_0
       6: iconst_3
       7: iastore
       8: aload_1
       9: iconst_1
      10: iconst_3
      11: iastore
      12: aload_1
      13: astore_0
      14: bipush        6
      16: istore_1
      17: aload_0
      18: iload_1
      19: invokestatic  #10                 // Method SumTwoNumbersEqualToTarget:([II)[I
      22: pop
      23: return

  public static final int[] SumTwoNumbersEqualToTarget(int[], int);
    Code:
       0: aload_0
       1: ldc           #17                 // String intArray
       3: invokestatic  #23                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_2
       7: newarray       int
       9: astore_2
      10: new           #25                 // class java/util/HashMap
      13: dup
      14: invokespecial #28                 // Method java/util/HashMap."<init>":()V
      17: astore_3
      18: iconst_0
      19: istore        4
      21: iconst_0
      22: istore        5
      24: aload_0
      25: arraylength
      26: istore        6
      28: iload         5
      30: iload         6
      32: if_icmpge     114
      35: iload_1
      36: aload_0
      37: iload         5
      39: iaload
      40: isub
      41: istore        4
      43: aload_3
      44: iload         4
      46: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: invokevirtual #38                 // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
      52: ifeq          82
      55: aload_2
      56: iconst_0
      57: aload_3
      58: iload         4
      60: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      63: invokevirtual #42                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      66: dup
      67: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      70: checkcast     #48                 // class java/lang/Number
      73: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      76: iastore
      77: aload_2
      78: iconst_1
      79: iload         5
      81: iastore
      82: iload         5
      84: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      87: astore        7
      89: aload_3
      90: checkcast     #54                 // class java/util/Map
      93: aload_0
      94: iload         5
      96: iaload
      97: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     100: aload         7
     102: invokeinterface #58,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     107: pop
     108: iinc          5, 1
     111: goto          28
     114: aload_2
     115: invokestatic  #64                 // Method java/util/Arrays.toString:([I)Ljava/lang/String;
     118: getstatic     #70                 // Field java/lang/System.out:Ljava/io/PrintStream;
     121: swap
     122: invokevirtual #75                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     125: aload_2
     126: areturn

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


/**
* https://leetcode.com/problems/two-sum-less-than-k/
*
* 1. Two Sum Less Than K
*
* Given an array A of integers and integer K, return the maximum S such that
* there exists i < j with A[i] + A[j] = S and S < K. If no i, j exist satisfying
* this equation, return -1.
*
* Example 1:
* Input: A = [34,23,1,24,75,33,54,8], K = 60
* Output: 58
* Explanation:
* We can use 34 and 24 to sum 58 which is less than 60.
*
* Example 2:
* Input: A = [10,20,30], K = 15
* Output: -1
* Explanation:
* In this case it's not possible to get a pair sum less that 15.
*
* Note:
* 1 <= A.length <= 100
* 1 <= A[i] <= 1000
* 1 <= K <= 2000
*/

fun main(){
	//val inputArray: IntArray = intArrayOf(34,23,1,24,75,33,54,8)
	//var targetSum = 60;
	val inputArray: IntArray = intArrayOf(10,20,30)
	var targetSum = 15;

	SumTwoNumbersLessThanTarget(inputArray, targetSum)
}

fun SumTwoNumbersLessThanTarget(intArray: IntArray, target: Int): Int {
	var SumLessThanTarget = -1

	return SumLessThanTarget
}

Compiled from "TwoSumLessThanTarget.kt"
public final class TwoSumLessThanTargetKt {
  public static final void main();
    Code:
       0: iconst_3
       1: newarray       int
       3: astore_1
       4: aload_1
       5: iconst_0
       6: bipush        10
       8: iastore
       9: aload_1
      10: iconst_1
      11: bipush        20
      13: iastore
      14: aload_1
      15: iconst_2
      16: bipush        30
      18: iastore
      19: aload_1
      20: astore_0
      21: bipush        15
      23: istore_1
      24: aload_0
      25: iload_1
      26: invokestatic  #10                 // Method SumTwoNumbersLessThanTarget:([II)I
      29: pop
      30: return

  public static final int SumTwoNumbersLessThanTarget(int[], int);
    Code:
       0: aload_0
       1: ldc           #17                 // String intArray
       3: invokestatic  #23                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_m1
       7: istore_2
       8: iload_2
       9: ireturn

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


fun main(args: Array<String>) {
    print(
        "answer1:${
            solution(
                listOf(
                    intArrayOf(1, 4),
                    intArrayOf(3, 4),
                    intArrayOf(3, 10)
                ).toTypedArray()
            ).contentToString()
        }\n"
    )
    print(
        "answer2:${
            solution(
                listOf(
                    intArrayOf(1, 1),
                    intArrayOf(2, 2),
                    intArrayOf(1, 2)
                ).toTypedArray()
            ).contentToString()
        }"
    )
}

/**
 * Follow direction from pointA to pointB
 */
fun getVector(pointA: IntArray, pointB: IntArray): IntArray = intArrayOf(pointB[0] - pointA[0], pointB[1] - pointA[1])

fun dotProduct(vectorA: IntArray, vectorB: IntArray): Int = vectorA[0] * vectorB[0] + vectorA[1] * vectorB[1]

/**
 * Use vector to calculate the fourth  point.
 * There is 2 problem need to be addressed
 * 1. define 2 vectors make the angle
 * 2. define the last point.
 * E.g:
 * Have rectangle ABCD: AB and BC combine to a angle at B when: vectorAB dotProduct vectorBC = 0
 * So B is the angle point --> vectorBA = vectorCD hence we can get D point (fourth  point)
 */
fun solution(v: Array<IntArray>): IntArray {

    if (v.size != 3) {
        throw Exception("Illegal parameter")
    }

    val length = v.size

    for (i in 0..length) {

        val subV = v.withIndex().filter { (j) -> j != i }.map { (j, value) -> value }

        val pA = v[i]
        val pB = subV[0]
        val pC = subV[1]

        val vectorAB = getVector(pA, pB)
        val vectorAC = getVector(pA, pC)
        val vectorBA = getVector(pB, pA)

        if (dotProduct(vectorAB, vectorAC) == 0) {
            val xD = pC[0] - vectorBA[0]
            val yD = pC[1] - vectorBA[1]
            return intArrayOf(xD, yD)
        }

    }
    throw Exception("Not found")
}

Compiled from "main.kt"
public final class MainKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #21                 // Method java/lang/StringBuilder."<init>":()V
      13: ldc           #23                 // String answer1:
      15: invokevirtual #27                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      18: iconst_3
      19: anewarray     #29                 // class "[I"
      22: astore_1
      23: aload_1
      24: iconst_0
      25: iconst_2
      26: newarray       int
      28: astore_2
      29: aload_2
      30: iconst_0
      31: iconst_1
      32: iastore
      33: aload_2
      34: iconst_1
      35: iconst_4
      36: iastore
      37: aload_2
      38: aastore
      39: aload_1
      40: iconst_1
      41: iconst_2
      42: newarray       int
      44: astore_2
      45: aload_2
      46: iconst_0
      47: iconst_3
      48: iastore
      49: aload_2
      50: iconst_1
      51: iconst_4
      52: iastore
      53: aload_2
      54: aastore
      55: aload_1
      56: iconst_2
      57: iconst_2
      58: newarray       int
      60: astore_2
      61: aload_2
      62: iconst_0
      63: iconst_3
      64: iastore
      65: aload_2
      66: iconst_1
      67: bipush        10
      69: iastore
      70: aload_2
      71: aastore
      72: aload_1
      73: checkcast     #31                 // class "[Ljava/lang/Object;"
      76: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      79: checkcast     #39                 // class java/util/Collection
      82: astore_1
      83: nop
      84: iconst_0
      85: istore_2
      86: aload_1
      87: astore_3
      88: aload_3
      89: iconst_0
      90: anewarray     #29                 // class "[I"
      93: invokeinterface #43,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
      98: checkcast     #45                 // class "[[I"
     101: invokestatic  #49                 // Method solution:([[I)[I
     104: invokestatic  #55                 // Method java/util/Arrays.toString:([I)Ljava/lang/String;
     107: dup
     108: ldc           #57                 // String toString(...)
     110: invokestatic  #60                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     113: invokevirtual #27                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     116: bipush        10
     118: invokevirtual #63                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     121: invokevirtual #66                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     124: astore_1
     125: getstatic     #72                 // Field java/lang/System.out:Ljava/io/PrintStream;
     128: aload_1
     129: invokevirtual #78                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     132: new           #17                 // class java/lang/StringBuilder
     135: dup
     136: invokespecial #21                 // Method java/lang/StringBuilder."<init>":()V
     139: ldc           #80                 // String answer2:
     141: invokevirtual #27                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     144: iconst_3
     145: anewarray     #29                 // class "[I"
     148: astore_1
     149: aload_1
     150: iconst_0
     151: iconst_2
     152: newarray       int
     154: astore_2
     155: aload_2
     156: iconst_0
     157: iconst_1
     158: iastore
     159: aload_2
     160: iconst_1
     161: iconst_1
     162: iastore
     163: aload_2
     164: aastore
     165: aload_1
     166: iconst_1
     167: iconst_2
     168: newarray       int
     170: astore_2
     171: aload_2
     172: iconst_0
     173: iconst_2
     174: iastore
     175: aload_2
     176: iconst_1
     177: iconst_2
     178: iastore
     179: aload_2
     180: aastore
     181: aload_1
     182: iconst_2
     183: iconst_2
     184: newarray       int
     186: astore_2
     187: aload_2
     188: iconst_0
     189: iconst_1
     190: iastore
     191: aload_2
     192: iconst_1
     193: iconst_2
     194: iastore
     195: aload_2
     196: aastore
     197: aload_1
     198: checkcast     #31                 // class "[Ljava/lang/Object;"
     201: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     204: checkcast     #39                 // class java/util/Collection
     207: astore_1
     208: nop
     209: iconst_0
     210: istore_2
     211: aload_1
     212: astore_3
     213: aload_3
     214: iconst_0
     215: anewarray     #29                 // class "[I"
     218: invokeinterface #43,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     223: checkcast     #45                 // class "[[I"
     226: invokestatic  #49                 // Method solution:([[I)[I
     229: invokestatic  #55                 // Method java/util/Arrays.toString:([I)Ljava/lang/String;
     232: dup
     233: ldc           #57                 // String toString(...)
     235: invokestatic  #60                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     238: invokevirtual #27                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     241: invokevirtual #66                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     244: astore_1
     245: getstatic     #72                 // Field java/lang/System.out:Ljava/io/PrintStream;
     248: aload_1
     249: invokevirtual #78                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     252: return

  public static final int[] getVector(int[], int[]);
    Code:
       0: aload_0
       1: ldc           #90                 // String pointA
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #92                 // String pointB
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_2
      13: newarray       int
      15: astore_2
      16: aload_2
      17: iconst_0
      18: aload_1
      19: iconst_0
      20: iaload
      21: aload_0
      22: iconst_0
      23: iaload
      24: isub
      25: iastore
      26: aload_2
      27: iconst_1
      28: aload_1
      29: iconst_1
      30: iaload
      31: aload_0
      32: iconst_1
      33: iaload
      34: isub
      35: iastore
      36: aload_2
      37: areturn

  public static final int dotProduct(int[], int[]);
    Code:
       0: aload_0
       1: ldc           #96                 // String vectorA
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #98                 // String vectorB
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iconst_0
      14: iaload
      15: aload_1
      16: iconst_0
      17: iaload
      18: imul
      19: aload_0
      20: iconst_1
      21: iaload
      22: aload_1
      23: iconst_1
      24: iaload
      25: imul
      26: iadd
      27: ireturn

  public static final int[] solution(int[][]);
    Code:
       0: aload_0
       1: ldc           #100                // String v
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #31                 // class "[Ljava/lang/Object;"
      10: arraylength
      11: iconst_3
      12: if_icmpeq     25
      15: new           #102                // class java/lang/Exception
      18: dup
      19: ldc           #104                // String Illegal parameter
      21: invokespecial #107                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
      24: athrow
      25: aload_0
      26: checkcast     #31                 // class "[Ljava/lang/Object;"
      29: arraylength
      30: istore_1
      31: iconst_0
      32: istore_2
      33: iload_2
      34: iload_1
      35: if_icmpgt     381
      38: aload_0
      39: checkcast     #31                 // class "[Ljava/lang/Object;"
      42: invokestatic  #113                // Method kotlin/collections/ArraysKt.withIndex:([Ljava/lang/Object;)Ljava/lang/Iterable;
      45: astore        4
      47: iconst_0
      48: istore        5
      50: aload         4
      52: astore        6
      54: new           #115                // class java/util/ArrayList
      57: dup
      58: invokespecial #116                // Method java/util/ArrayList."<init>":()V
      61: checkcast     #39                 // class java/util/Collection
      64: astore        7
      66: iconst_0
      67: istore        8
      69: aload         6
      71: invokeinterface #122,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      76: astore        9
      78: aload         9
      80: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      85: ifeq          141
      88: aload         9
      90: invokeinterface #132,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      95: astore        10
      97: aload         10
      99: checkcast     #134                // class kotlin/collections/IndexedValue
     102: astore        11
     104: iconst_0
     105: istore        12
     107: aload         11
     109: invokevirtual #138                // Method kotlin/collections/IndexedValue.component1:()I
     112: istore        13
     114: iload         13
     116: iload_2
     117: if_icmpeq     124
     120: iconst_1
     121: goto          125
     124: iconst_0
     125: ifeq          78
     128: aload         7
     130: aload         10
     132: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     137: pop
     138: goto          78
     141: aload         7
     143: checkcast     #144                // class java/util/List
     146: nop
     147: checkcast     #118                // class java/lang/Iterable
     150: astore        4
     152: nop
     153: iconst_0
     154: istore        5
     156: aload         4
     158: astore        6
     160: new           #115                // class java/util/ArrayList
     163: dup
     164: aload         4
     166: bipush        10
     168: invokestatic  #148                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     171: invokespecial #151                // Method java/util/ArrayList."<init>":(I)V
     174: checkcast     #39                 // class java/util/Collection
     177: astore        7
     179: iconst_0
     180: istore        8
     182: aload         6
     184: invokeinterface #122,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     189: astore        9
     191: aload         9
     193: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     198: ifeq          255
     201: aload         9
     203: invokeinterface #132,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     208: astore        10
     210: aload         7
     212: aload         10
     214: checkcast     #134                // class kotlin/collections/IndexedValue
     217: astore        11
     219: astore        15
     221: iconst_0
     222: istore        12
     224: aload         11
     226: invokevirtual #138                // Method kotlin/collections/IndexedValue.component1:()I
     229: istore        13
     231: aload         11
     233: invokevirtual #154                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     236: checkcast     #29                 // class "[I"
     239: astore        14
     241: aload         14
     243: aload         15
     245: swap
     246: invokeinterface #142,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     251: pop
     252: goto          191
     255: aload         7
     257: checkcast     #144                // class java/util/List
     260: nop
     261: astore_3
     262: aload_0
     263: iload_2
     264: aaload
     265: astore        4
     267: aload_3
     268: iconst_0
     269: invokeinterface #158,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     274: checkcast     #29                 // class "[I"
     277: astore        5
     279: aload_3
     280: iconst_1
     281: invokeinterface #158,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     286: checkcast     #29                 // class "[I"
     289: astore        6
     291: aload         4
     293: aload         5
     295: invokestatic  #160                // Method getVector:([I[I)[I
     298: astore        7
     300: aload         4
     302: aload         6
     304: invokestatic  #160                // Method getVector:([I[I)[I
     307: astore        8
     309: aload         5
     311: aload         4
     313: invokestatic  #160                // Method getVector:([I[I)[I
     316: astore        9
     318: aload         7
     320: aload         8
     322: invokestatic  #162                // Method dotProduct:([I[I)I
     325: ifne          370
     328: aload         6
     330: iconst_0
     331: iaload
     332: aload         9
     334: iconst_0
     335: iaload
     336: isub
     337: istore        10
     339: aload         6
     341: iconst_1
     342: iaload
     343: aload         9
     345: iconst_1
     346: iaload
     347: isub
     348: istore        11
     350: iconst_2
     351: newarray       int
     353: astore        12
     355: aload         12
     357: iconst_0
     358: iload         10
     360: iastore
     361: aload         12
     363: iconst_1
     364: iload         11
     366: iastore
     367: aload         12
     369: areturn
     370: iload_2
     371: iload_1
     372: if_icmpeq     381
     375: iinc          2, 1
     378: goto          38
     381: new           #102                // class java/lang/Exception
     384: dup
     385: ldc           #164                // String Not found
     387: invokespecial #107                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
     390: athrow
}


/**
 * P14-Longest Collatz sequence
 * The following iterative sequence is defined for the set of positive integers:
 *      n → n/2 (n is even)
 *      n → 3n + 1 (n is odd)
 * Using the rule above and starting with 13, we generate the following sequence:
 *      13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
 * It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.
 * Which starting number, under one million, produces the longest chain?
 * NOTE: Once the chain starts the terms are allowed to go above one million.
 */
fun p14() {
    var term: Long
    var termCount: Int
    var greatestTermCount = 0
    var greatest = 0L
    repeat(1_000_000) {
        termCount = 1
        term = it.toLong()
        while (term > 1) {
            term = if (term % 2 == 0L) term / 2 else 3 * term + 1
            termCount++
        }
        if(termCount > greatestTermCount) {
            greatest = it.toLong()
            greatestTermCount = termCount
        }
    }
    println("A14: $greatest")
}

Compiled from "P014_LongestCollatzSequence.kt"
public final class P014_LongestCollatzSequenceKt {
  public static final void p14();
    Code:
       0: lconst_0
       1: lstore        6
       3: iconst_0
       4: istore_0
       5: iconst_0
       6: istore_1
       7: lconst_0
       8: lstore        8
      10: ldc           #7                  // int 1000000
      12: istore_2
      13: iconst_0
      14: istore_3
      15: iload_3
      16: iload_2
      17: if_icmpge     93
      20: iload_3
      21: istore        4
      23: iconst_0
      24: istore        5
      26: iconst_1
      27: istore_0
      28: iload         4
      30: i2l
      31: lstore        6
      33: lload         6
      35: lconst_1
      36: lcmp
      37: ifle          74
      40: lload         6
      42: iconst_2
      43: i2l
      44: lrem
      45: lconst_0
      46: lcmp
      47: ifne          58
      50: lload         6
      52: iconst_2
      53: i2l
      54: ldiv
      55: goto          65
      58: iconst_3
      59: i2l
      60: lload         6
      62: lmul
      63: lconst_1
      64: ladd
      65: lstore        6
      67: iload_0
      68: iconst_1
      69: iadd
      70: istore_0
      71: goto          33
      74: iload_0
      75: iload_1
      76: if_icmple     86
      79: iload         4
      81: i2l
      82: lstore        8
      84: iload_0
      85: istore_1
      86: nop
      87: iinc          3, 1
      90: goto          15
      93: new           #9                  // class java/lang/StringBuilder
      96: dup
      97: invokespecial #12                 // Method java/lang/StringBuilder."<init>":()V
     100: ldc           #14                 // String A14:
     102: invokevirtual #18                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     105: lload         8
     107: invokevirtual #21                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     110: invokevirtual #25                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     113: getstatic     #31                 // Field java/lang/System.out:Ljava/io/PrintStream;
     116: swap
     117: invokevirtual #37                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     120: return
}


Compiled from "P018_MaximumPathSum.kt"
public final class P018_MaximumPathSumKt {
  public static final java.lang.String str;

  private static final java.util.List<java.util.List<java.lang.Integer>> rows;

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

  public static final void p18();
    Code:
       0: iconst_0
       1: iconst_0
       2: iconst_0
       3: invokestatic  #18                 // Method getMax:(III)I
       6: istore_0
       7: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      10: iload_0
      11: invokevirtual #30                 // Method java/io/PrintStream.print:(I)V
      14: return

  public static final int getMax(int, int, int);
    Code:
       0: iload_1
       1: getstatic     #12                 // Field rows:Ljava/util/List;
       4: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
       7: if_icmple     38
      10: new           #38                 // class java/lang/StringBuilder
      13: dup
      14: invokespecial #41                 // Method java/lang/StringBuilder."<init>":()V
      17: ldc           #43                 // String Total:
      19: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: iload_0
      23: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      26: invokevirtual #54                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      29: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      32: swap
      33: invokevirtual #58                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      36: iload_0
      37: ireturn
      38: new           #38                 // class java/lang/StringBuilder
      41: dup
      42: invokespecial #41                 // Method java/lang/StringBuilder."<init>":()V
      45: ldc           #60                 // String ->
      47: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      50: getstatic     #12                 // Field rows:Ljava/util/List;
      53: iload_1
      54: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      59: checkcast     #62                 // class java/util/List
      62: iload_2
      63: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      68: checkcast     #68                 // class java/lang/Number
      71: invokevirtual #72                 // Method java/lang/Number.intValue:()I
      74: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      77: ldc           #74                 // String  [
      79: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      82: iload_1
      83: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      86: bipush        44
      88: invokevirtual #77                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      91: iload_2
      92: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      95: ldc           #79                 // String ] sum:
      97: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     100: iload_0
     101: getstatic     #12                 // Field rows:Ljava/util/List;
     104: iload_1
     105: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     110: checkcast     #62                 // class java/util/List
     113: iload_2
     114: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     119: checkcast     #68                 // class java/lang/Number
     122: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     125: iadd
     126: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     129: invokevirtual #54                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     132: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
     135: swap
     136: invokevirtual #58                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     139: iload_0
     140: getstatic     #12                 // Field rows:Ljava/util/List;
     143: iload_1
     144: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     149: checkcast     #62                 // class java/util/List
     152: iload_2
     153: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     158: checkcast     #68                 // class java/lang/Number
     161: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     164: iadd
     165: iload_1
     166: iconst_1
     167: iadd
     168: iload_2
     169: invokestatic  #18                 // Method getMax:(III)I
     172: iload_0
     173: getstatic     #12                 // Field rows:Ljava/util/List;
     176: iload_1
     177: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     182: checkcast     #62                 // class java/util/List
     185: iload_2
     186: invokeinterface #66,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     191: checkcast     #68                 // class java/lang/Number
     194: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     197: iadd
     198: iload_1
     199: iconst_1
     200: iadd
     201: iload_2
     202: iconst_1
     203: iadd
     204: invokestatic  #18                 // Method getMax:(III)I
     207: invokestatic  #85                 // Method java/lang/Math.max:(II)I
     210: ireturn

  static {};
    Code:
       0: ldc           #92                 // String 75\n95 64\n17 47 82\n18 35 87 10\n20 04 82 47 65\n19 01 23 75 03 34\n88 02 77 73 07 63 67\n99 65 04 28 06 16 70 92\n41 41 26 56 83 40 80 70 33\n41 48 72 33 47 32 37 16 94 29\n53 71 44 65 25 43 91 52 97 51 14\n70 11 33 28 77 73 17 78 39 68 17 57\n91 71 52 38 17 14 91 43 58 50 27 29 48\n63 66 04 68 89 53 67 30 73 16 69 87 40 31\n04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
       2: checkcast     #94                 // class java/lang/CharSequence
       5: iconst_1
       6: anewarray     #96                 // class java/lang/String
       9: astore_0
      10: aload_0
      11: iconst_0
      12: ldc           #98                 // String \n
      14: aastore
      15: aload_0
      16: iconst_0
      17: iconst_0
      18: bipush        6
      20: aconst_null
      21: invokestatic  #104                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      24: checkcast     #106                // class java/lang/Iterable
      27: astore_0
      28: iconst_0
      29: istore_1
      30: aload_0
      31: astore_2
      32: new           #108                // class java/util/ArrayList
      35: dup
      36: aload_0
      37: bipush        10
      39: invokestatic  #112                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      42: invokespecial #114                // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #116                // class java/util/Collection
      48: astore_3
      49: iconst_0
      50: istore        4
      52: aload_2
      53: invokeinterface #120,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        5
      60: aload         5
      62: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          235
      70: aload         5
      72: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        6
      79: aload_3
      80: aload         6
      82: checkcast     #96                 // class java/lang/String
      85: astore        7
      87: astore        19
      89: iconst_0
      90: istore        8
      92: aload         7
      94: checkcast     #94                 // class java/lang/CharSequence
      97: iconst_1
      98: anewarray     #96                 // class java/lang/String
     101: astore        9
     103: aload         9
     105: iconst_0
     106: ldc           #132                // String
     108: aastore
     109: aload         9
     111: iconst_0
     112: iconst_0
     113: bipush        6
     115: aconst_null
     116: invokestatic  #104                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     119: checkcast     #106                // class java/lang/Iterable
     122: astore        9
     124: iconst_0
     125: istore        10
     127: aload         9
     129: astore        11
     131: new           #108                // class java/util/ArrayList
     134: dup
     135: aload         9
     137: bipush        10
     139: invokestatic  #112                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     142: invokespecial #114                // Method java/util/ArrayList."<init>":(I)V
     145: checkcast     #116                // class java/util/Collection
     148: astore        12
     150: iconst_0
     151: istore        13
     153: aload         11
     155: invokeinterface #120,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     160: astore        14
     162: aload         14
     164: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     169: ifeq          216
     172: aload         14
     174: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     179: astore        15
     181: aload         12
     183: aload         15
     185: checkcast     #96                 // class java/lang/String
     188: astore        16
     190: astore        17
     192: iconst_0
     193: istore        18
     195: aload         16
     197: invokestatic  #138                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     200: nop
     201: invokestatic  #142                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     204: aload         17
     206: swap
     207: invokeinterface #146,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     212: pop
     213: goto          162
     216: aload         12
     218: checkcast     #62                 // class java/util/List
     221: nop
     222: nop
     223: aload         19
     225: swap
     226: invokeinterface #146,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     231: pop
     232: goto          60
     235: aload_3
     236: checkcast     #62                 // class java/util/List
     239: nop
     240: putstatic     #12                 // Field rows:Ljava/util/List;
     243: return
}


/**
 * P21 - Amicable Numbers
 *
 * Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
 * If d(a) = b and d(b) = a, where a ≠ b,
 * then a and b are an amicable pair and each of a and b are called amicable numbers.
 *
 * For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284.
 * The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.
 *
 * Evaluate the sum of all the amicable numbers under 10000.
 */
fun p21() {
    val pairs: MutableList<Pair<Int, Int>> = mutableListOf((0 to 0))
    val boundary = 10000
    var n: Int; var dn: Int

    for (i in 1..boundary) {
        n = i
        dn = 0
        for (j in 1 until n) if (n % j == 0) dn += j
        pairs.add(n to dn)
    }

    fun d(x: Int): Int  = pairs[x].second

    var a: Int; var b: Int; var sum = 0
    for (i in pairs) {
        a = i.first
        b = i.second
        if (a < boundary && b < boundary && a != b && a == d(b) && b == d(a)) sum += a
    }
    println("A21: $sum")
}

Compiled from "P021_AmicableNumber.kt"
public final class P021_AmicableNumberKt {
  public static final void p21();
    Code:
       0: iconst_1
       1: anewarray     #8                  // class kotlin/Pair
       4: astore_1
       5: aload_1
       6: iconst_0
       7: iconst_0
       8: invokestatic  #14                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      11: iconst_0
      12: invokestatic  #14                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: invokestatic  #20                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      18: aastore
      19: aload_1
      20: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      23: astore_0
      24: sipush        10000
      27: istore_1
      28: iconst_0
      29: istore_2
      30: iconst_0
      31: istore_3
      32: iconst_1
      33: istore        4
      35: iload         4
      37: istore_2
      38: iconst_0
      39: istore_3
      40: iconst_1
      41: istore        5
      43: iload_2
      44: istore        6
      46: iload         5
      48: iload         6
      50: if_icmpge     71
      53: iload_2
      54: iload         5
      56: irem
      57: ifne          65
      60: iload_3
      61: iload         5
      63: iadd
      64: istore_3
      65: iinc          5, 1
      68: goto          46
      71: aload_0
      72: iload_2
      73: invokestatic  #14                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      76: iload_3
      77: invokestatic  #14                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: invokestatic  #20                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      83: invokeinterface #32,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      88: pop
      89: iload         4
      91: iload_1
      92: if_icmpeq     101
      95: iinc          4, 1
      98: goto          35
     101: iconst_0
     102: istore        4
     104: iconst_0
     105: istore        5
     107: iconst_0
     108: istore        6
     110: aload_0
     111: invokeinterface #36,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     116: astore        7
     118: aload         7
     120: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          217
     128: aload         7
     130: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: checkcast     #8                  // class kotlin/Pair
     138: astore        8
     140: aload         8
     142: invokevirtual #49                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     145: checkcast     #51                 // class java/lang/Number
     148: invokevirtual #55                 // Method java/lang/Number.intValue:()I
     151: istore        4
     153: aload         8
     155: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     158: checkcast     #51                 // class java/lang/Number
     161: invokevirtual #55                 // Method java/lang/Number.intValue:()I
     164: istore        5
     166: iload         4
     168: iload_1
     169: if_icmpge     118
     172: iload         5
     174: iload_1
     175: if_icmpge     118
     178: iload         4
     180: iload         5
     182: if_icmpeq     118
     185: iload         4
     187: aload_0
     188: iload         5
     190: invokestatic  #62                 // Method p21$d:(Ljava/util/List;I)I
     193: if_icmpne     118
     196: iload         5
     198: aload_0
     199: iload         4
     201: invokestatic  #62                 // Method p21$d:(Ljava/util/List;I)I
     204: if_icmpne     118
     207: iload         6
     209: iload         4
     211: iadd
     212: istore        6
     214: goto          118
     217: new           #64                 // class java/lang/StringBuilder
     220: dup
     221: invokespecial #67                 // Method java/lang/StringBuilder."<init>":()V
     224: ldc           #69                 // String A21:
     226: invokevirtual #73                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     229: iload         6
     231: invokevirtual #76                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     234: invokevirtual #80                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     237: getstatic     #86                 // Field java/lang/System.out:Ljava/io/PrintStream;
     240: swap
     241: invokevirtual #92                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     244: return

  private static final int p21$d(java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #8                  // class kotlin/Pair
      10: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      13: checkcast     #51                 // class java/lang/Number
      16: invokevirtual #55                 // Method java/lang/Number.intValue:()I
      19: ireturn
}