import kotlin.String
import kotlin.collections.List

object Day9 {
    fun part1(input: List<String>): String {
        return parse(input)
            .sumOf { extrapolate(it) { deltas, ret -> deltas.last() + ret } }.toString()
    }

    fun part2(input: List<String>): String {
        return parse(input)
            .sumOf { extrapolate(it) { deltas, ret -> deltas.first() - ret } }.toString()
    }

    private fun parse(input: List<String>): List<List<Long>> {
        return input.map { it.split("\\s+".toRegex()).map { it.toLong() } }
    }

    private fun extrapolate(input: List<Long>, extrapolator: (List<Long>, Long) -> Long): Long {
        val deltas = input.zipWithNext().map { (a, b) -> b - a }
        if (deltas.all { it == 0L }) {
            return extrapolator(input, 0)
        }
        return extrapolator(input, extrapolate(deltas, extrapolator))
    }
}

Compiled from "Day9.kt"
public final class Day9 {
  public static final Day9 INSTANCE;

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

  public final java.lang.String part1(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #26                 // Method parse:(Ljava/util/List;)Ljava/util/List;
      11: checkcast     #28                 // class java/lang/Iterable
      14: astore_2
      15: lconst_0
      16: lstore_3
      17: aload_2
      18: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      23: astore        5
      25: aload         5
      27: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      32: ifeq          81
      35: aload         5
      37: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: astore        6
      44: lload_3
      45: aload         6
      47: checkcast     #44                 // class java/util/List
      50: astore        7
      52: lstore        9
      54: iconst_0
      55: istore        8
      57: getstatic     #47                 // Field INSTANCE:LDay9;
      60: aload         7
      62: invokedynamic #67,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
      67: invokespecial #71                 // Method extrapolate:(Ljava/util/List;Lkotlin/jvm/functions/Function2;)J
      70: lstore        11
      72: lload         9
      74: lload         11
      76: ladd
      77: lstore_3
      78: goto          25
      81: lload_3
      82: invokestatic  #77                 // Method java/lang/String.valueOf:(J)Ljava/lang/String;
      85: areturn

  public final java.lang.String part2(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #26                 // Method parse:(Ljava/util/List;)Ljava/util/List;
      11: checkcast     #28                 // class java/lang/Iterable
      14: astore_2
      15: lconst_0
      16: lstore_3
      17: aload_2
      18: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      23: astore        5
      25: aload         5
      27: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      32: ifeq          81
      35: aload         5
      37: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: astore        6
      44: lload_3
      45: aload         6
      47: checkcast     #44                 // class java/util/List
      50: astore        7
      52: lstore        9
      54: iconst_0
      55: istore        8
      57: getstatic     #47                 // Field INSTANCE:LDay9;
      60: aload         7
      62: invokedynamic #87,  0             // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function2;
      67: invokespecial #71                 // Method extrapolate:(Ljava/util/List;Lkotlin/jvm/functions/Function2;)J
      70: lstore        11
      72: lload         9
      74: lload         11
      76: ladd
      77: lstore_3
      78: goto          25
      81: lload_3
      82: invokestatic  #77                 // Method java/lang/String.valueOf:(J)Ljava/lang/String;
      85: areturn

  private final java.util.List<java.util.List<java.lang.Long>> parse(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #28                 // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: astore        4
      10: new           #91                 // class java/util/ArrayList
      13: dup
      14: aload_2
      15: bipush        10
      17: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      20: invokespecial #100                // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #102                // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        6
      31: aload         4
      33: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        7
      40: aload         7
      42: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          220
      50: aload         7
      52: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        8
      59: aload         5
      61: aload         8
      63: checkcast     #73                 // class java/lang/String
      66: astore        9
      68: astore        21
      70: iconst_0
      71: istore        10
      73: aload         9
      75: checkcast     #104                // class java/lang/CharSequence
      78: astore        11
      80: new           #106                // class kotlin/text/Regex
      83: dup
      84: ldc           #108                // String \\s+
      86: invokespecial #111                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      89: astore        12
      91: iconst_0
      92: istore        13
      94: aload         12
      96: aload         11
      98: iload         13
     100: invokevirtual #115                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
     103: checkcast     #28                 // class java/lang/Iterable
     106: astore        11
     108: nop
     109: iconst_0
     110: istore        12
     112: aload         11
     114: astore        13
     116: new           #91                 // class java/util/ArrayList
     119: dup
     120: aload         11
     122: bipush        10
     124: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     127: invokespecial #100                // Method java/util/ArrayList."<init>":(I)V
     130: checkcast     #102                // class java/util/Collection
     133: astore        14
     135: iconst_0
     136: istore        15
     138: aload         13
     140: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     145: astore        16
     147: aload         16
     149: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     154: ifeq          201
     157: aload         16
     159: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     164: astore        17
     166: aload         14
     168: aload         17
     170: checkcast     #73                 // class java/lang/String
     173: astore        18
     175: astore        19
     177: iconst_0
     178: istore        20
     180: aload         18
     182: invokestatic  #121                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     185: nop
     186: invokestatic  #124                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     189: aload         19
     191: swap
     192: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     197: pop
     198: goto          147
     201: aload         14
     203: checkcast     #44                 // class java/util/List
     206: nop
     207: nop
     208: aload         21
     210: swap
     211: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     216: pop
     217: goto          40
     220: aload         5
     222: checkcast     #44                 // class java/util/List
     225: nop
     226: areturn

  private final long extrapolate(java.util.List<java.lang.Long>, kotlin.jvm.functions.Function2<? super java.util.List<java.lang.Long>, ? super java.lang.Long, java.lang.Long>);
    Code:
       0: aload_1
       1: checkcast     #28                 // class java/lang/Iterable
       4: invokestatic  #145                // Method kotlin/collections/CollectionsKt.zipWithNext:(Ljava/lang/Iterable;)Ljava/util/List;
       7: checkcast     #28                 // class java/lang/Iterable
      10: astore        4
      12: iconst_0
      13: istore        5
      15: aload         4
      17: astore        6
      19: new           #91                 // class java/util/ArrayList
      22: dup
      23: aload         4
      25: bipush        10
      27: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      30: invokespecial #100                // Method java/util/ArrayList."<init>":(I)V
      33: checkcast     #102                // class java/util/Collection
      36: astore        7
      38: iconst_0
      39: istore        8
      41: aload         6
      43: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        9
      50: aload         9
      52: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          129
      60: aload         9
      62: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        10
      69: aload         7
      71: aload         10
      73: checkcast     #147                // class kotlin/Pair
      76: astore        11
      78: astore        17
      80: iconst_0
      81: istore        12
      83: aload         11
      85: invokevirtual #150                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      88: checkcast     #152                // class java/lang/Number
      91: invokevirtual #156                // Method java/lang/Number.longValue:()J
      94: lstore        13
      96: aload         11
      98: invokevirtual #159                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     101: checkcast     #152                // class java/lang/Number
     104: invokevirtual #156                // Method java/lang/Number.longValue:()J
     107: lstore        15
     109: lload         15
     111: lload         13
     113: lsub
     114: invokestatic  #124                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     117: aload         17
     119: swap
     120: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     125: pop
     126: goto          50
     129: aload         7
     131: checkcast     #44                 // class java/util/List
     134: nop
     135: astore_3
     136: aload_3
     137: checkcast     #28                 // class java/lang/Iterable
     140: astore        4
     142: iconst_0
     143: istore        5
     145: aload         4
     147: instanceof    #102                // class java/util/Collection
     150: ifeq          170
     153: aload         4
     155: checkcast     #102                // class java/util/Collection
     158: invokeinterface #162,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     163: ifeq          170
     166: iconst_1
     167: goto          231
     170: aload         4
     172: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     177: astore        6
     179: aload         6
     181: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     186: ifeq          230
     189: aload         6
     191: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     196: astore        7
     198: aload         7
     200: checkcast     #152                // class java/lang/Number
     203: invokevirtual #156                // Method java/lang/Number.longValue:()J
     206: lstore        8
     208: iconst_0
     209: istore        10
     211: lload         8
     213: lconst_0
     214: lcmp
     215: ifne          222
     218: iconst_1
     219: goto          223
     222: iconst_0
     223: ifne          179
     226: iconst_0
     227: goto          231
     230: iconst_1
     231: ifeq          252
     234: aload_2
     235: aload_1
     236: lconst_0
     237: invokestatic  #124                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     240: invokeinterface #166,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     245: checkcast     #152                // class java/lang/Number
     248: invokevirtual #156                // Method java/lang/Number.longValue:()J
     251: lreturn
     252: aload_2
     253: aload_1
     254: aload_0
     255: aload_3
     256: aload_2
     257: invokespecial #71                 // Method extrapolate:(Ljava/util/List;Lkotlin/jvm/functions/Function2;)J
     260: invokestatic  #124                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     263: invokeinterface #166,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     268: checkcast     #152                // class java/lang/Number
     271: invokevirtual #156                // Method java/lang/Number.longValue:()J
     274: lreturn

  private static final long part1$lambda$1$lambda$0(java.util.List, long);
    Code:
       0: aload_0
       1: ldc           #178                // String deltas
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #182                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      10: checkcast     #152                // class java/lang/Number
      13: invokevirtual #156                // Method java/lang/Number.longValue:()J
      16: lload_1
      17: ladd
      18: lreturn

  private static final long part2$lambda$3$lambda$2(java.util.List, long);
    Code:
       0: aload_0
       1: ldc           #178                // String deltas
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #186                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      10: checkcast     #152                // class java/lang/Number
      13: invokevirtual #156                // Method java/lang/Number.longValue:()J
      16: lload_1
      17: lsub
      18: lreturn

  static {};
    Code:
       0: new           #2                  // class Day9
       3: dup
       4: invokespecial #188                // Method "<init>":()V
       7: putstatic     #47                 // Field INSTANCE:LDay9;
      10: return
}


import java.io.File

// Problem:
// https://adventofcode.com/2022/day/3

// More solutions:
// https://www.competitivecoders.com/ProgrammingCompetitions/advent-of-code/advent-of-code/2022/day-3/

fun main() {

    fun part1(input: List<String>): Int {

        return input.map { row ->
            val parts = row.chunked(row.length / 2)
            for (c in parts[0]) {
                if (parts[1].contains(c)) {
                    return@map if (c.code > 96) c.code - 96 else c.code - 64 + 26
                }
            }
            return@map 0
        }.sum()

    }

    fun part2(input: List<String>): Int {

        return input.chunked(3).map {

            for (c in it[0]) {

               if (it[1].contains(c) && it[2].contains(c)){
                   return@map if (c.code > 96) c.code - 96 else c.code - 64 + 26
               }

            }
           return@map 0
       }.sum()
    }

    val input = readInput("Day03")
    println("Part 1: ${part1(input)}")
    println("Part 2: ${part2(input)}")
}

private fun readInput(name: String) = File("src", "$name.txt")
    .readLines()

Compiled from "Day03.kt"
public final class Day03Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day03
       2: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: new           #14                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
      13: ldc           #19                 // String Part 1:
      15: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      18: aload_0
      19: invokestatic  #27                 // Method main$part1:(Ljava/util/List;)I
      22: invokevirtual #30                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      25: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      28: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: swap
      32: invokevirtual #46                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      35: new           #14                 // class java/lang/StringBuilder
      38: dup
      39: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
      42: ldc           #48                 // String Part 2:
      44: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      47: aload_0
      48: invokestatic  #51                 // Method main$part2:(Ljava/util/List;)I
      51: invokevirtual #30                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      54: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      57: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      60: swap
      61: invokevirtual #46                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      64: return

  private static final java.util.List<java.lang.String> readInput(java.lang.String);
    Code:
       0: new           #56                 // class java/io/File
       3: dup
       4: ldc           #58                 // String src
       6: new           #14                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
      13: aload_0
      14: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      17: ldc           #60                 // String .txt
      19: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      25: invokespecial #63                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      28: aconst_null
      29: iconst_1
      30: aconst_null
      31: invokestatic  #69                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      34: areturn

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

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #79                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #81                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #87                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #90                 // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #92                 // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #96,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          197
      48: aload         6
      50: invokeinterface #106,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #108                // class java/lang/String
      64: astore        8
      66: astore        15
      68: iconst_0
      69: istore        9
      71: aload         8
      73: checkcast     #110                // class java/lang/CharSequence
      76: aload         8
      78: invokevirtual #114                // Method java/lang/String.length:()I
      81: iconst_2
      82: idiv
      83: invokestatic  #120                // Method kotlin/text/StringsKt.chunked:(Ljava/lang/CharSequence;I)Ljava/util/List;
      86: astore        10
      88: aload         10
      90: iconst_0
      91: invokeinterface #126,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      96: checkcast     #108                // class java/lang/String
      99: astore        11
     101: iconst_0
     102: istore        12
     104: aload         11
     106: invokevirtual #114                // Method java/lang/String.length:()I
     109: istore        13
     111: iload         12
     113: iload         13
     115: if_icmpge     181
     118: aload         11
     120: iload         12
     122: invokevirtual #130                // Method java/lang/String.charAt:(I)C
     125: istore        14
     127: aload         10
     129: iconst_1
     130: invokeinterface #126,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     135: checkcast     #110                // class java/lang/CharSequence
     138: iload         14
     140: iconst_0
     141: iconst_2
     142: aconst_null
     143: invokestatic  #134                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     146: ifeq          175
     149: iload         14
     151: bipush        96
     153: if_icmple     164
     156: iload         14
     158: bipush        96
     160: isub
     161: goto          182
     164: iload         14
     166: bipush        64
     168: isub
     169: bipush        26
     171: iadd
     172: goto          182
     175: iinc          12, 1
     178: goto          111
     181: iconst_0
     182: invokestatic  #140                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     185: aload         15
     187: swap
     188: invokeinterface #144,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     193: pop
     194: goto          38
     197: aload         4
     199: checkcast     #122                // class java/util/List
     202: nop
     203: checkcast     #79                 // class java/lang/Iterable
     206: invokestatic  #148                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     209: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #79                 // class java/lang/Iterable
       4: iconst_3
       5: invokestatic  #166                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
       8: checkcast     #79                 // class java/lang/Iterable
      11: astore_1
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #81                 // class java/util/ArrayList
      19: dup
      20: aload_1
      21: bipush        10
      23: invokestatic  #87                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #90                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #92                 // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload_3
      38: invokeinterface #96,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        6
      45: aload         6
      47: invokeinterface #102,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          209
      55: aload         6
      57: invokeinterface #106,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        7
      64: aload         4
      66: aload         7
      68: checkcast     #122                // class java/util/List
      71: astore        8
      73: astore        14
      75: iconst_0
      76: istore        9
      78: aload         8
      80: iconst_0
      81: invokeinterface #126,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      86: checkcast     #108                // class java/lang/String
      89: astore        10
      91: iconst_0
      92: istore        11
      94: aload         10
      96: invokevirtual #114                // Method java/lang/String.length:()I
      99: istore        12
     101: iload         11
     103: iload         12
     105: if_icmpge     193
     108: aload         10
     110: iload         11
     112: invokevirtual #130                // Method java/lang/String.charAt:(I)C
     115: istore        13
     117: aload         8
     119: iconst_1
     120: invokeinterface #126,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     125: checkcast     #110                // class java/lang/CharSequence
     128: iload         13
     130: iconst_0
     131: iconst_2
     132: aconst_null
     133: invokestatic  #134                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     136: ifeq          187
     139: aload         8
     141: iconst_2
     142: invokeinterface #126,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     147: checkcast     #110                // class java/lang/CharSequence
     150: iload         13
     152: iconst_0
     153: iconst_2
     154: aconst_null
     155: invokestatic  #134                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     158: ifeq          187
     161: iload         13
     163: bipush        96
     165: if_icmple     176
     168: iload         13
     170: bipush        96
     172: isub
     173: goto          194
     176: iload         13
     178: bipush        64
     180: isub
     181: bipush        26
     183: iadd
     184: goto          194
     187: iinc          11, 1
     190: goto          101
     193: iconst_0
     194: invokestatic  #140                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     197: aload         14
     199: swap
     200: invokeinterface #144,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     205: pop
     206: goto          45
     209: aload         4
     211: checkcast     #122                // class java/util/List
     214: nop
     215: checkcast     #79                 // class java/lang/Iterable
     218: invokestatic  #148                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     221: ireturn
}


import java.io.File

// Problem:
// https://adventofcode.com/2022/day/2

// More solutions:
// https://www.competitivecoders.com/ProgrammingCompetitions/advent-of-code/advent-of-code/2022/day-2/

fun main() {

    fun part1(input: List<String>): Int {
        val scores = mapOf(
            Pair("A", "X") to 1 + 3,
            Pair("A", "Y") to 2 + 6,
            Pair("A", "Z") to 3 + 0,
            Pair("B", "X") to 1 + 0,
            Pair("B", "Y") to 2 + 3,
            Pair("B", "Z") to 3 + 6,
            Pair("C", "X") to 1 + 6,
            Pair("C", "Y") to 2 + 0,
            Pair("C", "Z") to 3 + 3,
        )

        return input.map { row ->
            row.split(" ")
                .let {
                scores.getValue(Pair(it[0], it[1]))
            }
        }.sum()

    }

    fun part2(input: List<String>): Int {
        val scores = mapOf(
            Pair("A", "X") to 3 + 0,
            Pair("A", "Y") to 1 + 3,
            Pair("A", "Z") to 2 + 6,
            Pair("B", "X") to 1 + 0,
            Pair("B", "Y") to 2 + 3,
            Pair("B", "Z") to 3 + 6,
            Pair("C", "X") to 2 + 0,
            Pair("C", "Y") to 3 + 3,
            Pair("C", "Z") to 1 + 6,
        )

        return input.map { row ->
            row.split(" ")
                .let {
                    scores.getValue(Pair(it[0], it[1]))
                }
        }.sum()

    }

    val input = readInput("Day02")
    println("Part 1: ${part1(input)}")
    println("Part 2: ${part2(input)}")
}

private fun readInput(name: String) = File("src", "$name.txt")
    .readLines()

Compiled from "Day02.kt"
public final class Day02Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day02
       2: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: new           #14                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
      13: ldc           #19                 // String Part 1:
      15: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      18: aload_0
      19: invokestatic  #27                 // Method main$part1:(Ljava/util/List;)I
      22: invokevirtual #30                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      25: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      28: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: swap
      32: invokevirtual #46                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      35: new           #14                 // class java/lang/StringBuilder
      38: dup
      39: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
      42: ldc           #48                 // String Part 2:
      44: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      47: aload_0
      48: invokestatic  #51                 // Method main$part2:(Ljava/util/List;)I
      51: invokevirtual #30                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      54: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      57: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      60: swap
      61: invokevirtual #46                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      64: return

  private static final java.util.List<java.lang.String> readInput(java.lang.String);
    Code:
       0: new           #56                 // class java/io/File
       3: dup
       4: ldc           #58                 // String src
       6: new           #14                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
      13: aload_0
      14: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      17: ldc           #60                 // String .txt
      19: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      25: invokespecial #63                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      28: aconst_null
      29: iconst_1
      30: aconst_null
      31: invokestatic  #69                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      34: areturn

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

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: bipush        9
       2: anewarray     #79                 // class kotlin/Pair
       5: astore_2
       6: aload_2
       7: iconst_0
       8: new           #79                 // class kotlin/Pair
      11: dup
      12: ldc           #81                 // String A
      14: ldc           #83                 // String X
      16: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      19: iconst_4
      20: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      26: aastore
      27: aload_2
      28: iconst_1
      29: new           #79                 // class kotlin/Pair
      32: dup
      33: ldc           #81                 // String A
      35: ldc           #100                // String Y
      37: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      40: bipush        8
      42: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      45: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      48: aastore
      49: aload_2
      50: iconst_2
      51: new           #79                 // class kotlin/Pair
      54: dup
      55: ldc           #81                 // String A
      57: ldc           #102                // String Z
      59: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      62: iconst_3
      63: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      69: aastore
      70: aload_2
      71: iconst_3
      72: new           #79                 // class kotlin/Pair
      75: dup
      76: ldc           #104                // String B
      78: ldc           #83                 // String X
      80: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      83: iconst_1
      84: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      87: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      90: aastore
      91: aload_2
      92: iconst_4
      93: new           #79                 // class kotlin/Pair
      96: dup
      97: ldc           #104                // String B
      99: ldc           #100                // String Y
     101: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     104: iconst_5
     105: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     111: aastore
     112: aload_2
     113: iconst_5
     114: new           #79                 // class kotlin/Pair
     117: dup
     118: ldc           #104                // String B
     120: ldc           #102                // String Z
     122: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     125: bipush        9
     127: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     130: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     133: aastore
     134: aload_2
     135: bipush        6
     137: new           #79                 // class kotlin/Pair
     140: dup
     141: ldc           #106                // String C
     143: ldc           #83                 // String X
     145: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     148: bipush        7
     150: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     153: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     156: aastore
     157: aload_2
     158: bipush        7
     160: new           #79                 // class kotlin/Pair
     163: dup
     164: ldc           #106                // String C
     166: ldc           #100                // String Y
     168: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     171: iconst_2
     172: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     175: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     178: aastore
     179: aload_2
     180: bipush        8
     182: new           #79                 // class kotlin/Pair
     185: dup
     186: ldc           #106                // String C
     188: ldc           #102                // String Z
     190: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     193: bipush        6
     195: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     198: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     201: aastore
     202: aload_2
     203: invokestatic  #112                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     206: astore_1
     207: aload_0
     208: checkcast     #114                // class java/lang/Iterable
     211: astore_2
     212: iconst_0
     213: istore_3
     214: aload_2
     215: astore        4
     217: new           #116                // class java/util/ArrayList
     220: dup
     221: aload_2
     222: bipush        10
     224: invokestatic  #122                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     227: invokespecial #125                // Method java/util/ArrayList."<init>":(I)V
     230: checkcast     #127                // class java/util/Collection
     233: astore        5
     235: iconst_0
     236: istore        6
     238: aload         4
     240: invokeinterface #131,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     245: astore        7
     247: aload         7
     249: invokeinterface #137,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     254: ifeq          362
     257: aload         7
     259: invokeinterface #141,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     264: astore        8
     266: aload         5
     268: aload         8
     270: checkcast     #143                // class java/lang/String
     273: astore        9
     275: astore        14
     277: iconst_0
     278: istore        10
     280: aload         9
     282: checkcast     #145                // class java/lang/CharSequence
     285: iconst_1
     286: anewarray     #143                // class java/lang/String
     289: astore        11
     291: aload         11
     293: iconst_0
     294: ldc           #147                // String
     296: aastore
     297: aload         11
     299: iconst_0
     300: iconst_0
     301: bipush        6
     303: aconst_null
     304: invokestatic  #153                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     307: astore        12
     309: iconst_0
     310: istore        13
     312: aload_1
     313: new           #79                 // class kotlin/Pair
     316: dup
     317: aload         12
     319: iconst_0
     320: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     325: aload         12
     327: iconst_1
     328: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     333: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     336: invokestatic  #163                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     339: checkcast     #165                // class java/lang/Number
     342: invokevirtual #169                // Method java/lang/Number.intValue:()I
     345: nop
     346: nop
     347: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     350: aload         14
     352: swap
     353: invokeinterface #173,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     358: pop
     359: goto          247
     362: aload         5
     364: checkcast     #155                // class java/util/List
     367: nop
     368: checkcast     #114                // class java/lang/Iterable
     371: invokestatic  #177                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     374: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: bipush        9
       2: anewarray     #79                 // class kotlin/Pair
       5: astore_2
       6: aload_2
       7: iconst_0
       8: new           #79                 // class kotlin/Pair
      11: dup
      12: ldc           #81                 // String A
      14: ldc           #83                 // String X
      16: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      19: iconst_3
      20: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      26: aastore
      27: aload_2
      28: iconst_1
      29: new           #79                 // class kotlin/Pair
      32: dup
      33: ldc           #81                 // String A
      35: ldc           #100                // String Y
      37: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      40: iconst_4
      41: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      44: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      47: aastore
      48: aload_2
      49: iconst_2
      50: new           #79                 // class kotlin/Pair
      53: dup
      54: ldc           #81                 // String A
      56: ldc           #102                // String Z
      58: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      61: bipush        8
      63: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      69: aastore
      70: aload_2
      71: iconst_3
      72: new           #79                 // class kotlin/Pair
      75: dup
      76: ldc           #104                // String B
      78: ldc           #83                 // String X
      80: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      83: iconst_1
      84: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      87: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      90: aastore
      91: aload_2
      92: iconst_4
      93: new           #79                 // class kotlin/Pair
      96: dup
      97: ldc           #104                // String B
      99: ldc           #100                // String Y
     101: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     104: iconst_5
     105: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     111: aastore
     112: aload_2
     113: iconst_5
     114: new           #79                 // class kotlin/Pair
     117: dup
     118: ldc           #104                // String B
     120: ldc           #102                // String Z
     122: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     125: bipush        9
     127: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     130: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     133: aastore
     134: aload_2
     135: bipush        6
     137: new           #79                 // class kotlin/Pair
     140: dup
     141: ldc           #106                // String C
     143: ldc           #83                 // String X
     145: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     148: iconst_2
     149: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     152: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     155: aastore
     156: aload_2
     157: bipush        7
     159: new           #79                 // class kotlin/Pair
     162: dup
     163: ldc           #106                // String C
     165: ldc           #100                // String Y
     167: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     170: bipush        6
     172: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     175: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     178: aastore
     179: aload_2
     180: bipush        8
     182: new           #79                 // class kotlin/Pair
     185: dup
     186: ldc           #106                // String C
     188: ldc           #102                // String Z
     190: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     193: bipush        7
     195: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     198: invokestatic  #98                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     201: aastore
     202: aload_2
     203: invokestatic  #112                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     206: astore_1
     207: aload_0
     208: checkcast     #114                // class java/lang/Iterable
     211: astore_2
     212: iconst_0
     213: istore_3
     214: aload_2
     215: astore        4
     217: new           #116                // class java/util/ArrayList
     220: dup
     221: aload_2
     222: bipush        10
     224: invokestatic  #122                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     227: invokespecial #125                // Method java/util/ArrayList."<init>":(I)V
     230: checkcast     #127                // class java/util/Collection
     233: astore        5
     235: iconst_0
     236: istore        6
     238: aload         4
     240: invokeinterface #131,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     245: astore        7
     247: aload         7
     249: invokeinterface #137,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     254: ifeq          362
     257: aload         7
     259: invokeinterface #141,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     264: astore        8
     266: aload         5
     268: aload         8
     270: checkcast     #143                // class java/lang/String
     273: astore        9
     275: astore        14
     277: iconst_0
     278: istore        10
     280: aload         9
     282: checkcast     #145                // class java/lang/CharSequence
     285: iconst_1
     286: anewarray     #143                // class java/lang/String
     289: astore        11
     291: aload         11
     293: iconst_0
     294: ldc           #147                // String
     296: aastore
     297: aload         11
     299: iconst_0
     300: iconst_0
     301: bipush        6
     303: aconst_null
     304: invokestatic  #153                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     307: astore        12
     309: iconst_0
     310: istore        13
     312: aload_1
     313: new           #79                 // class kotlin/Pair
     316: dup
     317: aload         12
     319: iconst_0
     320: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     325: aload         12
     327: iconst_1
     328: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     333: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     336: invokestatic  #163                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     339: checkcast     #165                // class java/lang/Number
     342: invokevirtual #169                // Method java/lang/Number.intValue:()I
     345: nop
     346: nop
     347: invokestatic  #92                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     350: aload         14
     352: swap
     353: invokeinterface #173,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     358: pop
     359: goto          247
     362: aload         5
     364: checkcast     #155                // class java/util/List
     367: nop
     368: checkcast     #114                // class java/lang/Iterable
     371: invokestatic  #177                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     374: ireturn
}


import java.util.*

fun main() {
    val mutableList = arrayListOf(3,23,5435,2323,43,32,43)
    println(mutableList)

    println( mutableList.quickSort().let { mutableList })

}

/**
 *快排
 * 思想：分治
 * 1.从大到小每一层都一分为二 分到不能再分为止
 * 2.对于每一个小部分 都选定一个和标志位 使得标志位的左边都小于右边
 */
fun MutableList<Int>.quickSort() {
    if (this.isEmpty()) {
        return
    }

    val stack = Stack<Int>()
    stack.push(0)
    stack.push(this.size - 1)

    while (stack.isNotEmpty()) {
        val highIndex = stack.pop()
        val lowIndex = stack.pop()

        if (lowIndex < highIndex) {
            val flagIndex = partition(mList = this, lowIndex = lowIndex, highIndex = highIndex)

            stack.push(lowIndex)
            stack.push(flagIndex - 1)

            stack.push(flagIndex + 1)
            stack.push(highIndex)
        }

    }
}

/**
 * 选取一个标志位 让列表中的左边小于标志位右边大于标志位
 *
 * @return 标志位的索引
 */
fun partition(mList: MutableList<Int>, lowIndex: Int, highIndex: Int): Int {
    val flag = mList[highIndex]
    //最后一个小于flag的元素的位置 初始为lowIndex-1
    var theLowIndex = lowIndex - 1

    for (index in lowIndex until  highIndex){
        if (mList[index]<flag){
            mList.swap(theLowIndex+1,index)
            theLowIndex++
        }
    }

    mList.swap(theLowIndex + 1, highIndex)
    return theLowIndex + 1
}

/**
 * 交换两个索引对应元素的位置
 */
fun MutableList<Int>.swap(index1: Int, index2: Int) {
    val temp = this[index1]
    set(index = index1, element = this[index2])
    set(index = index2, element = temp)
}

Compiled from "QuickSort.kt"
public final class QuickSortKt {
  public static final void main();
    Code:
       0: bipush        7
       2: anewarray     #8                  // class java/lang/Integer
       5: astore_1
       6: aload_1
       7: iconst_0
       8: iconst_3
       9: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      12: aastore
      13: aload_1
      14: iconst_1
      15: bipush        23
      17: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      20: aastore
      21: aload_1
      22: iconst_2
      23: sipush        5435
      26: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: aastore
      30: aload_1
      31: iconst_3
      32: sipush        2323
      35: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      38: aastore
      39: aload_1
      40: iconst_4
      41: bipush        43
      43: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      46: aastore
      47: aload_1
      48: iconst_5
      49: bipush        32
      51: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: aastore
      55: aload_1
      56: bipush        6
      58: bipush        43
      60: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      63: aastore
      64: aload_1
      65: invokestatic  #18                 // Method kotlin/collections/CollectionsKt.arrayListOf:([Ljava/lang/Object;)Ljava/util/ArrayList;
      68: astore_0
      69: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      72: aload_0
      73: invokevirtual #30                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      76: aload_0
      77: checkcast     #32                 // class java/util/List
      80: invokestatic  #36                 // Method quickSort:(Ljava/util/List;)V
      83: getstatic     #42                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      86: astore_2
      87: iconst_0
      88: istore_3
      89: aload_0
      90: astore_1
      91: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      94: aload_1
      95: invokevirtual #30                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      98: return

  public static final void quickSort(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #51                 // String <this>
       3: invokestatic  #57                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #61,  1           // InterfaceMethod java/util/List.isEmpty:()Z
      12: ifeq          16
      15: return
      16: new           #63                 // class java/util/Stack
      19: dup
      20: invokespecial #66                 // Method java/util/Stack."<init>":()V
      23: astore_1
      24: aload_1
      25: iconst_0
      26: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: invokevirtual #70                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
      32: pop
      33: aload_1
      34: aload_0
      35: invokeinterface #74,  1           // InterfaceMethod java/util/List.size:()I
      40: iconst_1
      41: isub
      42: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      45: invokevirtual #70                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
      48: pop
      49: aload_1
      50: checkcast     #76                 // class java/util/Collection
      53: invokeinterface #77,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      58: ifne          65
      61: iconst_1
      62: goto          66
      65: iconst_0
      66: ifeq          157
      69: aload_1
      70: invokevirtual #81                 // Method java/util/Stack.pop:()Ljava/lang/Object;
      73: checkcast     #8                  // class java/lang/Integer
      76: astore_2
      77: aload_1
      78: invokevirtual #81                 // Method java/util/Stack.pop:()Ljava/lang/Object;
      81: checkcast     #8                  // class java/lang/Integer
      84: astore_3
      85: aload_3
      86: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
      89: aload_2
      90: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
      93: if_icmpge     49
      96: aload_0
      97: aload_3
      98: invokestatic  #87                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     101: aload_3
     102: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
     105: aload_2
     106: invokestatic  #87                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     109: aload_2
     110: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
     113: invokestatic  #91                 // Method partition:(Ljava/util/List;II)I
     116: istore        4
     118: aload_1
     119: aload_3
     120: invokevirtual #70                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     123: pop
     124: aload_1
     125: iload         4
     127: iconst_1
     128: isub
     129: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     132: invokevirtual #70                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     135: pop
     136: aload_1
     137: iload         4
     139: iconst_1
     140: iadd
     141: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     144: invokevirtual #70                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     147: pop
     148: aload_1
     149: aload_2
     150: invokevirtual #70                 // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     153: pop
     154: goto          49
     157: return

  public static final int partition(java.util.List<java.lang.Integer>, int, int);
    Code:
       0: aload_0
       1: ldc           #102                // String mList
       3: invokestatic  #57                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_2
       8: invokeinterface #106,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #108                // class java/lang/Number
      16: invokevirtual #109                // Method java/lang/Number.intValue:()I
      19: istore_3
      20: iload_1
      21: iconst_1
      22: isub
      23: istore        4
      25: iload_1
      26: istore        5
      28: iload         5
      30: iload_2
      31: if_icmpge     71
      34: aload_0
      35: iload         5
      37: invokeinterface #106,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      42: checkcast     #108                // class java/lang/Number
      45: invokevirtual #109                // Method java/lang/Number.intValue:()I
      48: iload_3
      49: if_icmpge     65
      52: aload_0
      53: iload         4
      55: iconst_1
      56: iadd
      57: iload         5
      59: invokestatic  #113                // Method swap:(Ljava/util/List;II)V
      62: iinc          4, 1
      65: iinc          5, 1
      68: goto          28
      71: aload_0
      72: iload         4
      74: iconst_1
      75: iadd
      76: iload_2
      77: invokestatic  #113                // Method swap:(Ljava/util/List;II)V
      80: iload         4
      82: iconst_1
      83: iadd
      84: ireturn

  public static final void swap(java.util.List<java.lang.Integer>, int, int);
    Code:
       0: aload_0
       1: ldc           #51                 // String <this>
       3: invokestatic  #57                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: invokeinterface #106,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #108                // class java/lang/Number
      16: invokevirtual #109                // Method java/lang/Number.intValue:()I
      19: istore_3
      20: aload_0
      21: iload_1
      22: aload_0
      23: iload_2
      24: invokeinterface #106,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      29: invokeinterface #121,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      34: pop
      35: aload_0
      36: iload_2
      37: iload_3
      38: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokeinterface #121,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      46: pop
      47: return

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